Repository navigation
fix: make dependencies available in isolated worktrees - #321
chaitanyagiri merged 1 commit into
Conversation
An isolated worktree does not include the base checkout's dependencies, so project validation can fail before it checks an agent's change. Link the dependencies after creating the worktree, while preserving existing entries and allowing the spawn to continue if linking fails. Before deciding whether a worker worktree is dirty, remove only a dependency link that resolves to the base checkout's node_modules. This keeps unignored links from preventing automatic cleanup while preserving real directories and foreign links. Use Windows junctions so directory links work without elevated privileges. The regression coverage verifies link creation, skip and failure paths, cleanup without a .gitignore, Windows link selection, and that git worktree removal leaves the base dependencies intact.
|
Reviewed by an agent on the Munder Difflin hive floor, posted from @chaitanyagiri. The two unlink call sites are ordered correctly and the difference between them is deliberate in The thing I would want in the PR body is the isolation caveat, because right now it is not Second, the link makes the worktree dirty for its whole life, not just at teardown. Your own The two teardown paths are handled. What about the agent itself? An agent that runs On the last three tests: they regex the text of
|
What & why
Spawning an agent into an isolated worktree gives it a checkout with no
node_modules. Typecheck then fails on missing type definitions and tests and build fail on missing packages.This links the base checkout's dependencies into the worktree right after the worktree is created successfully, and removes that link again before the retention and garbage-collection checks so an untracked entry cannot make a worktree look permanently dirty. An existing entry is left alone, and a link failure is logged without blocking the spawn, so the worst case is the behaviour we already have today.
Two notes for the reviewer. Cleanup only removes an entry that is a symlink and resolves to the base checkout's
node_modulesa real directory, or a link pointing anywhere else, is left alone, and there are tests pinning both refusals. And because the worktree shares the base'snode_modules, annpm installrun inside a worktree writes through the link into the base checkout; that is inherent to sharing rather than copying.Type of change
Evidence
Before
A fresh isolated worktree, running the project's own typecheck:
With the dependency-link step removed, three of the regression tests fail:
After
The same command in the same worktree, with the dependencies linked:
Full suite with the change applied:
How I tested it
mainwith nonode_modulesand rannpm run typecheck— reproduced the twoTS2688errors above.node_modulesand re-ran the identical command in the identical worktree — 0 errors.npm run test:focusedon a clean branch cut frommain: 564/564 (baseline onmainis 552; this adds 12).npm run typecheck— 0 errors.npm run build— succeeds.The deletion guards are covered by name: removing the symlink type check makes
does not remove a real worktree node_modules directoryfail, and removing the resolved-target comparison makesdoes not remove a worktree node_modules link to another directoryfail. Teardown safety was the other case worth being careful about:git worktree remove --forcemust not follow the link and delete the base checkout'snode_modules. Test 556 covers that, and it asserts the symlink exists before the removal runs.Checklist