Skip to content

[Bug]: Restoring a removed worktree skips the project's setup scripts #30765

Open

Description

@vySoSerious

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

  1. Add a project script with "Run on worktree creation" turned on, for example: date > "$(git rev-parse --git-dir)/setup-ran"
  2. Start a thread in a new worktree and send a message. The setup script runs and the file exists.
  3. 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.
  4. 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:

(co-written with Claude Opus 5.5)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions