Skip to content

Never activate Codev inside a builder worktree; hide the Agents view there #1809

Closed

Description

@amrmelsayed

Problem

Opening a builder worktree (<root>/.builders/<id>) as the VS Code folder makes Codev treat the worktree as a workspace of its own. The extension activates it in Tower, Tower registers it as a known workspace and spawns a fresh main architect session rooted in the worktree, and the sidebar renders Architects > MAIN with an empty Agents view. Verified today on a shannon worktree window; the global database holds 298 known-workspace rows and 28 architect rows under .builders/ directories.

Owner ruling (2026-10-13): Codev must never activate inside a builder worktree, and the extension's Agents view must not render there at all.

Each stray architect is a live harness session with the worktree as its cwd: it burns a session, carries the #1783 identity trap (its sends belong to a phantom workspace), can act on the worktree if addressed, and leaves rows that outlive the worktree.

Where it happens (verified in source)

  • Extension detection. apps/vscode/src/workspace-detector.ts detectWorkspacePath treats any opened folder that directly contains codev/ as a workspace root, with no ancestor walk (vscode: IDE-mode foundation: dual-mode activation, workspace/IDE context keys, empty-window surfaces #1144, deliberate). A builder worktree is a full checkout, so it matches. Its own comment says worktrees "match directly".
  • Extension activation. connection-manager.ts connects with codev.autoConnect (default on), starts Tower with codev.autoStartTower (default on), then activateWorkspace() POSTs /api/workspaces/<worktree>/activate.
  • Tower. packages/codev/src/agent-farm/servers/tower-instances.ts launchInstance validates only "exists and is a directory", calls registerKnownWorkspace, and spawns the main architect terminal when none exists for that path. The only .builders check in that file is in the instance listing (it hides such workspaces from the Tower list) and does not stop activation.
  • Agents view. In apps/vscode/package.json the codev.agents view carries no when clause, unlike every sibling view (gated on codev.hasWorkspace). It renders in every window, worktree or not.

Expected

  1. Tower refuses to activate a builder worktree. launchInstance (and therefore afx workspace start and the extension's activate call) returns a clear error for a path inside a .builders/ directory, writes no known-workspace row, and spawns no architect. The listing guard stays.
  2. The extension never activates a worktree window. In a window rooted at a builder worktree, the extension does not connect to Tower on that path, does not auto-start Tower for it, and does not activate it. The window keeps the features that are explicitly worktree-aware today (the markdown preview and its review comments, openWorktreeWindow, worktree dev controls, mainCheckoutRoot), which the builder verifies still work.
  3. The Agents view does not render in a worktree window. Gate codev.agents on a context key (for example codev.hasWorkspace && !codev.isBuilderWorktree), so the view is absent, not empty.
  4. Stale rows are cleaned up. A one-time migration or a codev doctor / Tower startup pass removes known-workspace and architect rows whose path contains /.builders/, after confirming no live terminal is attached. Live sessions are never killed by this; report them instead.

Fix shape (hypothesis; verify in source)

  • Detection is by path (/.builders/ segment), matching the existing mainCheckoutRoot regex in terminal-resolve.ts and the listing guard in Tower. A git rev-parse --git-common-dir check is not needed and would add a process spawn to activation.
  • One shared predicate for "is a builder worktree path" in the sdk (environment-agnostic, zero deps), consumed by both the extension and Tower, so the two sides cannot drift.
  • Extension: the detector returns a tagged result (workspace root vs builder worktree vs none); the connection manager skips connect/auto-start/activate for the worktree case and sets codev.isBuilderWorktree.
  • Decision for the plan (route to main before the plan gate, Tower and sdk surface): whether a worktree window should instead attach to the parent workspace (mainCheckoutRoot) so the preview's review-comment delivery and worktree dev controls keep their Tower data, or stay fully disconnected. State the choice and its effect on each worktree-aware feature.

Verification

Real path at the dev gate: open a builder worktree folder in VS Code with Tower running; confirm no activate call is made (Tower log), no new architect appears in afx status, no known-workspace row is written, and the Agents view is absent from the sidebar. Open a plan from that worktree in the preview and confirm review comments still work. Then run afx workspace start from inside a worktree and confirm the refusal message. Confirm the cleanup pass removes the stale rows and leaves live ones.

Protocol and routing

PIR (touches the extension, Tower and the sdk; must be tested in a real window). area/cross-cutting. Owner: vscode architect on the owner's direction; the Tower and sdk sections of the plan go to main before the plan gate.

Activity

  1. added
    area/cross-cutting
    on Oct 13, 2026
  2. amrmelsayed commented on Oct 13, 2026

    @amrmelsayed
    CollaboratorAuthor

    On it! Working on this with the PIR protocol (plan + dev-approval gates before PR).

  3. added 19 commits that reference this issue on Oct 13, 2026
  4. amrmelsayed commented on Oct 21, 2026

    @amrmelsayed
    CollaboratorAuthor

    Shipped in PR #1846 (merged 5bee8027a)

    Your ruling, verbatim, is what this implemented: "codev should never activate inside a builder worktree, nor vs code extension agents view render at all".

    What shipped

    • A worktree window never activates. Opening .builders/<id> as a folder used to register the worktree as a workspace of its own and start an architect for it. Such a window now attaches to the parent checkout read-only and never activates anything.
    • Tower refuses to activate a builder worktree, naming the parent to activate instead, while deactivate still reaches a live stray (it uses the unfiltered known-path list, so a stray is never stranded).
    • Startup prune, ordered reconcile → prune → orphan sweep so liveness is known before anything is removed. It deletes stale worktree rows from all three tables, keeps anything live, and emits one INFO line with the counts. A live stray is reported, never killed.
    • Parent-scoped surfaces are off in a worktree window: no Agents view, no gate or mailbox-escalation notifications, no status-bar builder counts, no activity-bar badge, no spawn handler, and the contextual panel is pinned to the worktree's own builder. The Workspace view keeps only its dev rows. Document Review still works, since it carries no queue actions.

    Decisions worth recording

    1. Accepted deviation, owner-ruled: the Agents view can paint briefly as a worktree window loads, because the context key is set inside activate() and the when clause is fail-open until then. A positive-polarity key would have removed the first-run welcome in every window, so you ruled "accept the flash" on 2026-10-21. Recorded in the review and in its verification list.
    2. Scope grew during the dev gate, deliberately and on your word. Your own testing found gate notifications for sibling lanes, each with an Approve button, and the counts and badge showing the parent's numbers. The three-way review then found two more: the spawn handler (which under auto would open a sibling's writable terminal) and the contextual panel's attention list. Each was closed under the same rule.
    3. Routed out, not forgotten: the Tower view renders in every window and its Deactivate stops another workspace's whole fleet. That is pre-existing and unrelated to this change, so it was traced and filed as Tower view: Deactivate on another workspace's row stops that whole fleet, and the view renders in builder-worktree windows too #1845 rather than fixed here.
    4. A condition from review that mattered: the prune's warning originally told the operator to run afx workspace stop, which cannot reach a stray that Tower never reattached. The warning now splits those cases and gives the process id for the unreachable one.

    Verification

    Owner-verified in the development extension host at the implementation head, covering activation behaviour, the notification/count/badge suppression and the panel pin. Three-way consultation: Gemini APPROVE, Codex and Claude REQUEST_CHANGES, both resolved with regression tests before merge. All seven required checks green on the merged head, Tower Integration included.

    Changelog and release-notes entries are on docs/vscode-changelog (88fc75a87). Review and retrospective: codev/reviews/1809-never-activate-codev-inside-a-.md.

    Also found during this work and filed separately: #1813, on processes a lane leaves behind that no sweep collects.

    Closing as complete.

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

    area/cross-cutting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions