Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): Claude sessions survive slow SessionStart hooks #23202

Openjuliusmarmingewants to merge 10 commits intomain fromrefs/pull/23202/headopened View on GitHub

juliusmarmingecommented

Problem

A Claude turn in a new worktree fails while a legitimate SessionStart setup hook is still running: T3 gives MCP registration 90 seconds, but Claude does not answer that request until the hook completes. In the Linux web dev app with Claude Code 2.1.303, a cold-worktree-only 105-second hook reproduced the failure at 90.2 seconds; the same fixture worked directly in Claude and from its main checkout.

Change

Increase the Claude MCP registration deadline to 690 seconds, allowing the default 600-second hook timeout plus server connection time and slack. Add one regression test that completes registration after 105 seconds. The deadline remains bounded; an unresponsive CLI can now occupy an effect-worker slot for up to 11.5 minutes instead of 1.5 minutes. Hooks explicitly configured beyond this allowance can still time out.

Scope and approval

Fixes https://git.cafe/pingdotgg/t3code/pulls/23151

Triaged bug via the automated issue flow; GitCafe mirror #23155. This fixes the reproduced startup failure in the existing Claude adapter. Both initial isolated reviewers returned MERGE. The subsequent GPT review and Macroscope require human approval for the timing policy: an unresponsive CLI may occupy one of four effect-worker slots for longer. That approval remains pending. No client rendering or tool capabilities change.

Verification

  • Merged main into 52c7dcd. Resolved the timeout comment conflict while preserving the 690-second deadline and single regression test. Focused query-runner tests pass 4/4; scoped lint has no errors and one pre-existing unused layer warning. Formatting and PR-scoped diff checks pass. CI on this head has failed Lint and the aggregate Check. Both PR files pass targeted lint (also with CI=true), formatting and whitespace checks. The Lint job also runs Knip, generated-code checks and vp check; the failing substep is unknown without failed-step logs. No speculative code change was made; the preceding ff91e40 passed CI. Human timing-policy approval remains pending.

  • Red proof: unchanged regression test fails on main plus the test, with “Claude Code did not answer the MCP server registration.” Failing output.

  • Green: vp test run apps/server/src/orchestration-v2/Adapters/ClaudeAgentSdkQueryRunner.test.ts: 3/3 passed, including after merging current main into 13b0993.

  • Follow-up 4ef439b nests the regression test’s layer provisioning to avoid Effect diagnostic TS377033 (multipleEffectProvide). A minimal compiler fixture reproduces exit 2 before and exit 0 after; the focused test file still passes 3/3. CI failed on that earlier head without accessible failed-step diagnostics; the preceding merged head passed CI; CI is pending after the latest main merge. Production code is unchanged from the runtime-tested fix.

  • Targeted lint passed with one pre-existing unused layer warning; git diff --check passed. Scoped server typecheck was stopped after overloading the VM and has no result.

  • Server-only proof matrix is empty: no render paths changed. Runtime captures below were made on b5a226e and 7b67539. The production timeout change remains identical on the latest merged head; the regression test has only provisioning and import adjustments. Focused tests passed again on the merged head.

AttemptBeforeAfter
Cold linked worktree, 105-second SessionStart hookRegistration failed after 90,208.79 msRegistration succeeded after 106,767.69 ms; reply ok
Controls on mainMain checkout, warmed worktree and a resumed follow-up registered in about 0.8–1.0 secondsNo control behavior was changed

Before: Before: cold worktree turn fails at the registration deadline

After: After: cold worktree turn completes following its startup hook

Before recording · After recording. These are supplemental illustrations; the runtime transcript and regression test are the server proof. Chromium headless, Linux x64, 1280×800, light theme. The before recording begins partway through the wait; the after recording shows the whole attempt. No rendering changes are claimed.

Proof index and runtime transcript · Empty render matrix.

Unverified: reporter’s macOS desktop surface, native Windows and mobile; head controls, live-query reuse, the exact 690-second timeout/cleanup boundary, and remote/relay/tunnel execution. Reproduction used isolated empty development state because the real-data snapshot had incompatible migration names. Executing revisions are corroborated by reflog chronology and runtime traces, without a contemporaneous process-to-full-SHA attestation. The proof auditor used local artifact counterparts after public downloads returned HTTP 403. A first after attempt was interrupted by a dev-server restart and is excluded from the success claim.

Implemented with Claude Opus 5.5 through Claude Agent SDK; tests with Claude Opus 5.5; reviewed with GPT-6.1-Sol through Codex and Claude Opus 5.5 through Claude Agent SDK. Triage and evidence coordinated with GPT-6.1-Sol through Codex in T3 Code.

    1. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — The default Claude boot deadline increases from 5 to 11 minutes so slow SessionStart hooks can finish. Human judgment is needed on the tradeoff between successful slow startups and longer waits and resource occupancy for unresponsive sessions.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    2. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages110 (0.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.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages110 (0.0%)8✅

      Other scenarios

      All 64 scenario measurements match main.

      All 64 scenario measurements
      ProviderScenarioMetricMain baselineThis PRImpactPR ceiling
      Codexshort turn resumeWebSocket decoded10.5 KiB10.5 KiB0 B (0.0%)12.7 KiB✅
      Codexshort turn resumeWebSocket messages220 (0.0%)2✅
      Codexlong turn running, cold openHTTP decoded281.7 KiB281.7 KiB0 B (0.0%)302.7 KiB✅
      Codexlong turn running, cold openrows75750 (0.0%)75✅
      Codexlong turn running, history pageHTTP decoded92.4 KiB92.4 KiB0 B (0.0%)107.4 KiB✅
      Codexlong turn running, history pagerows75750 (0.0%)75✅
      Codexlong turn finished, cold openHTTP decoded381.5 KiB381.5 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, socket cold openWebSocket decoded381.6 KiB381.6 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Codexlong turn finished, socket cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, work pageHTTP decoded186.2 KiB186.2 KiB0 B (0.0%)200.2 KiB✅
      Codexlong turn finished, work pagerows1501500 (0.0%)150✅
      Codexidle thread resumeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexidle thread resumeWebSocket messages110 (0.0%)1✅
      Codexfleet shell snapshotHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexfleet shell snapshotrows27270 (0.0%)27✅
      Codexfleet shell subscribeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexfleet shell subscribeWebSocket messages110 (0.0%)1✅
      Codexfleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Codexfleet shell resume checkrows0000✅
      Codexstale shell reloadHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexstale shell reloadrows27270 (0.0%)27✅
      Codexstale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Codexstale shell resumeWebSocket messages220 (0.0%)2✅
      Codexstale todo list cold openHTTP decoded72.4 KiB72.4 KiB0 B (0.0%)83.0 KiB✅
      Codexstale todo list cold openrows75750 (0.0%)75✅
      Codexstale todo list cold opennodes220 (0.0%)4✅
      Codexstale todo list cold opensubagents220 (0.0%)4✅
      Codexstale todo list cold openplans110 (0.0%)2✅
      Codexstale todo list cold openproviderTurns110 (0.0%)2✅
      Codexstale todo list cold opencheckpoints110 (0.0%)2✅
      Claudeshort turn resumeWebSocket decoded10.6 KiB10.6 KiB0 B (0.0%)12.7 KiB✅
      Claudeshort turn resumeWebSocket messages220 (0.0%)2✅
      Claudelong turn running, cold openHTTP decoded283.3 KiB283.3 KiB0 B (0.0%)302.7 KiB✅
      Claudelong turn running, cold openrows75750 (0.0%)75✅
      Claudelong turn running, history pageHTTP decoded93.4 KiB93.4 KiB0 B (0.0%)107.4 KiB✅
      Claudelong turn running, history pagerows75750 (0.0%)75✅
      Claudelong turn finished, cold openHTTP decoded384.2 KiB384.2 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, socket cold openWebSocket decoded384.3 KiB384.3 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Claudelong turn finished, socket cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, work pageHTTP decoded188.1 KiB188.1 KiB0 B (0.0%)200.2 KiB✅
      Claudelong turn finished, work pagerows1501500 (0.0%)150✅
      Claudeidle thread resumeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudeidle thread resumeWebSocket messages110 (0.0%)1✅
      Claudefleet shell snapshotHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudefleet shell snapshotrows27270 (0.0%)27✅
      Claudefleet shell subscribeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudefleet shell subscribeWebSocket messages110 (0.0%)1✅
      Claudefleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Claudefleet shell resume checkrows0000✅
      Claudestale shell reloadHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudestale shell reloadrows27270 (0.0%)27✅
      Claudestale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Claudestale shell resumeWebSocket messages220 (0.0%)2✅
      Claudestale todo list cold openHTTP decoded73.4 KiB73.4 KiB0 B (0.0%)83.0 KiB✅
      Claudestale todo list cold openrows75750 (0.0%)75✅
      Claudestale todo list cold opennodes220 (0.0%)4✅
      Claudestale todo list cold opensubagents220 (0.0%)4✅
      Claudestale todo list cold openplans110 (0.0%)2✅
      Claudestale todo list cold openproviderTurns110 (0.0%)2✅
      Claudestale todo list cold opencheckpoints110 (0.0%)2✅

      Baseline: f313d0a · PR result: 913dfa8 · 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.

    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      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_commits setting.

      • Last reviewed commit: 96d6890a9b3019ae4e23c38d28eac29564c7f646
      • Latest commit, not reviewed: 913dfa8e3dd4e13f1a9aef5d1c7f1edd588016a3

      Use the following commands to manage reviews:

      • @coderabbitai resume to resume automatic reviews.
      • @coderabbitai review to trigger a single review.

      Use the checkboxes below for quick actions:

      • Resume reviews
      • Trigger review

      No actionable comments were generated in the recent review.

      Walkthrough

      The Claude MCP registration timeout increases from 90 to 690 seconds. Tests cover successful opening after registration resolves at 105 seconds and existing timeout recovery, retry, and failure cases with the longer deadline.

      Changes: Claude MCP registration timeout

      Layer / File(s)Summary
      Configure and test the registration timeout
      apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts, apps/server/src/orchestration-v2/Adapters/ClaudeAgentSdkQueryRunner.test.ts
      The timeout increases to 690 seconds. The comments describe SessionStart-hook delays and per-server connection timeouts. Tests cover registration resolving after 105 seconds, stalled-registration recovery, process-exit retry behavior, and failure after repeated timeouts.

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

      Change: Bug fix · Severity of issue fixed: Medium

      Possibly related issues

      • pingdotgg/t3code#23151 — The issue reports startup failure when a SessionStart hook exceeds the former 90-second deadline. This change raises that deadline.

      Possibly related PRs

      • pingdotgg/t3code#22365 — Both changes address Claude MCP registration-timeout handling and its effects on session startup.
      • pingdotgg/t3code#25372 — Both changes cover timeout recovery and process cleanup in the Claude adapter and its tests.
      • pingdotgg/t3code#30166 — Both changes modify Claude SDK startup deadlines, including MCP registration timing.

      Suggested reviewers: bil0000

      Merge Risk: Minimal · previous review 96d68

      Claude sessions can wait longer for slow startup hooks. No concrete issue currently prevents merging, though the longer wait is an operational tradeoff.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: allowing Claude sessions to survive slow SessionStart hooks.
      Description checkPassedThe description includes all required sections: Problem, Change, Scope and approval, and Verification. It provides reproduction details, implementation scope, test results, runtime evidence, known lim…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Description check

      Explanation

      The description includes all required sections: Problem, Change, Scope and approval, and Verification. It provides reproduction details, implementation scope, test results, runtime evidence, known limitations, and unresolved CI and approval items.

      Finishing Touches

      Generate unit tests (beta)

      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 52c7dcdeb3d86ccd382a582ec79fb317884cc6bd and 96d6890a9b3019ae4e23c38d28eac29564c7f646.

      Files selected for processing: 2

      • apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
      • apps/server/src/orchestration-v2/Adapters/ClaudeAgentSdkQueryRunner.test.ts

      Limit details: You’ve used all 10 included reviews currently available.

    4. juliusmarminge added labelsvia-triage:gates-failing

    5. juliusmarminge added labelspr:gate-failed

    6. juliusmarminge removed labelsvia-triage:gates-failing

    7. The new regression test triggered Effect diagnostic TS377033 (multipleEffectProvide) in a minimal compiler reproduction: chained provisioning exits 2; nested provisioning exits 0. 4ef439b applies the existing nested test pattern. Focused tests pass 3/3; CI confirmation is pending. The production timeout change is unchanged.

      The longer deadline's tradeoff remains for maintainer approval: an unresponsive Claude process can hold an effect-worker slot for up to 690 seconds. No automatic landing is enabled.

    8. CI on 4ef439b has 12 failed checks: Build and Typecheck, Lint, Test, all eight server shards, and Check. Cafe provides conclusions and timestamps, but no failure output or annotations; its job-log endpoint rejects the GitHub check IDs. No current failure cause is established. Several other checks were skipped, including Test Web and Rust.

      Diagnosis needs the failed step, first error, and exit code from the CI run, starting with Lint, Build, and Server 1. No further code change was made.

    9. Evidence

      Configure a startup SessionStart command hook with timeout 600 and a first-run setup script that sleeps 105 seconds. Create a fresh linked-worktree Claude thread and send reply ok. Repeat with another fresh worktree on the other commit using the same driver.

      Environment on both sides: real web app and Claude provider, separate fresh databases, Chromium 1280×800, light theme, synthetic data. Chat captures exclude private metadata. Videos begin approximately 28 seconds into startup.

      BeforeAfter
      a0efdaeb8996d6890a9b
      Before: Claude MCP registration timed outAfter: Claude answered ok after slow setup
      Startup recordingStartup recording
      Failed after 90.675 seconds, before setup completed.Hook completed after 105 seconds; ok arrived after 110.029 seconds.

      Reproduction driver · Persisted timing transcript

      AI-assisted; verified with the tests and tools listed above.

      Not shown:

      • The full 690-second registration allowance was not exercised; this comparison verifies the reported 105-second startup hook.
    10. The automated pipeline stopped on this pull request and will not merge it:

      someone else pushed to fix/issue-23151 (head is now da798c0a8d); the pipeline does not build on commits it did not review

      It stays open for a person to finish or close.

    11. tanstack-source added labelsbug

    12. Note

      🤖 Claude Fable 5.2 responding on behalf of Theo

      #30166 merged as 86e2cb2 and covers most of this PR. This branch now conflicts with main in ClaudeAdapterV2.ts.

      What changed on main: the 90 second registration limit starts after Claude Code finishes startup, and startup has its own 5 minute limit (CLAUDE_BOOT_TIMEOUT).

      Measured on the merge commit with the real Claude CLI (2.1.322) and Agent SDK 0.3.321: a SessionStart / startup hook that sleeps 100s no longer fails. ClaudeAgentSdkQueryRunner.open succeeds after 100.3s. The 105 second fixture in this PR's evidence is in that range.

      What is left: a hook that runs for more than 5 minutes. This PR allows 690 seconds, and main allows 300 seconds for startup. If that case matters, the smaller change is now to raise CLAUDE_BOOT_TIMEOUT, not CLAUDE_MCP_REGISTRATION_TIMEOUT.

      My judgment: this PR is superseded unless hooks longer than 5 minutes need support. I did not close it.

    13. juliusmarminge added labelstakeover:in-progress

    14. The automated pipeline stopped on this pull request and will not merge it:

      the fix is written and reviewed, but proving it needs something no worker has:

      • Permanent blocker: real Claude execution requires first-party Claude authentication, which the VM brief lists as unavailable and explicitly prohibits working around. Although the installed CLI reports an OAuth login, that does not establish usable authenticated execution, and no provider turn was attempted.
      • A SessionStart hook exceeding five minutes fails on base and completes on head: not demonstrated.
      • Stalled initialization and MCP registration retain bounded deadlines: not demonstrated in the real app.

      It stays open for a person to finish or close.

    15. juliusmarminge added labelstakeover:blocked

    16. juliusmarminge removed labelstakeover:in-progress

Sign in to join this conversation.