Skip to content

fix(gui): report consumed quota share in the per-account quota table - #9077

Merged
lidge-jun merged 7 commits into
lidge-jun:devfrom
rafaelmoreiraai:fix/accounts-quota-used-metric
Nov 25, 2026
Merged

lidge-jun merged 7 commits into
lidge-jun:devfrom
rafaelmoreiraai:fix/accounts-quota-used-metric

Conversation

@rafaelmoreiraai

@rafaelmoreiraai rafaelmoreiraai commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Providers → Accounts tab reports quota with the opposite metric from every other quota surface in the dashboard.

  • gui/src/components/provider-workspace/AccountQuotaTable.tsx rendered {percent}% left from a PoolCell.remaining field (src/provider-workspace/account-quota-table.ts computed 100 - usedPercent), and filled each bar to the remaining share.
  • Accounts & limits (the Codex page, CodexAccountPool → codex-account-pool-cards), the provider quota bars (ProviderCapacityQuota → QuotaBars), and the header QuotaSummaryBar all report consumed share.

So the same underlying number read 87% left on one screen and 13% used on another, and the two bars filled in opposite directions. QuotaBars' own thresholds make this more than cosmetic: warn/critical/exhaustion (isQuotaWarn, isQuotaExhausted) are all expressed on the consumed share, so a pool column could read "healthy, 96% left" next to a card flagging the same account as near-exhausted.

This PR makes the account quota table report consumed share, matching every other surface. It is a display-layer change: no probe, cache, routing or admission code is touched.

What changed

  • PoolCell.remaining → PoolCell.used, and clampRemaining(100 - pct) → clampUsed(pct). The cell now carries the wire value instead of its inverse.
  • PoolBar renders t("quota.usedPercent") (the string every other surface already uses) and fills the bar to the consumed share.
  • The warn tone threshold moves from remaining <= 20 to used >= 80 — the same point on the scale, just stated in the new direction, and it now comes from quotaBarTone(used, QUOTA_WARN_THRESHOLD) in QuotaBars instead of a literal, so this cell cannot drift from the surfaces it is being aligned to.
  • The reset-first next marker's "skip an exhausted window" guard moves from remaining <= 0 to used >= 100 (same condition).
  • acctTable.left is removed from gui/src/i18n/account-probe-copy.ts; nothing else referenced it.
  • Docs updated: structure/gui-and-management-api.md and docs-site/.../reference/cli/providers-accounts.md described this table as "remaining … by pool". The Spanish reference and the dashboard guide were fixed in c83971e (thanks @lidgejun) — they still said "percentage left".

I verified the two threshold rewrites by enumeration rather than by eye: over the 101 integer percentages 0–100, remaining <= 20 and used >= 80 disagree 0 times, and remaining <= 0 vs used >= 100 disagree 0 times.

They are equivalent for integer percentages, which is what the table receives after Math.round — they are not equivalent in general. For a fractional reading, Math.round sends the two expressions to opposite sides at exactly one point: at 79.5, round(100 - 79.5) = 21 is green under the old rule while round(79.5) = 80 is warn under the new one. The exhausted guard has the same half-point shift: at 99.5, round(100 - 99.5) = 1 is not exhausted under remaining <= 0, while round(99.5) = 100 is exhausted under used >= 100. So both boundaries move by half a point on fractional input; on integers neither moves. Enumerated over 0.0–100.0 in tenths: one divergence for the warn pair (79.5) and one for the exhausted pair (99.5), out of 1001 readings.

Screenshot

Same /api/provider-quotas data rendered by the pre-change and post-change components (real component output, real built stylesheet):

Before — % left, bar fills to remaining After — % used, bar fills as it is spent
before after

Test plan

Everything below was run on head 1d65de0ee, in a worktree checked out at exactly that SHA, with git rev-list --left-right --count HEAD...upstream/dev = 6 0 against dev at 9b5861c1a — i.e. this head is the current dev tip plus this PR's 6 commits.

Root suite (bun scripts/test.ts, the repo's own runner — a separate lane from gui/tests, and the one that caught the regression described below):

  • PR fast lane, bun scripts/test.ts --changed=9b5861c1a (the current merge base) → 300 pass, 0 fail, 19 files, 6.48s.
  • tests/gui/ files importing the changed modules (gui-account-quota-table, rate-limit-reset-credits, quota-bars-rows) → 74 pass, 0 fail, 179 expect() calls.
  • tests/ci-workflows/file-size-ratchet.test.ts → 9 pass, 0 fail (needs --timeout 60000 on a cold cache; the default 5000 ms trips inside this file's repo scan and reads as a failure).

GUI suite (cd gui && bun run test, i.e. scripts/test-with-pinned-bun.ts --isolate tests):

  • 4832 pass, 0 fail, 452 files, 483.86s.

For transparency: a previous head of this branch (927baf977) produced 1 fail in provider-first-response-guidance.test.tsx › Providers page joins /api/providers discovery with the model snapshot and refreshes on retry (stepState("models") expected "failed", got "loading"). That file is not in this PR, it passed 3/3 isolated runs on that same head, and it did not reproduce on 1d65de0ee — an order-dependent flake in that suite, not this diff.

Static gates on 1d65de0ee:

  • bun run typecheck → No type errors in 2,692 files
  • cd gui && bun run lint → rc 0; cd gui && bun run lint:i18n → rc 0
  • bun run structure:check → structure/ SSOT checks passed
  • bun run privacy:scan → Privacy scan passed
  • cd gui && bun run build → both bundles built (✓ built in 7.08s, ✓ built in 1.95s; the >4096 kB chunk warning is pre-existing)

The regression the maintainer fixed, and why my earlier verification missed it

c83971e (the maintainer's commit on this branch) corrects tests/gui/gui-account-quota-table.test.ts to read used instead of remaining. That was a real break I shipped, and the root cause is a verification gap worth stating: my earlier run covered only gui/tests, while this file lives in the root lane's tests/gui/. Two different ran suites, one of them unrun.

Proof it was red and not a cosmetic rename — the old head 3fe2dbadb in a throwaway worktree:

$ bun test --isolate ./tests/gui/gui-account-quota-table.test.ts
 8 pass
 3 fail
Ran 11 tests across 1 file.

Three assertions still reading the inverted field. The same file is green on 1d65de0ee (11/11, now part of the 74 above). Both lanes are in the verification list for this PR from here on.

account-quota-table-stacked.test.tsx also gained an example that does not exist to rename a string: it builds a cell whose windows read exactly QUOTA_WARN_THRESHOLD and QUOTA_WARN_THRESHOLD - 1 and requires bar-warn on the first and bar-green on the second. Verified red by flipping the comparison to used > 80, which turns 80% green and fails the example. (An earlier revision of this PR also added a "tones match quotaBarTone" example; it was removed because both sides called the same function, so it could not fail.)

Regression coverage: the three existing GUI tests that pinned the old wording now pin the consumed share instead, and each also exercises the direction of the change rather than just the label —
account-quota-table-stacked.test.tsx asserts 0% used for an unspent 5-hour window and 100% used for an exhausted weekly one, anthropic-subscription-label.test.tsx asserts 37% used / 18% used from 37%/18% upstream readings, and provider-auth-target-capture.test.tsx asserts 20% used from a 20% upstream reading.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. (None touched.)

One thing worth a maintainer's opinion: gui/src/components/v2-accounts/account-quota-meters.tsx (with serving-summary.tsx) also renders {pct}% left, but neither file is imported anywhere right now — AccountQuotaMeters/ServingSummary have no callers on dev. I left that pair alone rather than change unreachable code, on the assumption it is staged for the v2 Codex accounts page. If it is about to be mounted, it will reintroduce the same inversion and should be flipped in the same direction.


Review readiness

Re-attested on 1d65de0ee, after two maintainer merge commits on this branch (c83971e test/doc fix, then 927baf977 and 1d65de0ee merging dev) reset the checklist. Those commits are the maintainer's; I did not overwrite them.

  • Local CI green on 1d65de0ee — the commands and results in the test plan above.
  • Branch is on the latest dev commit — 9b5861c1a, 0 behind (git rev-list --left-right --count HEAD...upstream/dev = 6 0).
  • All correct Codex and CodeRabbit findings resolved — CodeRabbit's last pass generated no actionable comments; nothing else is open.
  • Ready for review — all four boxes of the quality gate are ticked on 1d65de0ee.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

The Providers Accounts table rendered 'N% left' from PoolCell.remaining
(100 - usedPercent) and filled each bar to the remaining share, while
Accounts & limits, ProviderCapacityQuota/QuotaBars and QuotaSummaryBar all
report the consumed share. The same reading therefore appeared as '87% left'
on one surface and '13% used' on another, with the bars filling in opposite
directions, and the shared warn/exhaustion thresholds (isQuotaWarn,
isQuotaExhausted) are expressed on the consumed share.

Carry PoolCell.used (the wire value) instead of its inverse, render the
existing quota.usedPercent string, and state the two threshold rewrites in
the new direction: remaining <= 20 becomes used >= 80 and remaining <= 0
becomes used >= 100. Both are exactly equivalent across 0-100%.

Remove the now-unused acctTable.left copy row and update the two documents
that described this table as remaining per pool.
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (0/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 0/4).

Review readiness checklist

  • ⬜ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ⬜ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ⬜ I resolved all correct Codex and CodeRabbit findings.
  • ⬜ My PR is ready for review.

0/4 boxes ticked.

Automatic draft conversion failed. Please convert this pull request to a draft manually until every box above is ticked.

Hygiene

✅ Deterministic PR hygiene checks passed.

@github-actions
github-actions Bot marked this pull request as draft November 23, 2026 12:45
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Quota cells now store used percentages instead of remaining percentages. The account table displays consumed percentages, uses a shared warning threshold, and updates related tests and documentation.

Changes: Quota percentage display

Layer / File(s) Summary
Quota data and selection
gui/src/provider-workspace/account-quota-table.ts
PoolCell now stores clamped used percentages. Reset-first selection skips a row if any quota window is at least 100% used.
Quota bars, labels, and descriptions
gui/src/components/QuotaBars.tsx, gui/src/components/provider-workspace/AccountQuotaTable.tsx, gui/src/i18n/account-probe-copy.ts, gui/tests/*, tests/gui/gui-account-quota-table.test.ts, docs-site/src/content/docs/reference/cli/providers-accounts.md, docs-site/src/content/docs/es/reference/cli/providers-accounts.md, docs-site/src/content/docs/guides/web-dashboard.md, structure/gui-and-management-api.md
Quota bars scale by used percentage and use the shared warning threshold. Tests and account-table descriptions use consumed-percentage wording and values. The “percent left” localization entry was removed.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • lidge-jun/opencodex#9004: Changes the layout of the same account quota table, including labels that need to match the consumed-percentage display.
  • lidge-jun/opencodex#8740: Introduces the per-account quota table whose display semantics this change updates.
Merge Risk: Minimal · up to 927ba

The Providers accounts table now shows consumed quota, which matches the rest of the dashboard. It is a display-only change with updated tests and docs, and no merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(gui): report consumed quota share in the per-account quota table" matches the main change. The PR switches the Providers → Accounts quota table from remaining quota to consumed (used) q…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "fix(gui): report consumed quota share in the per-account quota table" matches the main change. The PR switches the Providers → Accounts quota table from remaining quota to consumed (used) quota. The changed files include AccountQuotaTable.tsx, account-quota-table.ts (PoolCell.remaining → PoolCell.used), QuotaBars.tsx (new QUOTA_WARN_THRESHOLD), and the related tests and docs. The title is specific and concise, and it names the affected surface (the per-account quota table) and the behavior change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 3fe2dba and 927baf9.

Files selected for processing: 3

  • docs-site/src/content/docs/es/reference/cli/providers-accounts.md
  • docs-site/src/content/docs/guides/web-dashboard.md
  • tests/gui/gui-account-quota-table.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@github-actions
github-actions Bot marked this pull request as ready for review November 23, 2026 13:01
The cell hardcoded `used >= 80`, which is the value `ProviderCapacityQuota`
passes to `QuotaBars`, but nothing tied the two together: changing the
provider threshold would have left this table disagreeing with the cards it
is being aligned to. `QUOTA_WARN_THRESHOLD` now names that value once.

Also corrects the body's equivalence claim: the thresholds agree over the 101
integer percentages, not 1001, and not on fractional input (79.5 rounds to
21 remaining under the old rule and 80 used under the new one).

Two new tests hold the direction: the warn boundary at the threshold, and
parity with quotaBarTone for the same reading.
@rafaelmoreiraai
rafaelmoreiraai force-pushed the fix/accounts-quota-used-metric branch from 3a9f493 to fa2b01d Compare November 24, 2026 00:03
@github-actions
github-actions Bot marked this pull request as draft November 24, 2026 00:03
@github-actions
github-actions Bot marked this pull request as ready for review November 24, 2026 00:20
@rafaelmoreiraai

Copy link
Copy Markdown
Contributor Author

Re-attested on fa2b01dff — the previous push reset the readiness checklist, and the reset is correct: the head changed.

What the new commit adds: the cell's warn tone now comes from quotaBarTone(used, QUOTA_WARN_THRESHOLD) in QuotaBars instead of a literal 80, so this table cannot drift from the capacity card it is being aligned to. It also corrects the description's equivalence claim — the two threshold spellings agree over the 101 integer percentages, not 1001, and disagree at exactly one point on fractional input (79.5: 21 remaining under the old rule, 80 used under the new one).

Fresh local verification on exactly fa2b01dff (branch cut from dev at 9e0e298ef, git rev-list --count HEAD..upstream/dev = 0):

  • bun run test ... — the repo's own test script (scripts/test-with-pinned-bun.ts --isolate): 4831 passed, 0 failed, 50542 assertions, 451 files, 538.49s. Not bun test tests directly — that drops --isolate and reports phantom failures.
  • bun run typecheck — No type errors in 2,691 files
  • bun run lint and bun run lint:i18n — exit 0
  • bun run privacy:scan — passed
  • bun run build (in gui/) — both bundles built
  • bun run structure:check — passed

Two of the new tests are discriminating rather than decorative: the boundary test asserts bar-warn at exactly QUOTA_WARN_THRESHOLD and bar-green one point below (it fails if the comparison is changed to used > 80), and the parity test compares the table's tones against quotaBarTone for the same readings.

Hosted CI is still action_required on the fork head — that click is yours.

Both sides of that assertion called `quotaBarTone(x, QUOTA_WARN_THRESHOLD)`,
so it could not fail for any implementation that imported the helper — it
certified nothing beyond the import. The boundary example stays and was
verified red under a strict `used > 80`.

Body corrected in the same push: the fractional equivalence note now covers
the exhausted guard too (99.5 shifts like 79.5 does), and the test plan lists
the commands that actually ran on this head.
@github-actions
github-actions Bot marked this pull request as draft November 24, 2026 01:34
@rafaelmoreiraai
rafaelmoreiraai marked this pull request as ready for review November 24, 2026 02:48
…n the docs

The table now carries used share, so the root expectations still read the
inverted remaining values. The dashboard guide and the Spanish account
reference also still described the table as percentage left.
@github-actions
github-actions Bot marked this pull request as draft November 25, 2026 02:04
@rafaelmoreiraai
rafaelmoreiraai marked this pull request as ready for review November 25, 2026 03:19
@github-actions
github-actions Bot marked this pull request as draft November 25, 2026 03:36
@github-actions
github-actions Bot marked this pull request as ready for review November 25, 2026 03:40
@github-actions
github-actions Bot marked this pull request as draft November 25, 2026 04:45
@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer integration into dev (MAINTAINERS.md, maintainer-integration path), under the coordinator's relaxed behind-dev gate.

  • Exact head: d17ff0b214b9a3c2b7d59d995aabb763567dd359.
  • PR checks passing on that head: enforce / enforce-target, ci, npm-global ubuntu-latest, storage policy, api usage, structure gate, hygiene / hygiene, docs site build, gates, test changed, enforce / resolve-pr, docker smoke, label / label, changes, select windows runner, react-doctor. Skipped jobs are not counted as passing.
  • Relaxed gate: (a) 7 commits behind origin/dev f9ffbbd (limit 10): PASS. (b) git merge-tree --write-tree f9ffbbd d17ff0b: clean. (c) dev commits since merge-base 8961476 touch none of this PR's files: yes; shared-class files dev touched: scripts/test-layout/layout-server-inbound.json tests/fixtures/test-layout-expected.json ; shared-class files this PR touches: gui/src/i18n/account-probe-copy.ts (guards below decide when both sides touch a class). (d) temporary local merge 2066f3cf81294458a960081654f2c207838f2cf0: bun run typecheck exit 0; bun test --timeout 60000 [focused: tests/gui/gui-account-quota-table.test.ts] [guards: tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/file-size-ratchet.test.ts tests/ci-workflows/skill-ocx.test.ts]: 64 pass 0 fail exit 0; bun run structure:check exit 0; GUI bun test [tests/account-quota-table-stacked.test.tsx tests/anthropic-subscription-label.test.tsx tests/provider-auth-target-capture.test.tsx]: 25 pass 0 fail exit 0: PASS.
  • Independent review (gpt-6.1-terra): APPROVE after round 2. Round 1 BLOCKER (tests/gui/gui-account-quota-table.test.ts still asserted the inverted remaining share) and SHOULD (dashboard guide and Spanish account reference still said percentage left) fixed by maintainer commit c83971e. Changed GUI tests fail against dev source (11 expected failures) and pass here; quota.usedPercent exists in all 11 locales; screenshot is in the description.
  • scripts/ci/assert-mergeable-review.sh --maintainer-integration 9077: OK.

@lidge-jun
lidge-jun marked this pull request as ready for review November 25, 2026 04:50
@lidge-jun
lidge-jun merged commit 693454f into lidge-jun:dev Nov 25, 2026
28 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 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-11-25T04:54:05.740732Z d17ff0b Draft marked ready
ℹ️ 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.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants