fix(server): anchor Claude wake cooldowns to result arrival#25061
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:21instead of the expected02:54:21on 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:changedafter 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.529Zpersisted a reset at22:17:22.987Z; after, emission at22:17:39.148Zpersisted22: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
Added 3 commits
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.
Thread transfer impact
✅ Thread transfer remains within every enforced ceiling.
| Provider | Metric | Main baseline | This PR | Impact | PR ceiling | |
|---|---|---|---|---|---|---|
| Codex | Total thread wire | 5.0 KiB | 5.0 KiB | −35 B (−0.7%) | 6.8 KiB | ✅ |
| Codex | Thread snapshot wire | 3.8 KiB | 3.8 KiB | 0 B (0.0%) | 4.9 KiB | ✅ |
| Codex | Live turn WebSocket wire | 1.3 KiB | 1.2 KiB | −35 B (−2.7%) | 2.0 KiB | ✅ |
| Codex | Live turn WebSocket decoded | 21.6 KiB | 21.5 KiB | −41 B (−0.2%) | 24.4 KiB | ✅ |
| Codex | Live turn messages | 2 | 1 | −1 (−50.0%) | 8 | ✅ |
| Claude | Total thread wire | 5.0 KiB | 5.0 KiB | 0 B (0.0%) | 6.8 KiB | ✅ |
| Claude | Thread snapshot wire | 3.8 KiB | 3.8 KiB | 0 B (0.0%) | 4.9 KiB | ✅ |
| Claude | Live turn WebSocket wire | 1.3 KiB | 1.3 KiB | 0 B (0.0%) | 2.0 KiB | ✅ |
| Claude | Live turn WebSocket decoded | 21.9 KiB | 21.9 KiB | 0 B (0.0%) | 24.4 KiB | ✅ |
| Claude | Live turn messages | 2 | 2 | 0 (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.
No actionable comments were generated in the recent review.
External image Recent review info
-
External image Run configuration
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: fix/issue-25021
- File: .coderabbit.config.ts
- Commit: 615c77e
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Team
- Run ID:
e0509365-238e-4cd1-9a36-2a8ebd423d23
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.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; 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.tsThe 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 name Status Explanation Resolution Out of Scope Changes check Warning 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…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 name Status Explanation Title check Passed 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 inste… Description check Passed 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. … Linked Issues check Passed Issue #25021requiresresetAtto 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
#25021and 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
#25021requiresresetAtto use the buffered result arrival time plus the reported relative gateway cooldown. The PR summary and prior reviewed implementation show arrival timestamps passed toproviderFailureFromResult, with a regression test that advancesTestClockbefore 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