fix(server): older probes no longer overwrite live usage limits #18723
main fromrefs/pull/18723/head·merged by juliusmarminge View on GitHubRefreshing Usage → Limits could replace newer live readings with older probe results. Claude made this particularly visible by giving cached usage a fresh timestamp on every status refresh.
Preserve published windows and their read timestamp when a successful probe is strictly older. Keep the probe's reset credits and other metadata. Equal or newer probes still replace the windows, allowing resets and corrections. Claude now captures when its usage request starts and retains that timestamp through its capabilities cache and both usage conversion paths.
Maintainer takeover of #18723, credit to @bitmvk for the original fix. Contributor history is preserved and current main was merged. The original synthetic-cache test was replaced with coverage through the production Claude driver and cache.
Verification on the rebuilt head:
- Two PR-added regression tests retained and rewritten in existing files. Focused suites: 97 passed, including shared usage reconciliation, managed-provider behavior, provider registry, and Claude SDK boundary.
- The driver regression starts an actual capabilities probe with mocked SDK/CLI boundaries, advances TestClock between initialization, usage request, and response, then publishes live usage. Refreshing cached 12% usage preserves the newer 95% live reading and timestamp, while the status timestamp advances. One SDK query confirms cache reuse.
- Three red checks failed as expected when the shared freshness guard was removed, timestamp capture moved after the response, or cached status conversion used refresh time. All fixes were restored before the final passing checks.
- Scoped lint and formatting, provider-core typecheck, server typecheck, and diff check pass.
The proof uses headless server behavior with simulated external readings. No live Claude/Codex account, browser, packaged Electron, macOS, Windows, iOS, or Android verification was performed. This server-side change reaches clients through existing snapshots; no UI or wire-contract changes require before/after screenshots.
Implemented through T3 Code/Codex with gpt-6.1-sol; test rewrite by Codex gpt-6-astra and independent reviews by Claude claude-opus-5-5 and Codex gpt-6-sol.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Approved at
1bff17eMacroscope's review found this PR approvable — This is a small, focused usage-limit freshness fix: newer live readings are preserved over older probe results, and cached Claude usage retains its original read timestamp. The remaining changed files are regression tests, with no product-default, schema, infrastructure, security, billing, or static-analysis changes.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Warning
Review limit reached#
Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.
Next included review available in 23 minutes.
View limit details
-
Limit details: You’ve used all 10 included reviews currently available.
Review configuration:
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
2caa630c-0b93-40c0-9d3b-21a50863bd71
📥 Commits
-
Reviewing files that changed from the base of the PR and between d9ddd83423998c7de704041870b0758e1736a589 and 248e21c31c1907b1917033bea2ba13825c112225.
📒 Files selected for processing: 5
-
apps/server/src/provider/ClaudeCapabilitiesProbe.test.tsapps/server/src/provider/ClaudeProvider.tsapps/server/src/provider/ProviderRegistry.test.tspackages/provider-core/src/server/usageLimits.test.tspackages/provider-core/src/server/usageLimits.ts
-
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
f4ce6842-cf05-40e6-a7eb-ef1955340b7e
📥 Commits
-
Reviewing files that changed from the base of the PR and between cdf156c2c310e47e36e99d4854a0684166d70337 and d9ddd83423998c7de704041870b0758e1736a589.
📒 Files selected for processing: 5
-
apps/server/src/provider/ClaudeCapabilitiesProbe.test.tsapps/server/src/provider/ClaudeProvider.tsapps/server/src/provider/ProviderRegistry.test.tspackages/provider-core/src/server/usageLimits.test.tspackages/provider-core/src/server/usageLimits.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
📝 Walkthrough
-
Claude usage data now carries the time of its probe into provider status. The usage-limit resolver retains published windows when their timestamp is later than the successful probe’s timestamp.
Changes: Usage timestamp freshness
Layer / File(s) Summary Capture and use Claude usage timestamps
apps/server/src/provider/ClaudeProvider.ts,apps/server/src/provider/ClaudeCapabilitiesProbe.test.ts,apps/server/src/provider/ProviderRegistry.test.tsThe capability probe records usageCheckedAtwith available usage data. Provider status uses that timestamp when present and falls back to the status check time. Tests verify the returned timestamp and its retention across status checks.Retain newer published usage
packages/provider-core/src/server/usageLimits.ts,packages/provider-core/src/server/usageLimits.test.tsThe resolver retains the published timestamp and windows when they are later than the successful probe’s. Other fields come from the probe. A test checks this merge behavior. Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix
Suggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
d9ddd-
Older usage probes no longer overwrite newer live usage readings, and equal or newer probes behave as before. No actionable merge-blocking risk was found; confirm CI passes before merging.
Security architecture risk: 🔵 Low · up to
d9ddd-
The change prevents older readings from replacing newer usage data. No new access or privilege path was identified. Account changes within an existing cache lifetime remain incompletely verified, so the assessment retains limited uncertainty.
Retained concerns No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- inferred — The behavioral reach extends beyond one provider because managed providers share the reconciliation helper. The changed operation merges usage snapshots within each managed instance; it does not itself grant credentials or select another account.
Trust Boundaries and Controls
- observed — Reset redemption uses the published grant identifier but rereads the access token and organization from the configured account files. Its destination is the fixed provider API, and usage windows and checkedAt do not supply account authority. This path is unchanged against the supplied base.
Resilience and Maintainability Implications
- observed — Reset recovery invalidates the capabilities cache before refreshing. If a successful reset cannot be confirmed by a changed usage timestamp, the driver reports that uncertainty. Existing redemption coordination serializes by configuration directory and retains the idempotency key after unsettled failures.
-
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the main fix: preventing older probe results from overwriting newer live usage limits. Description check The description includes the problem, implementation details, scope context, focused verification results, limitations, and tool attribution. It is complete and aligned with the repository template. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
Force-pushed a small follow-up folded into the same commit: when newer live usage wins, only its windows are kept, and reset credits and other probe-only fields still come from the probe.
juliusmarminge assignedjuliusmarminge
Taking over this one as maintainer for batch usage-billing-02. I will preserve contributor history, merge main, minimize regression coverage, rebuild the freshness handling to current conventions, and run independent reviews. No merge is planned.
Published the maintainer takeover at d9ddd83, preserving @bitmvk's history and merging main.
Both independent full-diff reviews found no fix-first issues. The two rewritten regression cases cover read ordering/metadata and the production Claude cache-to-snapshot path. All 97 focused tests pass, as do scoped lint/format and provider-core/server typechecks. Three deliberate regressions were confirmed to fail before restoration. The updated body records the proof and that live provider accounts and native clients were not exercised. Waiting for fresh CI; no merge performed.
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
juliusmarminge merged this0d10c36
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes