Skip to content

feat(quota): say why an API-key balance is unknown and when it was last read - #8519

Merged
lidge-jun merged 4 commits into
devfrom
codex/8397-quota-unknown-reason-r2
Nov 11, 2026
Merged

lidge-jun merged 4 commits into
devfrom
codex/8397-quota-unknown-reason-r2

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

For an API-key provider account, ocx account list <provider> --quota answered quotaMode: unsupported with no reason, so a reader could not tell "no balance source" from "balance is zero", and a probe provider never said when its balance was last read (#8397). Owner decision: step 1 only. When a balance is unknown, show why and when it was last read. Show values only for providers that already have a balance reader. Organization cost APIs that need an admin key are out of scope, and no provider requests are added.

API-key quota rows (and passive OAuth accounts) gain two optional fields:

  • quotaUnknownReason, a closed set:
    • no_balance_source: no reader exists for this destination (every unsupported key).
    • passive_not_observed: a passive OAuth provider has no observation for this account yet.
    • read_failed: a reader exists and its last read failed.
    • not_read: a reader exists but no read was made (paused key, a key that changed mid-read, or the flight cap).
  • quotaReadAt: epoch milliseconds of the last read, success or failure, taken from the per-key cache entry. It is omitted when no read happened.

Probe values still appear only for quotaMode: "probe" destinations. The existing quotaMode values and shapes are unchanged, older CLIs ignore the new fields, and this CLI drops a reason it does not know instead of failing. Human output never prints zero for an unknown balance:

deepseek  api-key  03f8797d  sk-d****0000  -  active  probe: unavailable; balance UNKNOWN (read failed); read 1 min ago

An unsupported key reads unsupported: balance UNKNOWN (no balance source). The dashboard adds "Last read: " under an unknown or failed reading, translated in all 11 locales.

Closes #8397

API key row: rate-limit data unavailable, with "Last read: Just now"

The screenshot and the CLI line above come from a throwaway local proxy with one DeepSeek key, a provider that has a balance reader. Its balance read was answered with a 401 inside the process, so nothing was sent to DeepSeek. --json returned "quotaUnknownReason": "read_failed" and quotaReadAt for the same row.

Verification

  • Failing-first: with src/ and gui/ put back to dev, six new cases fail. They cover the passive account, unsupported keys, probe read time and read failure, human text with an unknown reason dropped, the GUI last-read line, and the locale coverage. They all pass with the change.
  • After merging dev (including feat(accounts): explicit health-gated resume, and login that clears an automatic pause #8515, which touches oauth-account-routes.ts and src/cli/account.ts): the PR diff is byte-identical (same git patch-id). bun test on the quota, route, GUI and API-key tests, plus the feat(accounts): explicit health-gated resume, and login that clears an automatic pause #8515 resume tests, layout, ratchet, Lab boundary and skill-ocx: 215 pass, 0 fail.
  • bun run typecheck (2,400 files), bun run lint:gui, bun run privacy:scan, bun run structure:check and bun run skill:surface:check: pass.
  • test:changed (run by the implementing lane alongside another worktree's suite): 43,099 pass, 96 fail. Every failing file was rerun alone. One failure was this change (an expectation in provider-api-keys.test.ts that lists row keys) and is fixed. The others passed alone, failed only on spawned-process timeouts and also passed on dev, or also fail on dev (ocx-launcher-desktop-handoff, update-home-launcher, catalog-omit-disabled-native, cli-codex-cli-update-boundary, and link-ocx-child-e2e, which needs cargo).
  • NOT RUN: full bun run test; macOS/Windows CI (manual dev batch only).

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.

cpa added 2 commits November 11, 2026 11:14
…st read

API-key quota rows now carry two additive fields. quotaUnknownReason is a
closed set (no_balance_source, passive_not_observed, read_failed, not_read)
that explains a missing balance, and quotaReadAt is the time of the last
read, success or failure, taken from the per-key cache entry. Unsupported
destinations report no_balance_source and no value; probe failures report
read_failed; passive OAuth accounts with no observation report
passive_not_observed. Existing quotaMode values and response shapes are
unchanged, older CLIs ignore the fields, and the CLI drops reasons it does
not know.

The CLI QUOTA column reads "unsupported: balance UNKNOWN (no balance
source)" and "probe: mo 12%; read 3 min ago", and never prints zero for an
unknown balance. The dashboard shows "Last read" under an unknown or
failed reading, translated in every locale.

Refs #8397
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 11, 2026 02:24
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 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-11T02:26:38.730678Z dcba6cf 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.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the enhancement New feature or request label Nov 11, 2026
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • 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

cpa added 2 commits November 11, 2026 11:28
…bad read time (#8397 review)

- A successful read whose provider reports no meterable balance (Abliteration zero credits, a
  Z.AI plan with no model window) now carries quotaUnknownReason "not_reported" instead of a
  read time with no reason.
- A key added while the read was in flight is "not_read".
- The CLI drops a malformed quotaReadAt instead of failing the whole listing.
- Route tests for the empty read and for a paused key (not_read, no read time, no request).

Refs #8397
@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer judgment

  • Value: an API-key pool now says why a balance is unknown and when it was last read, so "no balance source" is no longer indistinguishable from a zero balance ([Feature]: Show per-organization API balance and read time for API-key providers, or UNKNOWN with reason #8397, owner decision step 1). Values still appear only for providers that already have a balance reader. Admin-key organization cost APIs are out of scope, and no provider requests were added.
  • UX change scope: two optional fields on API-key quota rows and passive OAuth rows (quotaUnknownReason from a closed set of five, quotaReadAt); clearer ocx account list --quota text that never prints zero for an unknown balance; and a "Last read" line in the dashboard under an unknown or failed reading, translated in all 11 locales.
  • Regression evidence for existing users: quotaMode values and shapes are unchanged. Older CLIs ignore the new fields, and this CLI drops reasons it does not know and malformed read times. Quota, route, GUI and API-key tests plus the feat(accounts): explicit health-gated resume, and login that clears an automatic pause #8515 and feat(logs): record the Anthropic pool account tag on each attempt #8520 tests and guards: 181 pass, 0 fail on the merged tree. Typecheck, GUI lint, privacy and structure pass.
  • Review: the first review returned REQUEST_CHANGES for one major issue (an empty read with no reason) and three small ones, all fixed with failing-first tests. A fresh final review approved 80b27ec.
  • Follow-ups not addressed here (non-blocking):
    • The in-flight cap drops a read time the server has.
    • There is no test for the GUI roster and late-row merge, and that merge copies a reason the dashboard does not display yet.
    • The OAuth and API-key paths differ in how strictly they parse a bad reason, and the CLI docs should say "an unrecognized reason string is dropped".
    • The CLI text hides the last-good value on a failed read.
  • Windows impact: none; no path or process handling changed.
  • NOT RUN: full bun run test; the implementing lane's test:changed failures were each rerun alone and either reproduced on dev, passed alone, or were fixed; macOS/Windows CI (manual dev batch only).
  • Reviewed head = merge head: 80b27ec.

@lidge-jun
lidge-jun merged commit 29a8120 into dev Nov 11, 2026
26 checks passed
@lidge-jun
lidge-jun deleted the codex/8397-quota-unknown-reason-r2 branch November 11, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Show per-organization API balance and read time for API-key providers, or UNKNOWN with reason

1 participant