Repository navigation
Description
Summary
When a builder lane is torn down, processes that lane spawned which are not shellpers survive afx cleanup, the worktree removal and the branch deletion. They are reparented to launchd and keep a cwd pointing at a directory that no longer exists. Nothing in the system ever reaps them, and no health signal reports them.
Observed
During the teardown of the pir-1802 lane (PR #1812, merged):
afx cleanup -p 1802ran and reportedKilled 1 shellper process(es), then preserved the worktree over uncommitted files.git worktree remove --force+git branch -D+git push origin --deletecompleted.- Two processes were still running afterwards:
PID 50508, PID 57753
.../.builders/pir-1802/node_modules/.pnpm/[email protected]/.../spawn-helper
ppid = 1 (parent already dead, reparented to launchd)
cwd = /Users/.../.builders/pir-1802/packages/codev (path no longer exists)
started during that lane's own build/test activity
They terminated with a plain SIGTERM once found.
Why nothing collects them
- Orphaned shellper and consult processes accumulate over time #341's sweep (
killOrphanedShellpers) cannot:findShellperProcesseskeeps onlypslines that containshellper-main.jsand the configured socket dir. A node-ptyspawn-helpermatches neither, so it is outside the sweep's definition of an orphan, not merely missed by it. - Never activate Codev inside a builder worktree; hide the Agents view there #1809's builder-worktree prune cannot: it deletes
known_workspaces/architect/terminal_sessionsrows and deliberately signals no process. afx cleanupdid not: it killed the Tower terminal and one shellper; these two were neither.- No signal reported them:
afx statusshowedUnregistered Shellpers: 0before, during and after. A maintainer doing a routine cleanup has nothing to look at.
Distinct from the adjacent issues: #341 and #1038 are about shellpers, #1688 is about that sweep's ps output handling, #1752 is about porch's own child chain holding stdio pipes, #1176 and #1803 are about registry rows.
The design decision this needs
Where the reaping belongs:
Option A, at cleanup time (recommended). afx cleanup knows exactly which worktree path is being removed, so "a descendant process whose cwd is under this path" is unambiguous at that moment, and it can terminate the process group rather than infer anything. Narrow blast radius, and it fixes the case a human actually triggers.
Option B, a boot-time sweep. Catches accumulated history too, but it needs a rule that can never match a live lane. A boot sweep that kills by cwd is the sort of thing that eventually reaps something live, so it would need the same liveness-first discipline #1809's prune uses.
The reliable orphan test used by hand here was ppid == 1 and a cwd under a path that no longer exists. Notably it must not key off the Unregistered Shellpers count, which read 0 throughout.
Severity
Hygiene, not correctness: each leak is a few idle processes holding an unlinked directory. It is worth fixing because it leaks once per teardown, scales with lane throughput, and is invisible to every existing health signal.
Activity
amrmelsayed commentedon Oct 16, 2026
Strengthening the "invisible to every existing health signal" point with the mechanism, since it turns out to be structural rather than incidental.
computeFleetHealthFields(#1227,tower-routes.ts) buildsfleetRssKbfrom exactly two sets:ppidis one of those shellper pids.A leaked
spawn-helperof the kind described above is in neither set: it is not a shellper, and once its parent dies it is reparented to launchd, soppid == 1. The same two-set scoping drivesunregisteredShellperCount, which counts only in-scope shellpers.So both fleet signals are structurally incapable of showing these processes: the moment one becomes an orphan is the moment it leaves the accounting. Any fix should therefore not try to surface them through the existing counters; it needs its own test (
ppid == 1plus a cwd under a removed worktree), which is the argument for Option A doing the work at cleanup time, where the path is known.amrmelsayed commentedon Oct 21, 2026
Data point from the #1809 lane cleanup (2026-10-21), a second shape of the leak this issue tracks.
A stray architect session had been created in
.builders/pir-1809by opening the worktree folder during dev-gate testing (the #1809 fix is not live until Tower restarts). It was Tower-registered under the worktree as its own workspace, soafx statusfrom the real workspace root never listed it.What ending it took:
afx workspace stoprun from the worktree: Tower deregistered the terminal and killed the agent process. Reported "Stopped 1 process(es)".claude --resume <same session id>) with its cwd back in the worktree. No Tower row was recreated, so this was now an invisible agent, not just an invisible shellper.SIGTERMto the shellper, after confirming ppid 1 and noterminal_sessionsrow, ended it for good.afx cleanup -p 1809 -fthen killed the builder's own shellper correctly and left nothing rooted in the worktree.So the "process a lane leaves" can be a shellper whose relaunch loop keeps a live agent running after Tower has stopped it. A reap-at-cleanup sweep (Option A) should target the shellper, not only its current child, and should treat "no Tower row + cwd under the path being removed" as the orphan test. A
known_workspacesrow for the removed worktree path also remains until the #1809 startup prune runs.