Repository navigation
Description
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/server
Steps to reproduce
- Add a project script with "Run on worktree creation" turned on, for example:
date > "$(git rev-parse --git-dir)/setup-ran" - Start a thread in a new worktree and send a message. The setup script runs and the file exists.
- Let the thread go idle, then remove its worktree: either let storage cleanup do it ("Delete unchanged worktrees" on, thread with no commits of its own), or run
git worktree remove <worktree path>in the project checkout. - Send the thread another message.
These steps come from the source and a real trace (see Logs). I didn't replay them on a fresh install.
Expected behavior
The restored worktree runs the same "run on worktree creation" scripts as a new worktree.
Actual behavior
T3 Code recreates the worktree at the same path and starts the turn, but no setup script runs. Anything a setup script provides (links, config files, installed dependencies) is silently missing. Nothing in the UI shows that setup was skipped.
In our case a setup script links a CLI's config file into the worktree's git dir. After restore the link was gone, and that CLI's API calls failed with 401 until we recreated the link by hand.
With "Delete unchanged worktrees" on, this happens after any idle period on a thread that has no commits yet, so it recurs often.
Cause, from source on main @ 47f2c8d: recreateMissingWorktree in ProviderTurnStartService.ts only prunes and runs createWorktree. It never calls ProjectSetupScriptRunner, which ThreadLaunchService and WorktreeMcpService both use for new worktrees. The terminal restore path in #24156 has the same gap.
Impact
Major degradation or frequent failure
Version or commit
0.1.3-nightly.20261027.3754 (code unchanged on main @ 47f2c8d)
Environment
Linux (WSL2, kernel 6.18), git 2.47.3, local server
Logs or stack traces
# server.trace.ndjson, times local, paths redacted
10:34 thread created: GitVcsDriver.createWorktree (9 args), then terminal.startSession
for the setup script
11:56 StorageCleanup.sweep: integratedBranch, branchChanged, localChanges, submodules,
WorktreeRemoval.removeLinkedWorktree on ~/.t3/worktrees/<project>/t3-<id>
12:07 next message: "provider turn start recreating missing worktree",
GitVcsDriver.pruneWorktrees, GitVcsDriver.createWorktree (7 args), same path.
No terminal.startSession for the setup script follows.Screenshots, recordings, or supporting files
No response
Workaround
Rerun the setup script by hand in the restored worktree, or turn off "Delete unchanged worktrees" so idle threads keep their worktree.
Related:
- feat(worktrees): manage checkout lifecycle on the server #15080 (open) would fix this as part of its larger worktree lifecycle change. This issue tracks the bug on its own.
- [Bug]: t3_worktree_handoff never runs the project setup script (call interrupted when the session detaches) #21953: same gap for worktree handoff, fixed there.
- [Bug]: Terminal shows "cwd does not exist" after storage cleanup removes a thread's worktree #24154 / fix(server): terminals recreate a worktree removed by storage cleanup #24156: terminal restore path.
- fix(server): a thread whose worktree was deleted recovers on the next message #18359, fix(server): deleted worktree threads recover from a detached checkout #26758: restore on next message.
- Storage cleanup removes a fresh worktree while its first turn waits for a usage-limit reset #24389 / fix(server): cleanup keeps worktrees waiting for a usage-limit reset #24689: the unchanged-worktree rule (narrow fix merged).
(co-written with Claude Opus 5.5)
Activity