Skip to content

fix(test): reap the CLI e2e children when a test times out - #80

Merged
kemalelmizan merged 1 commit into
mainfrom
fix/e2e-reap-children
Oct 17, 2026
Merged

kemalelmizan merged 1 commit into
mainfrom
fix/e2e-reap-children

Conversation

@kemalelmizan

Copy link
Copy Markdown
Contributor

Problem

src/cli.e2e.test.ts spawned the CLI with plain spawn and never reaped it. A REPL child blocks on stdin and the MCP server it starts is a grandchild, so a test that timed out (or a vitest worker torn down mid-run) left the whole chain reparented to systemd --user and hanging.

Seven such chains sat for 7h45m on this machine before anyone noticed, still holding their /tmp/agent-e2e-* directories open.

Fix

  • spawnCli spawns detached: true, so the child leads its own process group.
  • killTree kills the group (process.kill(-pid)), which takes the MCP server with it — killing the CLI alone would orphan the server.
  • afterEach kills anything still running; process.on("exit") is the belt-and-braces for a worker that never reaches the hook.

Verification

  • Added a REPL test whose marker never arrives: it times out at 5s and leaves no process and no temp directory behind, then removed it.
  • Full suite: 341 passed / 5 skipped, no orphans, no /tmp/agent-e2e-* left.

The e2e harness spawned the CLI with plain `spawn` and never killed it. A REPL
child blocks on stdin and the MCP server it starts is a grandchild, so a test
that timed out — or a vitest worker torn down mid-run — left the whole chain
reparented to systemd and hanging indefinitely. Seven such chains sat for 7h45m
before anyone noticed, still holding their `/tmp/agent-e2e-*` directories.

Spawn into a process group (`detached`) and kill the group in `afterEach`, and
again on worker exit, so a failure cleans up after itself. The group is what
matters: killing the CLI alone would have left its MCP server orphaned.

Verified by adding a REPL test that never answers its marker — it times out at
5s and leaves no process and no temp directory behind — then removing it.
@kemalelmizan
kemalelmizan merged commit b04b7d3 into main Oct 17, 2026
2 checks passed
@kemalelmizan
kemalelmizan deleted the fix/e2e-reap-children branch October 17, 2026 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant