fix: Ctrl-C, --max-failures, and e2e mcp client lifecycle
Fixes from the Oct 1 bug bash: Ctrl-C, --max-failures, and the e2e mcp server's handling of a client that goes away, plus two smaller MCP bugs.
- Ctrl-C with a web test running now reports the test
interruptedand keeps its attempt. Before, the worker exited 130 withWORKER_EXITand the test was reportedskippedwith 0 attempts. Playwright's own SIGINT and SIGTERM handlers are off (packages/web/src/browser-connection.ts), so the runner's interrupt is the one that ends the test. Its SIGHUP handler stays: the runner does not handle a hangup, and that handler closes the browser when the terminal goes away. - A Ctrl-C that hits workers still loading is no longer counted as a boot failure (
WORKER_INIT_FAILED). A worker that dies of SIGINT, SIGTERM, or SIGHUP before it's ready is treated as interrupted when it was alive as that first signal landed (one Ctrl-C reaches every worker at once); a replacement that dies of a signal still counts as a boot failure, so a target that keeps killing its own workers fails withWORKER_INIT_FAILED(run/scheduler.ts,excusedSignal). The exit signal now reaches the scheduler throughUnitRunnerEvents.onExit. --max-failuresstops a running file right away. Eachrun-unitmessage carriesfailureLimit(worker/protocol.ts), and the worker counts its own failures against it, aborting as soon as the limit is reached (worker/session.ts,countFailure). The next test in the file is skipped withfailure-limitinstead of starting before the runner's interrupt arrives.- When the MCP client goes away, the server closes every session, stops the app commands, and exits 0. It watches stdin
end/errorand stdouterror(mcp/server.ts). An EPIPE onprocess.stdoutnow reaches the server instead of crashing it, and an EPIPE on stderr (a client that captured it) is ignored so the shutdown messages cannot kill the server first (cli/mcp.ts). - MCP
open_sessionon a second config fails withCONFIG_IN_USEbefore that config is evaluated. The config is found and claimed first (mcp/sessions.tsclaimConfig/claimEngine,mcp/config.tslocateProjectConfig). Before, the second config evaluatedsecrets.get()against the first session's secrets and failed with a misleadingsecret "..." is not configured. - A failed action no longer reads as done. Its result starts with the tool, its target, and the error code, e.g.
navigate file:///etc/passwd failed: POLICY_DENIED: forbidden URL scheme: file:. Before, the result started with the success text:Navigated to file:///etc/passwd. failed: .... This text is what the testing agent's model reads and what MCP returns. MCP marks these resultsisError: trueand still returns the screen the action observed afterward (agent/primitives.tsfailureLead,mcp/tools.tsactionResult).
flowchart LR
C[client ends stdin / dies] --> S[serveMcp: stdin end, stdout EPIPE]
S --> A[closeAll 'client disconnected']
A --> T[teardown: attempt, engine, app commands]
T --> X[exit 0]
Review these decisions
- The agent's check for a streak of failed actions (
isFailedResult,agent/loop-guards.ts) now takes the tool name. A first line that starts with a lowercase word and containsfailed:counts as a failure only for built-in grammar tools. A project tool's own text such asbuild failed: 2 redis not a failure; a project tool fails only by throwing (Tool "x" failed: ...). MCP'sisErroris also limited to grammar tools. - Point-verb failures keep their old start (
tap_at (x, y) failed: ...), apart from adding the error code for e2e errors. Only the verbs that target a node, a URL, or a key changed. --max-failuresis now enforced in two places. The worker stops its own file using the run's count at the moment the file was dispatched plus its own failures since then. The scheduler still stops the rest of the run. A failure on another worker between dispatch and the local limit is only counted by the scheduler, so it cannot make a worker stop early.- The mobile engine has no equivalent Ctrl-C bug and is unchanged. agent-device installs no signal handlers in the worker, and its daemon and device tooling are spawned
detached.
Verified
Ran it locally: yes. Built CLI on scratch projects (web engine, app on ports 4311-4312), a real MCP stdio client, and mcp-two-configs.mjs on the testbed configs. main was a worktree at the merge base.
| Case | main | this branch |
|---|---|---|
Ctrl-C to the process group mid-test (long poll) | rc 130, errors ['WORKER_EXIT'], long poll skipped attempts 0 | rc 130, errors [], long poll interrupted attempts 1, afterEach done |
| Ctrl-C reaches workers still loading | errors ['WORKER_INIT_FAILED'], b skipped: worker process failed to start | errors [], a and b skipped: run interrupted before execution |
--max-failures 1 --workers 1, two tests in one file | × would run next (interrupted), 2 failed | ↓ would run next [run stopped after 1 failure (--max-failures 1)], 1 failed | 1 skipped |
| MCP client closes stdin, session open | still running after 20 s, app listening | exit 0 after 1 s, app stopped |
| MCP client closes stdin, no session | exit 13, Warning: Detected unsettled top-level await | exit 0 |
| MCP client killed mid-call | exit 1, Error: write EPIPE, Unhandled 'error' event, app orphaned | exit 0, Session ... closed (client disconnected), app stopped |
| second session on another config | CONFIG_LOAD_FAILED: ... secret "BASIC_PW" is not configured | CONFIG_IN_USE: session ... is open on config .../e2e.bugbash-mcp.config.ts |
call navigate {url: 'file:///etc/passwd'} | Navigated to file:///etc/passwd. failed: forbidden URL scheme: file:, isError false | navigate file:///etc/passwd failed: POLICY_DENIED: forbidden URL scheme: file:, isError true |
call tap {target: 'zzz'} | Tapped #zzz. failed: node #zzz is not on the current screen ... | tap #zzz failed: LOCATOR_NOT_FOUND: node #zzz is not on the current screen ..., isError true |
After every run, ps and lsof showed no leftover app, browser, or worker processes.
New tests, each failing on main: interrupt-signals.test.ts (browser open in the worker), scheduler.test.ts (workers killed by Ctrl-C while loading), parallel-workers.test.ts (--max-failures in the running file), mcp-session-host.test.ts (config claimed before it evaluates), mcp-disconnect.test.ts (three disconnect cases), and mcp-server.test.ts, loop-guards.test.ts, agent-act-verbs.test.ts (failure text and isError).
The failure text is part of what the model reads, so I replayed the web benchmark's agent suite from its committed recordings: CI=1 e2e run --config e2e.agent.config.ts --strict-cache passed 32/32 with no REPLAY_STALE and no cache changes. The benchmark's deterministic suite passed 90/90 and the testbed 70/70.