Repository navigation
Closed
Labels
area/towerArea: Tower server / agent farm CLI
Description
Impact (observed in production, 2026-08-17/18)
Running the codev test suite while a cloud-connected Tower is up disconnects the user's real cloud tunnel and deregisters their Tower, silently, until a human manually reconnects. Last night's sequence, from ~/.agent-farm/tower.log:
23:49:43Z— during a builder's full-suite run:Tunnel connect requested (via=local ua="node")×3 + oneTunnel disconnect requested, thenServer-side deregister succeeded for tower 01KZ…, then the production Tower logsCloud config removed or invalid, disconnecting tunnel.- Tunnel stays down 6.5 hours until the owner manually reconnects at
06:14Z. Downstream consumers of the cloud connection (e.g. the Stream Deck integration) broke for the whole window. - Further identical bursts at
03:02–03:13Zduring another builder's suite runs (config already gone by then, so no further state transitions).
This is a recurrence of the "disconnect saga" (#1370/#1372 era) — and the via= attribution logging shipped for it in 3.3.0 is what finally named the actor: our own test suite.
Root cause
packages/codev/src/agent-farm/__tests__/helpers/tower-test-utils.ts spawns a real tower-server child with:
env: { ...process.env, NODE_ENV: 'test', AF_TEST_DB: `test-${actualPort}.db`, SHELLPER_SOCKET_DIR: socketDir, ... }The DB and shellper sockets are isolated; ~/.agent-farm is not. The spawned Tower therefore:
- Reads the production cloud config — real tower ID and token. A test exercising
/api/tunnel/connect/disconnectacts as the user's registered Tower: disconnect performs a server-side deregister of the production tower ID and deletes the production cloud config file. - The real Tower's config watcher notices the deletion and drops its live tunnel.
- Writes to the shared
~/.agent-farm/tower.log, interleaving test-tower lines with production lines — which is why the earlier forensics (this saga's "unidentified actor") never converged: the evidence was two processes writing one file.
Prescribed fix (BUGFIX-shaped)
- Isolate the agent-farm dir per spawned test Tower — point the child at a
mkdtemp'd dir (whatever mechanism tower-server honors:AGENT_FARM_DIRenv or equivalent; add the override if none exists). No test Tower may ever see the real cloud config, key, log, or global.db. - Defense in depth: under
NODE_ENV=test, tower-server refuses cloud side effects (server-side deregister, cloud-config deletion) unless explicitly opted in by a test that owns a fake config. A leaky test should fail loudly, not deregister a human. - Regression test: spawn a test Tower with a canary cloud config in the fake dir + a canary in a real-shaped path; drive connect/disconnect; assert the real-shaped canary is untouched and the log landed in the isolated dir.
- Sweep other spawn sites (e2e helpers, vitest-e2e setup) for the same
...process.envinheritance.
Evidence pointers
~/.agent-farm/tower.loglines around2026-08-17T23:49:43Zand2026-08-18T03:02–03:13Z.- Suite-run timing correlates with builder-air-1489 (spawned 23:42Z, suite before its 00:04Z report) and builder-spir-1470's Phase 2 iterations.
Metadata
Metadata
Assignees
Labels
area/towerArea: Tower server / agent farm CLI
Activity
waleedkadous commentedon Aug 18, 2026
On it! Working on a fix now.
waleedkadous commentedon Aug 18, 2026
Root-cause correction from the bugfix investigation (verified by A/B repro, not statically):
The actor is
packages/codev/src/agent-farm/__tests__/tower-cloud-cli.test.ts— a unit test in the default suite, not an e2e helper.towerRegister()/towerDeregister()invoked with no port option resolvegetTowerClient()tolocalhost:4100— the live production Tower — authenticated with the real~/.agent-farm/local-key. Its 3-connects-then-1-disconnect shape matches the incident log exactly (guard off → 4 tunnel lines in the production log; guard on → 0).Two corrections to this issue's original root-cause section:
tower.log(no--log-file), so the "two processes sharing the log" theory was wrong.NODE_ENV=testguard) would not have prevented this — the victim Tower is the production one, running without any test env. The effective fix is the client-side guard the builder added, plus the test-env isolation from fix The Gestalt Problem - Features Developed in Isolation Without System Awareness #1.Fix #1515: stop test runs from deregistering the developer's real Tower
[Bugfix #1515] Add review document
[Bugfix #1515] Address CMAP review
[Bugfix #1515] Remove review artifact per BUGFIX protocol
[Bugfix #1515] Address CMAP round 2
[Bugfix #1515] Route startTower cleanup through the helper
Merge pull request #1516 from cluesmith/builder/bugfix-1515
waleedkadous commentedon Aug 18, 2026
Completion stats — bugfix-1515
Fixed in #1516 (merged
2026-08-18T15:33:39Z, merge commitf73f1f5). Protocol phase:verified.Timings
Change size
Production change is well inside the BUGFIX ceiling:
constants.ts,test-env.ts,tower-client.ts,tower-tunnel.ts.Consultation
7 invocations, 15.9 min, $6.83, 100% success — 3 CMAP rounds.
Both
REQUEST_CHANGESwere correct and both were mine to own:tower-routes-husks.e2e.test.tsandshellper-husk-sweep.e2e.test.ts, which read the DB at the old~/.agent-farmpath. It also caught that my "all tests pass" covered 5 Tower-spawning e2e files when 12 use the helper I changed — 2 of the 7 I skipped were the broken ones.codev/reviews/bugfix-1515-*.md. The BUGFIX protocol says "no artifact files: the issue is the specification and the PR body carries the reasoning." Removed.Verification
tower.logBoth layers hold independently. The e2e regression was confirmed to fail without the fix with the production symptom (
expected 'canary-real-tower-id' to be 'isolated-test-tower-id').Final: unit suite green (4929 tests); all 14 Tower-spawning e2e files green (85 tests); zero leftover credential dirs.
Correction to this issue's root-cause section
Recorded because the stated mechanism would have left the bug live:
~/.agent-farm/tower.log, interleaving test-tower lines with production lines" — false.tower-server.tswrites a log only when--log-fileis passed, which no test spawner does. The lines interleave with production mailbox/cron lines in a single process.test-141*.dbwere sitting in~/.agent-farm), but not the actor. The actor wastower-cloud-cli.test.ts, a unit test in the default suite, whosetowerRegister()/towerDeregister()calls pass noportand so command the live Tower on 4100 with the real local key.Consequently prescribed fix #2 (server-side
NODE_ENV=testguard) would not have prevented this — the Tower being commanded runs with neitherVITESTnorNODE_ENV=test. The client-side guard was the missing piece.Collateral
Two further tunnel drops at
06:29:36Zand06:31:15Zwere caused by my own pre-fix targeted runs (tower01M09R4DAMRMYHZ523475WVKVRderegistered). That is what named the actor:06:29:36Zis the exact start timestamp of thetower-cloud-cli.test.tsrun. Owner reconnect was required.Follow-up filed as #1517 (the guard is on the CLI
TowerClientsubclass, soapps/vscode'ssignalTunnelpath is unguarded).Full narrative:
codev/state/bugfix-1515_thread.md.Merge pull request #1525 from cluesmith/records/bugfix-1515
[Bugfix #1629] Fix: refuse a second Tower against a live global.db (o…
Fix #1691: drop internal issue numbers from the user-visible refusal …