fix(server): keep Claude reset times on quick retries #18616
main fromrefs/pull/18616/head·merged by juliusmarminge View on GitHubA quick retry after a Claude usage limit can lose its reset time, disabling existing automatic recovery. Claude suppresses unchanged rate_limit_event frames but repeats the reset in the blocked root assistant’s api_error_params.rate_limit_info.
The adapter now validates that structured payload and keeps it on the latest root response. A later root response clears it; nested responses cannot set or clear it. Event-provided resets remain authoritative for the same window, all rejected windows participate in reset selection, and missing or invalid reset timestamps hold recovery. Valid timestamps from newer window names remain supported. Overage metadata cannot supply a reset. The existing failure and server recovery paths handle ordinary turns and background wake continuations. Main is merged and contributor commits are preserved.
This focused maintainer takeover addresses #15665 without a cross-turn cache, settings, or wire changes.
Verification at 07d581db8f:
- Adapter tests: 285 passing / 3 failing → 288 passing. Exactly two cases were added, matching the author’s final trimmed count: embedded-only wake continuation and competing rejected windows. The latter now uses a future window name, exposing a compatibility regression before its fix without adding a case. Four existing retry rows now carry embedded metadata and assert root/nested isolation and clearing after a later root response. The existing event-present wake case also checks same-window precedence.
- 320 focused tests pass: adapter 288, Claude usage 11, and persisted server recovery scenarios 21. The primary agent independently reran this scope. Recovery scenarios exercise resume, snooze, cancellation and stale runs; they do not represent a live scheduler/client pass.
- Real Claude Code 2.1.303, isolated home, synthetic OAuth token, loopback subscription-limit endpoint: two immediate blocked turns made two local requests. Both root assistants carried the same reset; only the first turn emitted a standalone rate-limit event. The second emitted none. Expected CLI exit 1 because both turns were limited. No real account or subscription quota used.
- Server typecheck, targeted lint, formatting and whitespace checks passed. Lint retains one existing unused
layerwarning. - Current-head CI and bot checks pass, with skipped jobs left as configured. An existing steering test failed in the first server-shard run; local isolation and the full adapter rerun passed, followed by a successful unchanged CI rerun. No code or timeout changes were made for the rerun.
- Two full-diff review rounds on Claude Opus 5.5 and GPT-6 Sol. Round one caught an unnecessary known-window restriction; it was reproduced in an existing test and removed. Both second-round reviews found no substantive issues. The historical stale-root P1 is guarded by the strengthened retry matrix.
This is a server adapter correction shared by web, desktop and mobile; screenshots do not apply. The original screenshots and recording predate this rebuild and are replaced by current-head nonvisual evidence. Running-client snooze/automatic recovery, a live scheduler, real accounts, relay/tunnel, macOS, Windows, iOS, Android and Electron desktop were not verified.
Credit to @realhasanshoaib for the original #18616, and @EhsanulHaqueSiam for the embedded-payload reproduction.
Tests: GPT-6 Astra; implementation: GPT-6.1 Sol; reviews: Claude Opus 5.5 and GPT-6 Sol, through T3 Code’s Codex/Claude harnesses.
- 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
07d581dMacroscope's review found this PR approvable — This is a localized Claude adapter fix that restores reset times lost on quick retries while preserving existing limit handling and overage behavior. The companion changes are test-only and cover the new embedded-payload and precedence cases.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.- Last reviewed commit: 07d581db8fedb79acc65ac67b3a7394cfb46d8ce
Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.
Use the checkboxes below for quick actions:
- ▶️ Resume reviews
- 🔍 Trigger review
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:
dc31bdb1-d60b-42dc-b86b-45756b95d740
📥 Commits
-
Reviewing files that changed from the base of the PR and between b6a95c2dace257ce446520c257f6fd08eb8a5553 and 07d581db8fedb79acc65ac67b3a7394cfb46d8ce.
📒 Files selected for processing: 2
-
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
-
📝 Walkthrough
-
ClaudeAdapterV2 now tracks validated reset data from rate-limit events and rejected assistant messages. It uses assistant-reported reset data when no matching event reset exists. Tests cover reset selection and wake-rate-limit continuation.
Changes: Claude usage-limit reset handling
Layer / File(s) Summary Normalize rate-limit event reset times
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.tsA shared helper validates and converts supported epoch-second reset values to ISO timestamps. Rate-limit event handling uses this helper. Capture and aggregate assistant reset metadata
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts,apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsRoot assistant messages can supply validated rejected-limit metadata unless overage is allowed. The adapter uses the assistant reset when no event reset exists for that limit type. Tests cover event-versus-assistant reset selection, retries, and wake-rate-limit continuation with and without a standalone event. Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
07d58-
The reset handling is mergeable after normal checks. Recovery remains unavailable when the rejected windows do not provide enough trustworthy timing information.
Security architecture risk: 🔵 Low · up to
07d58-
The change retains existing recovery preferences and validates reset times. No new access or permission exposure was identified, but an unresolved retry-exhaustion edge case leaves some uncertainty about automatic recovery timing.
Retained concerns No architecture-level concerns identified.
Security review details
-
Security Blast Radius
- inferred — The demonstrated effect is recovery eligibility and timing for the associated failed thread and run. Continuation commands retain that thread and run identity; the inspected change does not introduce a new command destination or permission setting.
Trust Boundaries and Controls
- observed — Embedded resets are read only from non-replayed root assistant rate-limit errors with rejected structured metadata. Nested messages cannot populate this record, and overage-allowed metadata cannot supply its reset. Existing authentication and terminal-status checks further constrain usage-limit classification.
Resilience and Maintainability Implications
- observed — Existing recovery command generation excludes archived or settled threads, pending runtime requests, and resets no later than the failed run's completion. It uses deterministic thread/run/reset identities and requires armed automatic recovery to be due before generating continuation.
- inferred — Retry-attempt freshness remains conditional on producer ordering: api_retry preserves embedded evidence, while a later root assistant replaces it. The existing exhausted-retry test ends directly in a status-529 result, which the classification guard excludes; it does not resolve the case of an intervening retry followed by a terminal error without explicit status.
-
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly describes the primary fix: preserving Claude reset times during quick retries. It uses a concise conventional commit format. Linked Issues check The change satisfies the coding requirements in [ #15665].ClaudeAdapterV2validates embeddedapi_error_params.rate_limit_infofrom root assistant errors, rejects invalid and overage data, ignores …Out of Scope Changes check The changes remain within [ #15665]. Production changes are limited to Claude adapter reset evidence and selection. Tests cover the required recovery behavior. The reviewed scope adds no cross-turn cac…Description check The description clearly explains the problem, implementation, scope, verification results, limitations, linked issues, and agent attribution. It does not use the template headings, and it does not pro… Full details: Linked Issues check
-
Explanation
The change satisfies the coding requirements in [
#15665].ClaudeAdapterV2validates embeddedapi_error_params.rate_limit_infofrom root assistant errors, rejects invalid and overage data, ignores nested responses, preserves valid event timestamps for the same window, and considers other rejected windows. The selected reset reaches the existing recovery path. Tests cover embedded-only wake recovery, event precedence, clearing after a later root response, and competing windows.
Full details: Out of Scope Changes check
-
Explanation
The changes remain within [
#15665]. Production changes are limited to Claude adapter reset evidence and selection. Tests cover the required recovery behavior. The reviewed scope adds no cross-turn cache, settings change, wire change, client change, text parsing, or unrelated feature.
Full details: Description check
-
Explanation
The description clearly explains the problem, implementation, scope, verification results, limitations, linked issues, and agent attribution. It does not use the template headings, and it does not provide an explicit maintainer approval comment or a clear explanation of why prior approval was unnecessary. These are documentation gaps, but the description is otherwise complete and directly relevant.
-
✨ Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
🧪 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
juliusmarminge added labelsmacroscope-review
💡 Codex Review#
Here are some automated review suggestions for this pull request.
Reviewed commit:
c7ba802d2bℹ️ 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".
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts line 6838OutdatedResolvedby realhasanshoaib(GitHub profile, opens in a new tab)@@ -6805,3 +6826,13 @@68056826 context.nativeMessageCursor = message.uuid;68066827 if (message.parent_tool_use_id === null) {68076828 context.latestAssistantRateLimited = message.error === "rate_limit";6829+ if (message.error === "rate_limit" && isClaudeBlockedAssistantRateLimit(message)) {6830+ const info = message.api_error_params.rate_limit_info;6831+ const overageAllowed =6832+ info.overageStatus === "allowed" ||6833+ info.overageStatus === "allowed_warning" ||6834+ info.isUsingOverage === true ||6835+ info.overageInUse === true;6836+ if (!overageAllowed) {6837+ const limitType = info.rateLimitType ?? "unknown";6838+ context.rejectedRateLimitTypes.add(limitType);Clear embedded limit evidence after a later root response
When Claude internally retries a root call, emits no intervening allowed
rate_limit_event, and a rate-limited assistant is followed by a non-rate-limited root assistant before a status-less finalapi_error, the pre-existing “parent limit then parent response” case inClaudeAdapterV2.test.ts(lines 3401–3413) intentionally expects the final failure to remain a provider error. This set entry is never removed by the later assistant (onlylatestAssistantRateLimitedis reset), so adding the newly observed payload makes that real frame sequence satisfyusageLimitedat lines 7630–7638 and attaches the stale reset, potentially snoozing or auto-resuming a non-limit failure. Store the embedded reset without persistent rejection evidence, or clear that evidence when a later root response supersedes it.Useful? React with 👍 / 👎.
Fixed in 310ec1d854. I reproduced the reported sequence: the new embedded parent-limit-then-root-response case failed as usage_limit before the change. Embedded metadata now belongs only to the latest root response and never adds persistent rejection evidence. A later root response clears it; nested responses do not. The reset merge happens only at the terminal result, preserving event-provided windows. Added cases also cover a newer embedded reset and recovery followed by a fresh limit. All 258 Claude tests, 19 recovery scenarios, server typecheck, and targeted lint pass. Repeated the real CLI/browser retry with no standalone event and verified snooze plus automatic recovery after this change.
juliusmarminge assignedjuliusmarminge
Taking over this one. I will rebuild the embedded reset handling on current main, retain the minimum runtime regressions, and verify quick retry, background wake, event precedence and later-response clearing. I will preserve your commits and push the focused adapter fix here. No merge is planned.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
I statically reviewed the rebuilt adapter and runtime regressions. No additional actionable code issue found in that pass, but current CI is not green: Test Server 7 fails
moves the root's foreground subagents to the background before a steer (answers after the steer went out)withTimed out waiting for background request.The shard reports 1 failed / 1035 passed. Build/typecheck, lint and the other server shards passed. Please isolate this failure before merging; the log alone does not establish whether it is flaky or caused by this change. I have not rerun tests.Failing job: https://github.com/pingdotgg/t3code/actions/runs/39252015565/job/118057870861
@realhasanshoaib Thanks for checking the rebuilt head and flagging the CI failure. I isolated the unchanged steering group: the exact CI row passed locally; one of its neighboring rows (
never answers) instead hit a timeout in that isolated run. The same six rows passed against the main adapter, and the complete adapter suite then passed 288/288 at 07d581db8f. The failing test and its steering/backgrounding path are unchanged by this patch; the CI failure occurs waiting for the background request before rate-limit handling. This points to scheduling sensitivity, but the local results alone do not prove the CI cause. I am rerunning the failed CI jobs once, with no code or timeout changes.I also checked CodeRabbit’s retry-exhaustion caveat: preserving the latest root limit through
api_retrymatches main’s existing classification behavior. A later root response replaces/clears the evidence; explicit non-429 terminal statuses keep their existing exclusion. No producer evidence was provided showing a stale reset on a terminal error without status, so I am leaving that classification policy unchanged in this focused fix.The unchanged CI rerun passed, including all eight server shards, build/typecheck, lint and the aggregate check. Current-head bot checks pass and there are no unresolved review threads. The body now records the failed first attempt and successful rerun. Ready for maintainer review; unmerged.
juliusmarminge merged this9957790
juliusmarminge closed this
Sign in to join this conversation.
Codex Review Summary#
This comment shows the latest Codex review activity on this pull request.
d10d0e2ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.