Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): turns recreate a worktree folder that lost its checkout #34894

Mergedjuliusmarmingemerged 4 commits intomain fromrefs/pull/34894/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

The failing Agent context budget check was not caused by this change. The PR does not change any agent context text. After the previous merge, main lowered apps/server/src/provider/agentContextBudget.json by 3 bytes in 0568a63aac (#30371), so the branch's older copy looked like growth. Merging origin/main again (merge commit, no conflicts) brings the budget file to main's values. The PR diff is unchanged: four server files covering worktree recovery in the shared restoreMissingWorktree helper (clears a folder only when it has no .git and holds only node_modules/.next directories), storage cleanup keeping such folders, and their tests.

Fixes pingdotgg/t3code#24390

Reproduction on main

In the app, create a worktree thread in a pnpm project and let setup install dependencies. Stop the turn, record its branch, then delete everything in that worktree except node_modules, including .git; optionally run git worktree prune in the project repository. Send another message to the same thread and ask the agent to report its current directory, branch, and tracked files. On main, recovery is skipped and the folder remains without a checkout; with this change, the leftover directory is removed and the thread's checkout is recreated before provider startup. Separately, trigger storage cleanup for an eligible archived thread in the same broken-folder state: main reports a missing-.git failure, whereas this change reports the folder as kept. These steps were read from the issue and PR, not executed.

Evidence

Evidence captured in Chromium at 1280×800, light theme, against fresh isolated servers with synthetic data and Replay. Create a worktree, install pnpm dependencies, leave only node_modules, remove .git, prune, and resume the thread. Separately archive another broken-folder thread and run storage cleanup. Filesystem observations are measured by the driver and displayed in chat, not generated by Replay. Absolute paths are redacted.

Before b5c0ee56faAfter 6facbfe5e1
Resumed checkoutBefore: missing checkoutAfter: original branch and tracked files restored
Archived-folder cleanupBefore: missing-.git stat failure, 1 kept and 1 failedAfter: 2 kept, no failures
RecordingBeforeAfter

Scenario source · Capture redaction script

scenarios:prove exited 0: failed on base and passed on head.

Not shown:

  • Automatic project setup and interrupting an active turn were not exercised: pnpm was invoked directly in the app-created checkout, and the initial Replay turn finished before folder corruption. A live provider's directory report was not exercised; the driver measured the actual filesystem and git state.

Tests

Compared agentContextBudget.json on the branch and origin/main (5597/7327 vs 5594/7324) and found the main commit that lowered it. After the merge, vp run check:changed passed: format, lint, knip, typecheck (3 packages), tests (3 files). The budget check itself was not rerun locally; CI runs it on the new head.

Not in this change

  • Already-broken folders that hold user files besides node_modules/.next are still not recovered; turns keep running there. Deciding what to do with them needs a maintainer decision.

Who did the work

  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. @@ -219,3 +219,4 @@
      219219 readonly branch: string;
      220220 }) {
      221221 const { cwd, worktreePath, branch } = input;
      222+ yield* fileSystem.remove(worktreePath, { recursive: true, force: true });
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🔴 Critical orchestration-v2/ProviderTurnStartService.ts:222

      When a managed worktree has lost only its .git entry, the next turn recursively deletes the entire worktreePath, permanently removing any remaining modified, untracked, or ignored files. The .git check detects the missing checkout metadata, while isManagedWorktreePath verifies only the path location; preserve the directory by moving it aside before recreation, or refuse recovery when its contents are not safe to discard.

      No longer relevant as of 72db8758b1c64b9ccadc37eeb7e9ae0d6b18a8ac

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

      Approvability

      Verdict: Approved at 72db875

      Macroscope's review found this PR approvable — Restores managed worktrees whose checkout disappeared but left dependency or build directories behind. Recovery preserves existing checkouts and folders containing other entries, while cleanup safely skips folders missing .git.

      No code changes detected at 6facbfe. Prior analysis still applies.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. 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: b5c0ee5 · PR result: 6facbfe · 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.

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

      No actionable comments were generated in the recent review.

      Walkthrough

      Managed-worktree recovery identifies existing directories without .git that contain only node_modules or .next directories, removes eligible managed leftovers, and recreates the worktree. Storage cleanup treats a missing .git entry as a non-linked worktree and propagates other stat errors.

      Changes: Managed worktree recovery and cleanup

      Layer / File(s)Summary
      Detect and recreate incomplete worktrees
      apps/server/src/workspace/restoreMissingWorktree.ts, apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts
      Recovery recognizes eligible managed directories without .git, removes them before recreation, and leaves paths with other contents untouched. Tests cover leftover recovery and preservation of a user file.
      Handle missing worktree links during cleanup
      apps/server/src/storageCleanup.ts, apps/server/src/storageCleanup.test.ts
      A missing .git entry is treated as a non-linked worktree. Other stat errors still propagate. A test verifies that cleanup keeps the directory and its node_modules contents.

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

      Change: Bug fix · Severity of issue fixed: Medium

      Suggested reviewers: t3dotgg, stienswout, tonybynmp4

      Merge Risk: Minimal · up to 72db8

      This change lets turn start recover a managed worktree folder that lost its checkout. It also stops storage cleanup from failing when .git is missing. No actionable merge-blocking risk remains.

      Pre-merge checks: Passed 3 · Inconclusive 1

      Failed Failed checks: 1 inconclusive
      Check nameStatusExplanationResolution
      Linked Issues checkInconclusive[#24390] Requirement A, turn-start recovery: the whole-PR diff (merge base f313d0a6 to head 72db8758) changes apps/server/src/workspace/restoreMissingWorktree.ts, not ProviderTurnStartService.ts. The …1. Confirm that the turn-start path reaches makeRestoreMissingWorktree for an existing managed folder without .git. Name the call site in the explanation or the PR text. 2. Update the PR description to name restoreMissingWorktree.ts and rem…
      Passed Passed checks: 3 passed

      Check nameStatusExplanation
      Title checkPassedThe title names the main change: turn starts recreate a managed worktree folder that lost its checkout. It is specific and conventional, and matches the code, tests, and objectives. It does not descri…
      Out of Scope Changes checkPassedEvery changed file maps to #24390. restoreMissingWorktree.ts adds leftover detection, a managed-path guard, and recursive removal before recreation. storageCleanup.ts handles NotFound for the .git sta…
      Description checkPassedThe description covers the required sections: Problem, Change, Scope, and Verification. It explains that the failing Agent context budget check comes from an older copy of agentContextBudget.json, not…
      Full details: Title check

      Explanation

      The title names the main change: turn starts recreate a managed worktree folder that lost its checkout. It is specific and conventional, and matches the code, tests, and objectives. It does not describe the storage cleanup change, but that is a secondary aspect.

      Full details: Out of Scope Changes check

      Explanation

      Every changed file maps to #24390. restoreMissingWorktree.ts adds leftover detection, a managed-path guard, and recursive removal before recreation. storageCleanup.ts handles NotFound for the .git stat. The tests cover both behaviors. The change to restoreMissingWorktree.ts also includes a comment and a path import, which support the same behavior. No unrelated file changes appear in the whole-PR diff for these paths. The PR description is stale about ProviderTurnStartService.ts, but this is a description mismatch, not an out-of-scope code change.

      Full details: Description check

      Explanation

      The description covers the required sections: Problem, Change, Scope, and Verification. It explains that the failing Agent context budget check comes from an older copy of agentContextBudget.json, not from this change, and that a merge of origin/main resolves it. It states the problem and reproduction steps, links the issue #24390, and describes the change to restoreMissingWorktree and storage cleanup. Verification lists focused commands, the observed results, and the items not exercised. Evidence includes before and after captures. The title is a conventional commit form in the linked PR objectives. The description has minor gaps: it does not state a conventional commit title in the description itself, and the Verification section is detailed but the wording is long. The author also states that the reproduction steps were not executed. The Who did the work section names models and harnesses, as the template asks.

      Full details: Linked Issues check

      Explanation

      [#24390] Requirement A, turn-start recovery: the whole-PR diff (merge base f313d0a6 to head 72db8758) changes apps/server/src/workspace/restoreMissingWorktree.ts, not ProviderTurnStartService.ts. The head adds isLeftoverFolder. It treats a folder as a leftover only when it has no .git entry and every top-level entry is a directory named node_modules or .next. Such folders are removed with fileSystem.remove(recursive) before recreateMissingWorktree runs. This matches the issue's node_modules-only reproduction. The PR description and the previous assessment cite ProviderTurnStartService.ts changes (path.join(worktreePath, ".git") check, forced remove inside recreateMissingWorktree). Those changes are absent from the reviewed diff, so the description is stale. I did not confirm that the turn-start path calls makeRestoreMissingWorktree. Requirement B, storage cleanup: storageCleanup.ts now uses Effect.catchReason("PlatformError", "NotFound") on stat(<worktree>/.git) and returns 'not a linked worktree'. This meets the issue's requirement. Open question: the issue's expected behavior covers any managed path that is not a valid checkout. A managed folder without .git that holds any other entry, such as a user file, is still not recovered. The test 'keeps user file' confirms this is intended. The issue text does not settle whether that is in scope. Tests: the test changes are reported as passing. I did not run them.

      Resolution

      1. Confirm that the turn-start path reaches makeRestoreMissingWorktree for an existing managed folder without .git. Name the call site in the explanation or the PR text. 2. Update the PR description to name restoreMissingWorktree.ts and remove the ProviderTurnStartService.ts claims, or move the change to the file the description names. 3. State explicitly whether a managed folder without .git that holds non-leftover content must stay unrecovered. If the issue requires recovery for it, extend the rule and add a test.
      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 2ae1676f7d6195792bd1da0c4f2c52579e6be5db and 72db8758b1c64b9ccadc37eeb7e9ae0d6b18a8ac.

      Files selected for processing: 4

      • apps/server/src/orchestration-v2/ProviderTurnStartService.test.ts
      • apps/server/src/storageCleanup.test.ts
      • apps/server/src/storageCleanup.ts
      • apps/server/src/workspace/restoreMissingWorktree.ts

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

    6. tanstack-source added labelsbug

    7. juliusmarminge added labelstakeover:in-progress

    8. juliusmarminge added labelstakeover:ready

    9. juliusmarminge removed labelstakeover:in-progress

    10. juliusmarminge merged this5aea99a

    11. juliusmarminge closed this

    12. juliusmarminge removed labelstakeover:ready

Sign in to join this conversation.