Skip to content

Show passive API-key rate-limit headroom - #8297

Merged
lidge-jun merged 75 commits into
devfrom
codex/quota-passive-headroom
Nov 13, 2026
Merged

lidge-jun merged 75 commits into
devfrom
codex/quota-passive-headroom

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Show passively observed request and token limits per provider, configured key and wire model for OpenAI API keys, Anthropic API keys, xAI, Groq and Mistral. The quota strip shows counts, observation age, reset and stale state without a new upstream quota call. A key whose first response carries no limit headers shows as Unknown until a real reading arrives; a headerless response never replaces or fences a measured one.
  • Capture only proven physical key sends, keep bounded observations in process memory, and keep them out of routing decisions. Missing counts and dimensions stay unknown; Mistral headers do not imply a reset. Passive reads never open the OS keychain or repair the auth store; keychain-backed key rows are withheld on passive reads unless the credential resolved by routing proves them, while OAuth rows are unaffected by an unused keychain key.
  • Quota reports are bound to the provider configuration that produced them, and queued reset observations recheck that owner and credential before recording, so a delayed observation cannot land on a replaced key. Unchanged literal, environment and keychain-backed keys (including Mistral) keep their normal reset notifications.
  • Antigravity and Kiro reset-ownership changes were split out of this PR by maintainer decision; both providers keep the existing account-ID reset baselines from dev.
  • Closes [Feature]: Surface rate-limit headroom from response headers for API-key providers (OpenAI, Anthropic API, xAI, Groq, Mistral) #8291.

Verification

Head c200c8bc.

  • bun run typecheck, bun run structure:check and bun run privacy:scan passed.
  • Focused provider, passive observation, Responses transport, quota-pool, reset, Kimi, Mistral, Claude CLI, Muse, Antigravity, Kiro, OAuth, layout and file-size tests: 2756 passed, 0 failed after the scope split; 286 passed, 0 failed after the final fix. The OAuth/keychain regression test failed before its fix.
  • Independent final reviews on this exact head: functional APPROVE (306 backend, 46 GUI, 29 layout and 9 ratchet tests), security APPROVE (256 focused tests, privacy scan).
  • A local full bun run test could not produce a valid verdict: the host was saturated by other lanes (load average ~17 on 16 cores) and the run overlapped a mid-run edit. Failing files outside the quota area are being compared against dev on the same host; hosted shards are the authoritative full run.

Before
After

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.

@coderabbitai

coderabbitai Bot commented Nov 7, 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

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@lidge-jun lidge-jun mentioned this pull request Nov 7, 2026
3 tasks done
@github-actions github-actions Bot added the bug Something isn't working label Nov 7, 2026
lidge-jun and others added 11 commits November 13, 2026 07:59
…droom-into-dev

Integrates #8297 passive key-limit observation onto dev while keeping dev's
#8295 Mistral budget, the exact credential optional binding, Claude held
reports, the Vertex final-send guard and Muse passive observation.

The owner-rejected feature-only Muse ownership ledger, the Antigravity quota
owner, and the reset-identity and key-quota-scope hardening are not restored;
those files are removed with the PR's own additions.

Security-review fixes carried in this merge:
- Passive cache identity and invalidation are scoped to the config home that
  observed the send, so the same provider and key in another home neither
  reads, replaces, nor retires this home's rows.
- A redirect is never a reading, and a parsed response with no count,
  remaining value, or reset no longer advances the sequence fence, so an
  older real response can still settle after a newer headerless 302.

Ratchets: providerRoutingQuota moves to provider-routing-quota.ts so
provider-routes.ts returns under the 2000-line new-file bound, and the
providers guide keeps dev's budget prose plus a compact passive-observation
note within the same bound. quota.ts stays at its 558-line cap.
…droom-into-dev

Brings the integration onto the current dev head after the first merge
resolved against an earlier target. The extra dev commits (Remote Link
WebSocket, zstd child bodies, Pi nested selectors, byte accounting) touch
the layout fixture and structure docs, so this merge re-derives both copies
of the layout table from the live parents instead of keeping the older
snapshot.

Verification on the merged tree:
- bun run typecheck: no type errors (2,456 files)
- bun scripts/file-size-ratchet.ts: passed
- bun run structure:check: passed
- bun run privacy:scan: passed
- tests/test-layout.test.ts + tests/test-layout-tooling.test.ts: 29 pass
- tests/providers/passive-key-limits.test.ts + passive-key-observation
  + responses-passive-key-limits: 105 pass
- tests/providers/mistral-budget-quota, usage/quota-pool,
  provider-quota-observed-marker, lab/core-lab-boundary: 108 pass
- tests/server/management-provider-validation: 138 pass
- gui quota-summary-bar/summary/observed-age/display-only-window: 43 pass
…eadroom

Restore the Antigravity and Kiro quota probes, their dedicated ownership tests and
the jev-decision note to dev, and drop the owner-hash reset key so both providers
keep dev's account-ID reset baselines across upgrade. The ownership work is kept
on goat/quota-8297-ownership-followup-20261113 for separate review.

Keep the passive auth-store peek that other passive quota reads rely on, and assert
the accepted first-headerless Unknown contract in the Responses end-to-end test.
Passive held reads withheld every report whose provider carried a keychain
apiKey, so a provider switched from key to OAuth authentication lost its live
OAuth report on passive reads. Withhold only key-authenticated reports, whose
ownership depends on the keychain value a passive read cannot verify.
@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer judgment (head c200c8bc)

Value. Closes #8291: API-key users of OpenAI, Anthropic, xAI, Groq and Mistral see the rate-limit headroom their own requests already report, with no extra upstream calls and no effect on routing.

UX change. A new passive row per provider, key and wire model in the quota strip: counts, observation age, reset and stale state. A key whose first response carried no limit headers shows Unknown until a measured reading arrives. Nothing existing is removed or relabelled.

Existing users. Reset notifications keep firing for unchanged literal, environment and keychain-backed keys, including Mistral. Antigravity and Kiro were split out by owner decision and keep the dev account-ID reset baselines, so upgrading loses no reset history. Passive reads now withhold reports whose owning configuration changed, which can make a stale row disappear sooner than before; that is the intended correction. OAuth rows stay visible beside an unused keychain key.

Windows. No platform-specific code paths, path handling or process spawning were added; observations are in-memory and keyed by hashed identifiers.

Security. Credential, keychain and account-ownership paths were reviewed independently at this exact head: APPROVE with no findings. No raw keys, headers or account identifiers are logged, serialized or persisted; passive reads never open the OS keychain or repair the auth store.

Evidence. Fresh functional and security reviews APPROVE at c200c8bc. Typecheck, structure and privacy gates pass. Focused suites pass: 2756 tests after the split, 286 after the final fix. On the same host, the five files that failed in the local full run (catalog convergence, Remote Link WebSocket, local-read proof, package-tree restart) fail identically on dev 522a6cd4, so the PR does not cause them. Hosted test 1/5 and test 4/5 passed; the remaining shards were still queued at merge time.

@lidge-jun
lidge-jun marked this pull request as ready for review November 13, 2026 02:12
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 13, 2026 02:12
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 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-13T02:15:06.651577Z c200c8b 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.

@lidge-jun
lidge-jun merged commit b540300 into dev Nov 13, 2026
38 checks passed
@lidge-jun
lidge-jun deleted the codex/quota-passive-headroom branch November 13, 2026 02:12
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.

[Feature]: Surface rate-limit headroom from response headers for API-key providers (OpenAI, Anthropic API, xAI, Groq, Mistral)

1 participant