Skip to content

usage: always show the subscription usage chip (#157) - #163

Merged
Lexus2016 merged 1 commit into
mainfrom
feat/157-usage-chip
Dec 1, 2026
Merged

Lexus2016 merged 1 commit into
mainfrom
feat/157-usage-chip

Conversation

@Lexus2016

Copy link
Copy Markdown
Owner

Part of #157 (the API-engine half). The studio showed the subscription usage only once a warning threshold was crossed: updateRateLimit() returned early for status:'allowed' below it and cleared the badge, and the single _rlInfo slot forgot one window as soon as the other one arrived (five_hour and seven_day are separate events of the same rate_limit frame type).

Now the chip is an indicator, not only an alert:

  • public/index.html keeps the last known utilisation per window under rl_usage (migrating a timestamped rl_info once), so both figures survive a reload and one event never erases the other.
  • The chip label lists every fresh window (5h 43% · 7d 12%); the tooltip carries one block per window with the used percentage and the reset time the CLI reported, plus how old the data is.
  • A window whose reset time has passed is dropped instead of rendered as 0%: the old figure says nothing about the current window.
  • Colour and text still follow the existing alerts: neutral below 80% (rl-ok: no pulse, no dismiss button), amber while warning, red at 95% or rejected. Threshold toasts, the browser notification and the rejected modal are unchanged.
  • New strings in all five languages (uk/en/ru/fr/he).

The Subscription engine (tmux) has no rate_limit_event yet, so nothing is shown there; wiring it to the TUI status line is the follow-up the issue itself calls unverified.

Evidence (Node 24.22.1): test/usage-indicator.test.js 19 passed — it runs the real renderer in a vm and pins that an allowed event below the threshold now renders the chip instead of clearing it, that the two windows keep separate slots, that a stale window is dropped, and that the chip follows the alert thresholds. i18n-completeness 139 passed, render suites 122 passed, and responsive-ui / section-controls-ux / settings-ux / secondary-navigation / frontend-recovery / terminal-keys / file-preview-copy / sidebar-ux all rc=0. The full npm test cannot finish on this host (task-backlog.test.js binds ::1 for HOST=localhost), so CI is the complete run.

The studio showed the subscription usage only once a warning threshold was
crossed: updateRateLimit() returned early for status:'allowed' below it and
cleared the badge, and the single _rlInfo slot forgot one window as soon as
the other one arrived (five_hour and seven_day are separate events of the
same rate_limit frame type).

Now the chip is an indicator, not only an alert:

- public/index.html keeps the last known utilisation per window under
  rl_usage (migrating a timestamped rl_info once), so both figures survive
  a reload and one event never erases the other.
- The chip label lists every fresh window ("5h 43% · 7d 12%"), the tooltip
  carries one block per window with the used percentage and the reset time
  the CLI reported, plus how old the data is.
- A window whose reset time has passed is dropped instead of rendered as
  0%: the old figure says nothing about the current window.
- Colour and text still follow the existing alerts: neutral below 80%
  (rl-ok: no pulse, no dismiss button), amber while warning, red at 95% or
  rejected. Threshold toasts, the browser notification and the rejected
  modal are unchanged.
- New strings in all five languages (uk/en/ru/fr/he).

The Subscription engine (tmux) still has no source for rate_limit_event, so
nothing is shown there yet; wiring it to the TUI status line is the follow-up
the issue itself calls unverified.

Evidence (Node 24.22.1): test/usage-indicator.test.js 19 passed - it runs the
real renderer in a vm and pins that an allowed event below the threshold now
renders the chip instead of clearing it, that the two windows keep separate
slots, that a stale window is dropped, and that the chip follows the alert
thresholds. i18n-completeness 139 passed, render suites 122 passed, and
responsive-ui / section-controls-ux / settings-ux / secondary-navigation /
frontend-recovery / terminal-keys / file-preview-copy / sidebar-ux all rc=0.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T06:11:30.884494Z f96b9cf PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f96b9cf6df

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread public/index.html
function _rlRenderUsage() {
const badge = $i('rlBadge');
if (!badge) return;
const fresh = _rlUsageFresh(_rlUsageLoad());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep live usage state independent of localStorage writes

When localStorage writes fail, such as when the origin's storage quota is exhausted, _rlUsageNote() silently loses the new event and this renderer reloads either empty or outdated state. A fresh 85% event consequently leaves the badge hidden if nothing was previously stored. Before this change, persistence was best-effort and the badge still rendered directly from the received event. Keep the per-window state in memory and use localStorage only for persistence so storage failures do not suppress or freeze the live indicator.

Useful? React with 👍 / 👎.

Comment thread public/index.html
if (!Object.keys(_rlUsageLoad()).length) {
const raw = localStorage.getItem(RL_STORAGE_KEY);
const legacy = raw ? JSON.parse(raw) : null;
if (legacy && legacy.rateLimitType && legacy.ts) _rlUsageNote(legacy, legacy.ts);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Migrate the legacy records that the previous version actually wrote

On an upgrade with an unexpired warning saved under rl_info, this condition prevents the existing indicator from being restored: the previous _rlSave() serialized info directly and did not add ts. Thus ordinary records written by the previous version fail the migration and the badge disappears until another rate-limit event arrives, whereas the previous restore path displayed them through their reset time. Accept legacy records without a timestamp when their reported reset time is still in the future, handling the unknown observation age separately.

Useful? React with 👍 / 👎.

@Lexus2016
Lexus2016 merged commit dbbbfa6 into main Dec 1, 2026
3 checks passed
@Lexus2016
Lexus2016 deleted the feat/157-usage-chip branch December 1, 2026 06:15
@Lexus2016

Copy link
Copy Markdown
Owner Author

Merged as dbbbfa61 (squash, 2026-12-01T06:15:01Z) on top of 4862657.

Verification:

  • PR head f96b9cf6 — CI run 46588301899: test (20) and test (24) both success over the full npm test chain on the GitHub runners (tmux present there).
  • Merge commit dbbbfa61: one parent, tree b8374472 — identical to the reviewed head tree, so the squash introduced nothing new.
  • feat/157-usage-chip deleted (this repo has delete_branch_on_merge off).
  • Post-merge main CI: 46588982693; pages build 46588980511 success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant