Repository navigation
Description
Problem
Opening a folder in VS Code with the Codev extension can write a full Codev scaffold into that folder without anyone asking for it. The write recurs on every reconnect to Tower for as long as the folder has no codev/ directory.
Observed on a repository that was being stripped of an old Codev install: the old codev/, .codev/, .claude/skills/ and .codex/ were deleted on purpose; two minutes later Tower's event stream to that window dropped, the extension reconnected, and .claude/skills/*, .codex/skills/*, codev/, .codev/config.json and .codev-new copies of CLAUDE.md and AGENTS.md reappeared, followed by a Claude merge session nobody launched. Nothing in the window said a scaffold had been written, and Tower's log carried no trace because the step failed on a timeout after the files were already on disk.
Root cause
Two pieces that were each reasonable on their own:
- Tower's activate route adopts implicitly.
launchInstanceinpackages/codev/src/agent-farm/servers/tower-instances.tsrunsnpx codev adopt --yesin any activated folder that lackscodev/(30s exec timeout). This was added for the web dashboard's clickable Recent Projects rows, where a human had just clicked the folder and a "Codev adopted!" toast reported the write. - The extension activates automatically.
apps/vscode/src/connection-manager.tsposts activate for the open folder on every connect and reconnect so overview fetches never race registration. It ignores theadoptedflag in the response and logs only "Workspace activated".
The Switch Workspace command (#1566, apps/vscode/src/commands/switch-workspace.ts) already recognised the hazard and confirms before activating a folder without codev/. That guard is scoped to the command; the connect path inherited the silent adopt.
Two secondary defects compound it:
codev adopt --yesstill launches the CLAUDE.md/AGENTS.md merge session and the adopt process outlives Tower's 30s timeout when that session runs long. Tower then reports "Failed to adopt codev" to the caller, logs nothing, and leaves the half-adopted tree behind.- Adopt failures are not logged by Tower at all, only returned, so a silent write is also an untraceable one.
Fix
- Tower: the activate route takes an explicit
adopt: truein the request body. Without it, a folder lackingcodev/is refused with a distinct, machine-readable error (for exampleneeds_adopt) instead of being adopted. The dashboard's row click and the extension's Switch Workspace flow pass the flag after their existing confirmation. Log adopt attempts, successes and failures. Do not leave a partial tree on timeout: either run adopt without the merge session when invoked by Tower, or raise the timeout and surface the merge step separately. - Extension connect path: on a
needs_adoptrefusal, do not adopt. Show one non-modal notice offering "Adopt this folder" (which re-activates with the flag, reusing the Switch Workspace confirmation text) or "Not now", remembered per workspace so the prompt does not repeat on every reconnect. Honour theadoptedflag in a successful response with a visible notice. - Docs: note in the extension and Tower docs that activation never writes into a folder without an explicit adopt.
Testing
- Tower route test: activate on a folder without
codev/and no flag returns the refusal and writes nothing; with the flag it adopts and logs. - Tower route test: an adopt that exceeds the timeout is logged and reported; assert the on-disk outcome the fix chooses.
- Extension unit test on the connect flow:
needs_adoptproduces the prompt, never an adopt; "Not now" is remembered across reconnects. - Manual: open a non-Codev folder in VS Code with the extension, drop and restore Tower, confirm no files are written until "Adopt this folder" is chosen.
Activity