Skip to content

Mix git deps under gitignored deps/ get worktrees; mix deps.get replaces them and the thread can't be restored #40911

Open

Description

@mavuio

Version: 0.1.12-nightly.20261122.5085 (macOS arm64)

What happens

In an Elixir/Phoenix project, folder discovery treats the Mix git dependencies under the gitignored deps/ folder (deps/heroicons, deps/quick_alias, each a git clone made by mix deps.get) as project repositories. Each new worktree thread then gets a git worktree of each dependency.

Mix can't use those worktrees. Mix.SCM.Git.checked_out? checks for a regular file at deps/<dep>/.git/HEAD, and in a linked worktree .git is a file. So Mix reports "the dependency is not available, run mix deps.get". The agent runs mix deps.get, which deletes the worktree and clones the dependency again.

From then on, every time the thread is restored (after each delegated task finishes, for example), it fails with:

Couldn't recreate thread workspace: Could not recreate the worktree for branch 't3/…' at ~/.t3/worktrees//t3-…

The thread's task_folders row still lists the dependency worktrees, and the path now holds a plain clone. The thread can't recover by itself; I had to clear repositories_json by hand.

Expected

  • Leave gitignored nested checkouts out of discovery by default, or at least the package-manager folders (deps/, node_modules/, vendor/). They aren't the project's repositories.
  • When a recorded nested worktree has been replaced by a plain checkout, restore the thread anyway and drop that entry, rather than failing every restore.

Workaround

A t3.json file in the project root with {"ignoreRepositories": ["deps"]}.

Related: #40406 (gitignored vendor checkouts breaking worktree creation through a checkout hook).

Activity

  1. lejacobroy commented on Nov 23, 2026

    @lejacobroy

    Same here on 0.1.12-nightly.20261122.5111 (Linux x64), so the bug is still there in the build after .5085. It hit every Phoenix project with a {:heroicons, github: ...} dependency (8 projects). Every thread created after discovery picked up a task_folders row for deps/heroicons, and each of them broke at its next restore.

    Where it happens: in WorkspaceFolders.scan, the only top-level children skipped are those starting with . and node_modules. A child without its own history, like deps/, is then searched one level down through childFolders, which finds deps/<dep>/.git. .gitignore is never consulted. On restore, TaskFolders.restore → recreateMissing raises TaskFolderError ("holds a checkout that is not a worktree of …") instead of dropping the entry. The thread then fails at every provider-turn.start with WorktreeRecreateError.

    To recover I needed three steps: t3.json with {"ignoreRepositories": ["deps"]}, emptying trackedFolders on each project (until the next scan does it), and UPDATE task_folders SET repositories_json='[]' on the affected rows. Without that last one, threads that already existed stayed blocked even after the ignore was added.

  2. Jo2234 commented on Nov 24, 2026

    @Jo2234
    Contributor

    Note

    Written by Claude Opus 5.5 on behalf of @Jo2234

    Partly fixed on main by #41907 (66947c7749, merged 2026-11-24). Once a project excludes the dependency ({"ignoreRepositories": ["deps"]} in t3.json), restore drops the stale worktree entry for a recloned dependency instead of failing with WorktreeRecreateError. Existing broken threads recover without editing repositories_json by hand.

    Still open on main: default discovery in WorkspaceFolders.scan picks up gitignored nested checkouts such as deps/, so without the t3.json exclusion new threads still get worktrees of Mix git dependencies (the first "Expected" item).

  3. klinerj commented on Nov 26, 2026

    @klinerj

    Note

    Written by Claude Opus 5.5 on behalf of a T3 Code user, checked against 0.1.13-nightly.20261125.5258 (macOS arm64) and current main.

    Another variant that #41907 doesn't cover: the source clone is deleted, rather than the copy being replaced.

    Setup

    A project keeps short-lived build clones in a gitignored folder, code-wt/<lane>. Each one is a full clone with its own .git directory, and it is deleted once its work lands. Discovery picks up each live clone, so every thread created while it exists gets a linked worktree of it at <thread>/code-wt/<lane>, listed in that thread's task_folders.repositories_json.

    What happens

    1. The lane lands and its clone, the repositoryPath, is deleted.
    2. The thread's copy is untouched, so <thread>/code-wt/<lane>/.git is still a file, pointing into the deleted repo's .git/worktrees/….
    3. On the next turn start, TaskFolders.restore → recreateMissing: isRepository is true and linkedGitDir returns null. It throws TaskFolderError: … holds a checkout that is not a worktree of … Move it away to restore the thread's worktree., which surfaces as WorktreeRecreateError. Every turn in the thread fails, though the thread's own worktree is intact.
    4. fix(server): resume threads after an excluded dependency is recloned #41907 doesn't help, even with the folder in ignoreRepositories. Its check needs lstat(<copy>/.git) to be a directory, and here it's a file. Current main (TaskFolders.ts ~1612) has the same check.
    5. Following the message's advice makes it worse. With the copy moved away, recreate runs git worktree add with cwd set to the deleted source and fails again. The only way out was editing repositories_json by hand.

    Every thread created while that clone existed broke the same way, four in our case.

    Suggested fix

    In restore, a nested copy is secondary to the thread's own worktree. When an entry's repositoryPath no longer exists, or the copy no longer links to it, and the repo was auto-discovered (not explicitly tracked), drop the entry with a warning, leave files on disk, and restore the thread. The message should also not advise moving the copy when its source is gone.

    On the discovery default asked for above: in this project the main nested repo (code/) is gitignored too. A blanket "skip gitignored clones" would drop it, so that needs an opt-in or a migration path. t3.json ignoreRepositories for the lane folder works for new threads, but it doesn't clean entries already recorded.

    Related: #40477

    After we hand-edited repositories_json to unblock the thread, the next user message failed with "…this model or setting change would end them". For a thread with its own worktree, WorkspaceFolders.forThread builds the workspace from the thread's task_folders row, and that workspace is part of queryPolicyKey. So any change to the row, by hand or by a future automatic drop, makes T3 want to replace the Claude process. A finished workflow's background task was still in the roster, which blocked the replacement until Stop. (The notification turn just before had gone through, because continuation turns skip the key check.) If restore starts dropping stale entries, it shouldn't trip this guard.

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