fix(server): anchor Claude wake cooldowns to result arrival#25061

open4
main
fix/issue-25021
opened7d agobyJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 2d ago

Problem

A Claude wake result containing a gateway's relative cooldown can wait in the wake buffer before its continuation starts. Replaying that result added the cooldown to replay time, extending the reset by the entire queue delay.

Change

Keep the arrival time of buffered result frames in memory and use it when deriving a relative gateway reset. Turn completion timestamps still reflect when the continuation completes.

Scope and approval

Fixes https://github.com/pingdotgg/t3code/issues/25021

GitCafe: https://git.cafe/pingdotgg/t3code/issues/25021

Triaged bug via the automated issue flow. This change only corrects the existing Claude gateway reset calculation.

Verification

  • Red regression: buffering a wake gateway result, advancing TestClock one hour, then replaying it produced 03:54:21 instead of the expected 02:54:21 on main. The fix makes the test pass.
  • Full ClaudeAdapterV2.test.ts: 236/236 passed (including nine gateway cases and the regression).
  • Final vp run check:changed after merging main: all checks passed (format, GraphQL generation, lint, both knip passes, affected-package typecheck, and all 236 adapter tests).
  • Real-app baseline: Claude Opus 5.5 launched a native background Agent, ended its root turn, and completed the wake normally through the configured gateway.
  • Controlled runtime reproduction: the real dev server consumed a CLI protocol fixture. Before, a one-minute wake result emitted at 22:16:22.529Z persisted a reset at 22:17:22.987Z; after, emission at 22:17:39.148Z persisted 22:18:39.148Z. The fixture substitutes for external gateway exhaustion; it does not claim the live pool was exhausted.

Evidence: evidence index, runtime transcript, before data, after data, fixture driver, proof matrix.

Both independent code reviews returned MERGE, and the final proof audit returned SUFFICIENT. Main was merged into the fix branch; the reviewed adapter and test sources are unchanged at final head 7efb37a23868e9e7ed37c4226983e7bc9db1acc1.

The visual matrix is empty: no render paths changed. Live gateway exhaustion and the full expired-reset auto-resume sequence were not exercised; the deterministic test covers the delayed replay calculation.

Models: Claude Opus 5.5 and GPT-6.1-Sol; harnesses: Claude Code and Codex through T3 Code.

Checks

20 successful · 20 skipped
All checks passed
615c77e

Added 3 commits

  • fix(server): buffered Claude wake gateway limits reset from their arrival064702b
  • Merge main into fix/issue-250217efb37a
  • test(server): reproduce #25021 buffered wake gateway limit resetAt drifts to replay timed26109d
Synced from GitHub

Approvability

Verdict: Approved at 7efb37a

Macroscope's review found this PR approvable — This is a focused server bug fix that prevents buffered Claude wake results from extending gateway cooldowns by the replay delay. Existing direct-result behavior remains unchanged, and the delayed-replay case has targeted regression coverage.

No code changes detected at 615c77e. Prior analysis still applies.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ProviderMetricMain baselineThis PRImpactPR ceiling
CodexTotal thread wire5.0 KiB5.0 KiB−35 B (−0.7%)6.8 KiB✅
CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
CodexLive turn WebSocket wire1.3 KiB1.2 KiB−35 B (−2.7%)2.0 KiB✅
CodexLive turn WebSocket decoded21.6 KiB21.5 KiB−41 B (−0.2%)24.4 KiB✅
CodexLive turn messages21−1 (−50.0%)8✅
ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
ClaudeLive turn WebSocket wire1.3 KiB1.3 KiB0 B (0.0%)2.0 KiB✅
ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
ClaudeLive turn messages220 (0.0%)8✅

Baseline: 97e35bc · PR result: 615c77e · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

Synced from GitHub

Review in Change Stack →

No actionable comments were generated in the recent review.

External image Recent review info
External image Run configuration
External image Commits

Reviewing files that changed from the base of the PR and between 7efb37a23868e9e7ed37c4226983e7bc9db1acc1 and 615c77e04ea714def5a45bcee0ab8a7e5613f857.

External image 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; 2 remain after this review.

Walkthrough

The Claude adapter records arrival times for buffered wake results and uses them to calculate gateway rate-limit reset timestamps. A regression test checks that a one-hour replay delay does not shift the reset timestamp.

Changes: Wake-result cooldown timing

Layer / File(s)Summary
Track arrival time through buffered result handling
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts, apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
The adapter records each buffered result’s arrival time and uses it as the base for gateway rate-limit reset calculations. If no arrival time is available, it uses completedAt. The regression test checks the reset timestamp after a one-hour replay delay.

Priority: External image Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • pingdotgg/t3code#25438 — This PR moves cooldown parsing into a shared helper that must preserve the arrival-time base for replayed results.
  • pingdotgg/t3code#25022 — This PR changes the same reset-time behavior and adds delayed-continuation regression coverage.
  • pingdotgg/t3code#25520 — This PR shares cooldown parsing for wrapped 503 and plain 429 results, so its reset-time base must align with this change.

Suggested reviewers: t3dotgg

Merge Risk: External image Minimal · up to 615c7

The change targets cooldowns extended by delayed replay. No merge-blocking issue was identified.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check nameStatusExplanationResolution
Out of Scope Changes checkWarningThe current head includes unrelated changes beyond issue #25021. The incremental diff adds Claude settings handling, device instructions, launch-argument parsing, MCP timeout and process-stop behavior…Remove the unrelated main-branch and feature changes from this PR, or retarget the branch so the reviewed diff contains only the Claude gateway reset fix and its focused regression test.
Passed Passed checks: 3 passed
Check nameStatusExplanation
Title checkPassedThe title "fix(server): anchor Claude wake cooldowns to result arrival" matches the main change. The raw summary and objectives say gateway reset times now use the buffered result's arrival time inste…
Description checkPassedThe description follows the template's main sections: Problem, Change, Scope and approval, and Verification. The Problem section explains the delayed replay that extends the reset by the queue delay. …
Linked Issues checkPassedIssue #25021 requires resetAt to use the buffered result arrival time plus the reported relative gateway cooldown. The PR summary and prior reviewed implementation show arrival timestamps passed to …
Full details: Title check

Explanation

The title "fix(server): anchor Claude wake cooldowns to result arrival" matches the main change. The raw summary and objectives say gateway reset times now use the buffered result's arrival time instead of replay time. The title follows conventional commit format, is one sentence, and names the affected area (server) and the behavior changed. It is specific enough for a teammate scanning history.

Full details: Description check

Explanation

The description follows the template's main sections: Problem, Change, Scope and approval, and Verification. The Problem section explains the delayed replay that extends the reset by the queue delay. The Change section explains that arrival time is kept in memory and used for relative gateway resets. The Scope section links issue #25021 and says it is a triaged bug. The Verification section gives specific test results, a red-then-green regression, and a runtime reproduction with timestamps. Minor gap: the template asks for a conventional commit title in the comment block, which the title meets. The description also does not state the Problem reproduction steps in detail for the live environment, but it gives enough context. The Scope section cites an automated triage flow rather than a maintainer approval comment. The template asks for the triaged issue or a maintainer approval comment, so the reviewer may need to confirm the approval evidence. The description is mostly complete.

Full details: Linked Issues check

Explanation

Issue #25021 requires resetAt to use the buffered result arrival time plus the reported relative gateway cooldown. The PR summary and prior reviewed implementation show arrival timestamps passed to providerFailureFromResult, with a regression test that advances TestClock before replay. The current evidence does not show a missing coding or test requirement.

Full details: Out of Scope Changes check

Explanation

The current head includes unrelated changes beyond issue #25021. The incremental diff adds Claude settings handling, device instructions, launch-argument parsing, MCP timeout and process-stop behavior, port tracking, and related test changes. These changes do not support the gateway reset calculation. The merge history also shows unrelated main-branch commits included in the current head.

Resolution

Remove the unrelated main-branch and feature changes from this PR, or retarget the branch so the reviewed diff contains only the Claude gateway reset fix and its focused regression test.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Added 1 commit

  • Merge branch 'main' into fix/issue-25021615c77e