fix(server): resume threads after merged worktree branches are removed #23132
Problem#
After an agent fast-forwards its work into the project checkout and removes its managed worktree and branch, later messages in the same thread fail: checkout recovery tries the deleted branch, logs ref_not_found, and the provider cannot open the missing workspace. Reproduced in the Linux web dev app with Codex 0.163.0.
Change#
Keep the existing branch checkout attempt. When Git reports ref_not_found, retry once by creating the original branch from the project checkout's current HEAD at the original managed path. The thread binding and provider conversation remain intact. Other Git errors retain the existing handling.
Scope and approval#
Fixes #19124
GitCafe: https://git.cafe/pingdotgg/t3code/issues/19124
Triaged bug via the automated issue flow; GitCafe issue #19124. This completes existing managed-worktree recovery for the deleted-branch case. Recovery uses root HEAD, one of the fallback sources proposed in the report.
Verification#
- Regression first: 026dd900c4 failed the deleted-branch recovery assertion, with the other 22 cases passing. Historical red assertion is a retained summary, not raw runner stdout.
node_modules/.bin/vp test run apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts: 23/23 passed, including after merging current main.vp run typecheckinapps/server(tsc-rs --noEmit): passed. Targeted lint and formatting passed; lint emitted three pre-existing unused-variable warnings.- Fresh independent GPT-6.1-Sol and Claude Opus 5.5 reviews both returned
MERGE; proof audit returnedSUFFICIENT. - Server-only diff: 0/0 visual matrix rows, with regression proof and real-app runtime transcripts. Matrix, evidence index and raw green test output.
| Before: 70e5e384da | After: 13f0f0a1d4 |
|---|---|
| Two messages fail after merged branch and managed checkout are removed. Runtime transcript | The same conversation answers AFTER_FIX; original path and branch are restored at the merged root commit, with the same persisted provider-thread ID. Runtime transcript |
![]() | ![]() |
Supplemental captures use Linux Chromium at 1280×800 with a desktop user agent, no device emulation; DPR was not recorded. These are runtime evidence, not a matched pixel comparison. Visible differences include timestamps, added turns, and a provider update toast; no client rendering code changed. After recording: recording starts 22:47:18 UTC; submit at 22:47:31; response at 22:47:36; recording ends 22:47:48.
Implementation was runtime-tested at 13f0f0a1d4; merging main produced 32b8ca0b38 without changing either affected file, and the focused tests passed again.
Unverified: Electron, native iOS/Android, other provider runtimes and operating systems, remote/relay/tunnel connections, and MCP/scheduled entry points. They share this server path, but were not exercised here. Dev servers started for verification have been stopped.
Models: Claude Opus 5.5 (tests and implementation), GPT-6.1-Sol (triage and proof); T3 Code with Claude Code and Codex harnesses.
- 1
juliusmarminge added labelsvia-triage
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
32b8ca0Macroscope's review found this PR approvable — This focused bug fix adds a tested fallback for recreating a managed worktree when its merged branch no longer exists, while leaving normal worktree restoration unchanged. The companion test-only changes have no production impact.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).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 +7 B (+0.1%) 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.2 KiB 1.2 KiB +7 B (+0.6%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 20.9 KiB 20.9 KiB 0 B (0.0%) 29.3 KiB ✅ Codex Live turn messages 2 2 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB −7 B (−0.1%) 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.2 KiB 1.2 KiB −7 B (−0.6%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB 0 B (0.0%) 29.3 KiB ✅ Claude Live turn messages 2 2 0 (0.0%) 8 ✅ Baseline:
a12d6ed· PR result:32b8ca0· Source CI: successScenario 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. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
754c0c82-bfae-4149-a608-92508fc786ef
📥 Commits
-
Reviewing files that changed from the base of the PR and between a12d6ed9428d8e64d76ca86d178abbf564b57cee and 32b8ca0b38a003864d6c7a602ba88cae57fa3943.
📒 Files selected for processing: 2
-
apps/server/src/orchestration-v2/ProviderTurnStartService.test.tsapps/server/src/orchestration-v2/ProviderTurnStartService.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
-
When recreation of a missing managed worktree fails because its branch reference is not found, the service now retries from
HEADusing the requested branch name. A regression test covers the failure and retry arguments.Changes: Worktree branch restoration
Layer / File(s) Summary Missing branch fallback and regression test
apps/server/src/orchestration-v2/ProviderTurnStartService.ts,apps/server/src/orchestration-v2/ProviderTurnStartService.test.tsWhen Git reports ref_not_found, worktree recreation creates the requested branch fromHEAD. The test injects the initial failure and checks the retry arguments.Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
t3dotgg
Merge Risk: ⚪ Minimal · up to
32b8c-
The branch-restoration retry matches the reported missing-branch failure. No issue identified here needs resolution before merging.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the server fix for resuming threads after managed worktree branches are removed. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Description check The pull request description includes all required sections: Problem, Change, Scope and approval, and Verification. It explains the failure, the fix, linked issue and approval context, focused test re… Full details: Description check
-
Explanation
The pull request description includes all required sections: Problem, Change, Scope and approval, and Verification. It explains the failure, the fix, linked issue and approval context, focused test results, runtime evidence, limitations, and agent details.
-
✨ 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
-
juliusmarminge removed labelsvia-triage
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:gate-failed
juliusmarminge added labelspr:ready
juliusmarminge removed labelspr:gate-failed
juliusmarminge closed this
Closing: main already fixes this via https://github.com/pingdotgg/t3code/pull/18359.
juliusmarminge removed labelspr:ready
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes