Skip to content

Keep following a finished subagent's worktree while it exists - #109

Merged
badcuban merged 1 commit into
mainfrom
subagent-worktree-linger
Aug 4, 2026
Merged

Keep following a finished subagent's worktree while it exists#109
badcuban merged 1 commit into
mainfrom
subagent-worktree-linger

Conversation

@badcuban

@badcuban badcuban commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Problem

Observed live (thread c9acfc40, Aug 4): launching an isolated subagent correctly flipped the thread's checkout indicator to the agent's worktree (SubagentWorktreeFollower, source subagent), but the moment the task ended the follower cleared the inference and the indicator snapped back to the configured checkout — while the session went on reviewing, fixing, committing, and opening a PR in that worktree for hours. The session never announces such a move: it navigates with plain cd and absolute paths, which neither Claude's session metadata nor the EnterWorktree event path can see. Result: the checkout chip and the source-control panel watched the wrong checkout for the rest of the session.

Fix

A followed worktree now lingers after its task ends. The heuristic: an isolated agent's worktree survives its task exactly when the agent left changes behind — which is exactly when the session keeps working there.

  • On last-task end, a delayed validation (2s, skipping the harness's unchanged-worktree cleanup race) checks whether the path is still a checkout of the thread's repository (git worktree list, same validation as at follow time). If yes, it stays followed; if the worktree is gone, the inference clears as before.
  • Reconciliation is deferred to the validation so the indicator never flickers back to the configured checkout while the answer is pending.
  • The linger ends when a new agent task starts (new inference supersedes), the session ends, or the worktree no longer exists. Session-reported cwds (effectiveCwdSource: "session") still override inference, unchanged.
  • make is now parameterized (lingerValidationDelay) so tests don't sleep real seconds.

Testing

  • ProviderRuntimeIngestion suite 72/72: the old "stops when the subagent finishes" test now asserts the linger (worktree still listed → still followed), plus new coverage for worktree-gone-at-task-end → cleared, and new-task-supersedes-linger.
  • vp fmt / vp lint clean (pre-existing CommandPalette warnings only).
  • Pre-existing on clean origin/main, unrelated to this change: two raw-tsc errors (ProviderInstanceRegistryLive.test.ts, server.test.ts) and the forwards WebSocket compression options test failure — all reproduce with this diff stashed.

@vercel

vercel Bot commented Aug 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
threadlines Skipped Skipped Aug 4, 2026 5:38am

Request Review

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:M labels Aug 4, 2026
When an isolated subagent finishes, its worktree survives exactly when
it left changes behind — and the session usually keeps working there
(review, fixes, commit) without ever announcing the move. The follower
used to clear the thread's inferred cwd the moment the task ended, so
the checkout chip and source-control panel snapped back to the
configured checkout while all subsequent work landed in the worktree.

The last task's checkout now lingers: after a short delay (skipping the
harness's unchanged-worktree cleanup race), it stays followed while
git still lists it as a checkout of the thread's repository. The linger
ends when a new agent task starts, the session ends, or the worktree is
gone. Session-reported cwds still override inference.
@badcuban
badcuban force-pushed the subagent-worktree-linger branch from 77bba08 to dd1eef1 Compare August 4, 2026 05:38
@badcuban
badcuban merged commit f1b25a2 into main Aug 4, 2026
19 of 21 checks passed
@badcuban
badcuban deleted the subagent-worktree-linger branch August 4, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant