test(acp): keep the delayed fake agent alive until its exit delay is up

Merged
KA
3d ago
+42-7

The acp test "retries the session directory removal after the agent exits when the first try fails" has failed 12 Linux CI jobs since #1626 (Node 22, 22.22.3, and 24): kill ESRCH at tests/executor.test.ts:522, because the fake agent, which should take 1.5 s to stop after SIGTERM, was gone within 500 ms. It blocks unrelated PRs such as #1647.

  • Teardown (packages/acp/src/session.ts) closes the agent's stdin and stdout pipe right before the SIGTERM. A process whose only other hold is a signal listener can exit on stdin's EOF before the signal handler runs, and a late write can hit EPIPE.
  • The fixture's delayed agent (ACP_EXIT_DELAY_MS) now holds the event loop until its delay is up. Once it is stopping, it logs a stdout error, an uncaught error, or a rejection instead of dying on it; before that, an error still ends it at once with code 1, so a real failure fails the test fast.
  • The delay starts at SIGTERM or stdin's end, whichever comes first, so an agent whose test worker died without a teardown still exits.
  • Both tests that use the delay print the agent's last log lines when it is gone early, so a future failure says why.
  • Test code only; no changeset.

Verified

Ran it locally: yes

  • The failure never reproduced: 6 runs on macOS and 37 in Linux containers (node:22.22.3, node:24, non-root, 1 and 2 CPUs), so the CI logs above are the evidence for the race.
  • With the change: pnpm --filter @e2e-dev/acp executor tests pass on macOS, and the full acp suite passed 15 times in a node:22.22.3 container as a non-root user (the test skips as root).
  • CI on this PR: the test jobs on all five Node versions passed, 22.22.3 included, where this test failed most. One check run hit an unrelated web-engine timeout (locator-frame.e2e.ts) and passed on rerun.
  • A fresh-context review found the orphan case (a held agent whose worker died would never exit); fixed by also starting the delay at stdin's end.

Tracked in ENG-1185.