Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): retain Claude reset times across usage-limit retries #15110

Closedenurmela(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/15110/headopened View on GitHub

A Claude usage-limit failure can include a valid reset timestamp, then a retry reports only a generic 429 or a repeated rejected notification without resetsAt. The later failure replaces the known timestamp with null, making the recovery banner say the reset is unavailable and preventing native resume-at-reset.

Retain future reset times per rejected window on the same native conversation and model. Sparse notifications and generic retries preserve that information; an allowed notification clears only its own window, and successful or other terminal outcomes clear the retained state. Multiple rejected windows still require all their timestamps before choosing the latest reset.

Validation:

  • ClaudeAdapterV2.test.ts: 131 tests passed, including new cases for sparse notifications, generic retries, unrelated allowed windows and recovery of the blocked window.
  • Focused native runtime usage-limit recovery tests: 25 passed across the adapter and runtime files.
  • Typecheck scoped to the two modified files passed; targeted lint passed with an existing unused layer warning.

GPT-6.1-Sol through the Codex harness in T3 Code.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. @@ -6273,3 +6303,11 @@
      62736303 resultFailure?.class === "usage_limit"
      62746304 ? { ...resultFailure, resetAt }
      62756305 : resultFailure;
      6306+ if (terminalFailure?.class === "usage_limit" && resetAt !== null) {
      6307+ usageLimitResetByNativeThread.set(liveQuery.nativeThreadId, {
      6308+ model: context.input.modelSelection.model,
      6309+ windows: resetWindows,
      6310+ });
      6311+ } else {
      6312+ usageLimitResetByNativeThread.delete(liveQuery.nativeThreadId);
      6313+ }
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium Adapters/ClaudeAdapterV2.ts:6306

      Incomplete usage-limit windows are discarded, so a later sparse retry cannot recover the previously recorded reset timestamp and reports no resetAt. The resetAt !== null guard prevents resetWindows from being persisted whenever any rejected window omits resetsAt; persist the per-window map for every usage-limit failure, including incomplete maps.

      -            if (terminalFailure?.class === "usage_limit" && resetAt !== null) {
      +            if (terminalFailure?.class === "usage_limit") {
                     usageLimitResetByNativeThread.set(liveQuery.nativeThreadId, {
                       model: context.input.modelSelection.model,
                       windows: resetWindows,
                     });
                   } else {
                     usageLimitResetByNativeThread.delete(liveQuery.nativeThreadId);
                   }
      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts around lines 6306-6313:
      
      Incomplete usage-limit windows are discarded, so a later sparse retry cannot recover the previously recorded reset timestamp and reports no `resetAt`. The `resetAt !== null` guard prevents `resetWindows` from being persisted whenever any rejected window omits `resetsAt`; persist the per-window map for every usage-limit failure, including incomplete maps.
    3. juliusmarminge added labelsmacroscope-review

    4. Approvability

      Verdict: Would Approve

      Macroscope's review found this PR approvable — This is a focused server-side bug fix that retains Claude usage-limit reset metadata across retries and adds targeted coverage, without schema, deployment, default, or static-analysis changes. A separate Medium finding notes that incomplete reset-window data can still lose resetAt, representing a remaining correctness risk.

      Not approved because:

      • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. Review in Change Stack →

      Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

      🧰 Additional context used
      📚 Code guidelines (1)
      docs/internals/effect-services.md — configured

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 8e51eb2a-6da5-4189-912e-3b8cf15f5f2c
      📥 Commits

      Reviewing files that changed from the base of the PR and between 6108ef3d3d0ef2a598088a1bb64980580e935830 and 60e71bd450b12b7cc9ee24f79312dd71210f848c.

      📒 Files selected for processing (2)
      • apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
      • apps/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; 9 remain after this review.


      📝 Walkthrough

      Walkthrough

      ClaudeAdapterV2 now retains usage-limit reset times by native thread across turns. Rate-limit events update or clear individual windows. Subsequent failures combine current reset times with valid saved times for the same model.

      Changes

      Claude usage-limit reset retention

      Layer / File(s)Summary
      Track reset times by window
      apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
      ClaudeAdapterV2 stores reset times by native thread. A rejected event without a valid reset uses the saved value for that window. Allowed, allowed-with-warning, or overage events remove that window's saved reset.
      Combine resets across turns
      apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts, apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
      ClaudeAdapterV2 combines current and saved resets for matching models and discards expired saved values. A usage-limit failure saves the combined map when it has a non-null reset; other outcomes delete it. Tests cover reset retention and clearing across turns.

      Priority: ⬇️ Low

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

      Change: Bug fix

      Suggested reviewers: juliusmarminge

      Merge Risk: ⚪ Minimal · up to 60e71

      No identified reset-retention issue remains to resolve before merging. The reported tests and normal checks should still be completed.

      Security Architecture Review

      Security architecture risk: 🔵 Low · up to 60e71

      Recovery remains guarded by existing checks. However, some terminal outcomes leave earlier reset information available to later retries, which can affect when work resumes. Concurrent-start behavior was not fully established.

      Retained concerns

      • Low · reliability · inferred: Retained reset information is cleared for non-usage-limit SDK results, but not by query-exit finalization or an empty continuation completing without a result frame. A future timestamp can therefore survive an intervening transport failure, interruption or empty completion and influence a later same-conversation, same-model usage-limit failure. This weakens terminal-state cleanup and can alter automatic recovery timing. Existing run/reset checks still constrain recovery; no authorization bypass is established.
      Security review details

      Security Blast Radius

      • inferred — The demonstrated effect is recovery timing for a native conversation and selected model within an open provider session, propagated to the associated failed run. The inspected change does not establish wider tenant, credential, environment or service exposure.

      Trust Boundaries and Controls

      • observed — Automatic recovery requires a failed usage-limit run and a reset later than that run's completion. Continuation revalidates recovery consent, run/reset/request identity, provider instance, thread state and absence of pending requests. An expired timestamp reported with a fresh failure cannot itself start a retry loop through the inspected worker.

      Resilience and Maintainability Implications

      • observed — Recovery commands use deterministic identities derived from thread, run, reset and recovery request, supporting duplicate-delivery containment. These checks do not establish whether an earlier timestamp should remain valid after an intervening terminal outcome.
      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly and concisely describes the change: retaining Claude reset times across usage-limit retries.
      Description check✅ PassedThe description explains the problem, the change, and focused verification results. It does not include the required scope and approval information, such as a linked issue or maintainer approval, or e…
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      • Fix all pre-merge checks with AI
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Comment `@coderabbitai help` to get the list of available commands.

Sign in to join this conversation.