fix(server): resume threads after merged worktree branches are removed#23132

open3
main
fix/issue-19124
opened6d agobyJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 2d ago

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 typecheck in apps/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 returned SUFFICIENT.
  • 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: 70e5e384daAfter: 13f0f0a1d4
Two messages fail after merged branch and managed checkout are removed. Runtime transcriptThe 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
Before: missing-workspace failureAfter: same conversation completes AFTER_FIX

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.

Checks

21 successful · 13 skipped
All checks passed
32b8ca0

Added 3 commits

  • test(server): reproduce issue 19124 missing worktree with deleted branch026dd90
  • fix(server): a merged and deleted worktree branch is recreated on the next turn13f0f0a
  • Merge remote-tracking branch 'origin/main' into fix/issue-1912432b8ca0
Synced from GitHub

Approvability

Verdict: Approved at 32b8ca0

Macroscope'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.

Synced from GitHub

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ProviderMetricMain baselineThis PRImpactPR ceiling
CodexTotal thread wire5.0 KiB5.0 KiB+7 B (+0.1%)6.8 KiB✅
CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
CodexLive turn WebSocket wire1.2 KiB1.2 KiB+7 B (+0.6%)2.0 KiB✅
CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
CodexLive turn messages220 (0.0%)8✅
ClaudeTotal thread wire5.0 KiB5.0 KiB−7 B (−0.1%)6.8 KiB✅
ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB−7 B (−0.6%)2.0 KiB✅
ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
ClaudeLive turn messages220 (0.0%)8✅

Baseline: a12d6ed · PR result: 32b8ca0 · 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. 🎉

ℹ️ 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.ts
  • apps/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 HEAD using 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.ts
When Git reports ref_not_found, worktree recreation creates the requested branch from HEAD. 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: Passed 4
Check nameStatusExplanation
Title checkPassedThe title clearly and concisely describes the server fix for resuming threads after managed worktree branches are removed.
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.
Description checkPassedThe 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

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