Repository navigation
Description
What happens
packages/codev/src/agent-farm/__tests__/spec-1134-whoami.test.ts fails 16 of 21 tests when the process running vitest has CODEV_WORKTREE_ROOT set. With it unset, the same tree passes 21/21.
Verified on builder/spir-146 at 6c708e17e, tree clean:
# fails
npx vitest run src/agent-farm/__tests__/spec-1134-whoami.test.ts
Tests 16 failed | 5 passed (21)
# passes, same commit, same cwd
env -u CODEV_WORKTREE_ROOT -u CODEV_BUILDER_ID -u CODEV_ARCHITECT_NAME \
npx vitest run src/agent-farm/__tests__/spec-1134-whoami.test.ts
Tests 21 passed (21)
Full suite in the leaked environment: 40 failed / 6586 passed, 3 files.
Why
detectCurrentBuilderId (agent-farm/commands/send.ts:195) reads CODEV_WORKTREE_ROOT in preference to process.cwd():
const identityPath = rawSessionWorktree?.replace(/\/+$/, '') ?? process.cwd();The test fixture controls identity with process.chdir() (documented at the top of the file: "control cwd with process.chdir()"). The env var overrides the chdir, so the test that asserts no identity resolves instead resolves a builder from the real worktree name and gets a BuilderIdResolutionError against the fixture's temp global.db:
expected 'Cannot resolve builder identity for worktree 'spir-146': global.db not found at
/var/folders/.../spec-1134-.../global.db (has Tower ever run?)...'
to contain 'Cannot determine agent identity'
The env var wins over cwd by design (#47, "preserve builder identity after cd"). The defect is that the test never neutralizes it.
Why it matters beyond the test
A builder running its own protocol checks hits this. porch done 146 on this branch went from ✓ tests (201.5s) to ✗ tests (173.6s) with 40 unrelated failures with no code change in between — only the session acquiring CODEV_WORKTREE_ROOT, CODEV_BUILDER_ID and CODEV_ARCHITECT_NAME. The failures point at whoami, so the reader's first hypothesis is a regression in identity resolution, which costs a full-suite bisect to disprove.
Because porch inherits the builder shell's environment, this can block a phase on a green tree.
Suggested fix
Delete the three variables in the test's beforeEach and restore them in afterEach, the way the file already saves and restores CODEV_ARCHITECT_NAME and origCwd:
delete process.env.CODEV_WORKTREE_ROOT;
delete process.env.CODEV_BUILDER_ID;Worth checking the other two failing files for the same coupling, and worth considering whether vitest-global-setup.ts should scrub the whole CODEV_* namespace once, so no future test inherits a builder session's identity.
Activity
pseudoseed commentedon Aug 29, 2026
All three files identified, and the counts account for the full 40.
CODEV_WORKTREE_ROOTsetagent-farm/__tests__/send.test.tsagent-farm/__tests__/spec-1134-whoami.test.tsagent-farm/__tests__/bugfix-774-detect-builder-id.test.tsReproduced by running those files plus 11 other identity-coupled candidates in the leaked environment:
Tests 24 failed | 333 passed (357)for the subset excluding whoami, and 16 for whoami separately.All three drive
detectCurrentBuilderIdand all three set up identity withprocess.chdir(), so all three are defeated the same way.bugfix-774-detect-builder-id.test.tsis the file whose fixture pattern the other two say they mirror, so fixing it there and copying is the natural order.This strengthens the case for scrubbing
CODEV_*once invitest-global-setup.tsrather than patching threebeforeEachblocks: the coupling is to the variable, not to any one test's setup, and the next test to calldetectCurrentBuilderIdinherits the same trap.pseudoseed commentedon Aug 29, 2026
On it! Working on a fix now.
Fix #189: scrub builder-session CODEV_* vars from the vitest harness
[Spec 146][Phase: phase_9] docs: record the #189 diagnosis, now three…
[Bugfix #189] docs: record CMAP verdicts on PR #192
[Bugfix #189] Fix: Extend suite lock wait timeout
Merge pull request #192 from pseudoseed/builder/bugfix-189
Fix #196: remove two dead exports and record the suite attribution
pseudoseed commentedon Aug 29, 2026
Confirmed in the environment this fix was written for, which nothing before today had done.
I closed this issue when PR #192 merged, on the strength of its own tests. That was the fix proving
itself with the suite it changed — a closed loop. The evidence that actually matters is a builder
session with the variables genuinely set by Tower, running the full suite with no
env -u.Two independent trees, both green:
bugfix-196origin/mainmerged, noenv -uspir-146env -uThe
spir-146run verified its own precondition rather than assuming it — all three variableswere confirmed present in that shell before the run. A green suite proves nothing here if the
variables were never set, and that check is what makes this evidence rather than a coincidence.
What this retires
Every green result on
builder/spir-146today carried a caveat: green with three variablesmanually stripped. Without them it failed exactly as
air-180did. That caveat led every reportfrom that builder since this morning and is now false — the PR body was rewritten rather than left
carrying a warning that no longer applies.
Cost this had before the fix
air-180's PR [Air #180] Pin the live t3 server runtime #191 could not pass its porch checks at all, and the failures pointed atwhoami,so they read as an identity regression.
porch done 146went from a 201.5s pass to a 173.6s failure with 40 unrelated failures and nocode change in between — only the session acquiring the variables.
bugfix-196chased this afternoon were this, in a worktree spawned from abase that predated the fix.
Closing this on a merge was right. This is the evidence that says so.