Repository navigation
Fix #1783: resolve builder identity from the spawn environment, not only cwd - #1784
Conversation
…nly cwd .builder-start.sh exports CODEV_BUILDER_WORKTREE; detectCurrentBuilderId and detectWorkspaceRoot prefer it over the cwd (still verified against global.db), so a builder running 'cd <root> && afx send architect' routes to its spawning architect. sanitizeAgentEnv strips the var; vitest-setup clears it. Docs narrow the 'afx only from the main root' rule for a builder's own afx send.
… guard, setup constant
Integration review (main) — high tier, 3-way CMAP on 048c482Codex APPROVE · Claude APPROVE · Gemini skipped (agy produced no output; non-blocking). CI 7/7 green. Branch is one merge behind main (#1780, no shared files). Verified
Two small changes before the gate word (cheap, in scope)
Follow-ups filed / extended
|
…up env-named worktree throws
|
Addressed integration review. New head:
Note on scope: if only the directory is deleted and the builder row remains, resolution returns the row's builder id. It does not throw and does not fall back to non-builder. That matches the existing cwd path, which has never checked the disk. Adding a disk-existence check would change behaviour, so I left it out. It's a one-line |
|
Ruling recorded for the edge the builder raised: when |
…of rule-plus-exception The rule now names the commands it protects; the builder afx send case is its own sentence. Builder role and afx skill note trimmed to one sentence. Doc-only.
|
Doc-only follow-up at the owner's request. New head: The owner found the "rule, then an exception to it" wording confusing. The root-only rule now names the commands it protects, and the builder case is its own sentence:
All copy pairs are byte-identical. The doc-guarding tests (scar-rules, parity, skills) pass: 26 files, 459 tests. No code changes. |
Architect review, round 3 (head c2798b3)The head moved off f277d60 for an owner-requested wording change. Re-verified on the new head:
Architect approval carries to c2798b3. Waiting on the full check set on this head, then the owner's pr-gate word. |
Most afx commands resolve a builder worktree as its own workspace (findWorkspaceRoot), so narrowing the rule to spawn/cleanup was wrong. With identity now carried in CODEV_BUILDER_WORKTREE, builders can follow the rule as written, so no exception is needed.
|
Owner-directed follow-up. New head: All doc edits are reverted to the base. The PR is now code, tests and the thread log only (8 files). The previous commit narrowed the root-only rule to No exception is needed. With identity carried in The doc-guarding tests pass (26 files, 459 tests). The PR description is updated. |
Summary
A builder that ran
cd <main root> && afx send architect(following the CLAUDE.md "run afx from the main workspace root" rule) resolved as a non-builder, so plainarchitectrouted tomaininstead of its spawning architect, and thearchitect:<name>spoofing guard was skipped. Builders now carry their identity in their spawn environment, so it resolves from any cwd.Fixes #1783
Root Cause
detectCurrentBuilderId()anddetectWorkspaceRoot()(packages/codev/src/agent-farm/commands/send.ts) derived identity only fromprocess.cwd()matching/.builders/<id>. Builder terminals carried no identity in their env, so from the main root the sender fell through toarchitectSenderId()(barearchitect). Every identity consumer (send,reset,interrupt,self-refresh,whoami) shares those two functions.Fix
.builder-start.sh(both the prompt-mode and worktree-mode script builders) exportsCODEV_BUILDER_WORKTREE=<worktree>.--resumeregenerates the script, so existing builders gain it on resume.identityPath()insend.tsprefers that env var (when it names a.builders/<id>path) over the cwd. The value is still only a path:detectCurrentBuilderIdverifies it against global.db exactly as before, and an unregistered worktree still throws (afx send: detectCurrentBuilderId silently falls back to bare worktree name on state.db read failure → builder messages misroute to main #1094), never launders into a non-builder.sanitizeAgentEnvstrips the var, so a Tower started from a builder shell cannot leak that builder's identity into other terminals.vitest-setup.tsclears it so suites run inside a builder session stay hermetic.afxonly from the main workspace root" rule stands as written. Mostafxcommands resolve a builder worktree as its own workspace, so the rule is right; this fix is what lets a builder follow it, becauseafx sendfrom the main root now reaches its spawning architect.Test Plan
bugfix-1783-builder-identity-env.test.ts: fails 3/6 without the fix (workspace-root resolution, env-over-cwd precedence, unregistered-env throws), 6/6 with itspawn-worktree.test.ts(fresh, resume, worktree mode export the var, with quoting)tsc --noEmitclean