fix(run): a worker crash during a retry keeps the attempts before it

Merged
OK
2mo ago
+1071-129

When a test with retries: 1 failed its first attempt and its retry crashed the worker, the report showed a single fabricated attempt 0 (WORKER_CRASH), and attempt 0's real error was gone. Serial groups had the same problem. The worker sent a test's result only once all its attempts were done (runOrdinaryPair in packages/e2e/src/run/execute.ts, runSerialUnit in serial.ts), so a crash took every finished attempt with it.

  • The worker streams progress ahead of the result with four typed messages in packages/e2e/src/run/worker/protocol.ts: attempt-start and attempt for ordinary and setup pairs, serial-member and serial-attempt for serial groups.
  • The scheduler keeps them per pair and per group until the result or group arrives (SchedulerWorker.attempts, serialGroups).
  • Crash during an attempt (its re-import and beforeAll included): the kept attempts, then a WORKER_CRASH attempt with the index attempt-start named.
  • Crash between attempts (an afterAll after the last one): recorded on the last attempt as a secondary error with cleanup: 'forced'. No retry attempt is invented.
  • Serial crash: finished group attempts, then a failed one holding the members finished so far, with the running member failed with WORKER_CRASH. A crash after a member finished fails the group attempt without blaming that member. A retry that crashed before any member keeps attempt 0's member verdicts. SerialGroupProgress is in serial.ts.
  • A serial crash after the last group attempt, with no retry to follow, goes on that attempt the same way.
  • Setup tests send each attempt before afterAll and the session saves, with the SESSION_CONTRACT check already applied, so a crash in either goes on that attempt. Its sessions still count as failed for dependents.
  • Interrupt that terminated or killed the worker: the finished attempts stand with the verdict they reach, flaky included. A serial attempt in flight is recorded interrupted and keeps the members it finished. That verdict comes from one pure helper, retryVerdict in retry.ts, which runWithRetries uses too.
  • Worker send now hands each message to the IPC channel right away instead of chaining it on the previous message's ack. Before, a pair-start sent just before a body called process.exit never left the process.

Overlap with #824 (worker hang watchdog, open): its watchdog kill also goes through synthesizeCrashResults. It reports the blocked test timed-out with only the synthesized attempt, so it drops earlier attempts the same way. Whichever PR lands second reconciles them. The watchdog kill should append its TEST_TIMEOUT attempt after the kept ones. Test for it: retries: 1, attempt 0 fails, attempt 1 busy-loops, both attempts reported, the last one TEST_TIMEOUT. Both PRs make the same send change in worker/entry.ts.

sequenceDiagram
  participant W as worker
  participant S as scheduler
  W->>S: pair-start
  W->>S: attempt-start 0
  W->>S: attempt 0 (failed)
  W->>S: attempt-start 1
  W--xS: process exits
  S->>S: result = attempt 0 + WORKER_CRASH attempt 1

A worker that exits on its own during the interrupt grace now counts as a crash, not an interrupted skip.

Verified

Ran it locally: yes

Scratch project in /tmp with a no-op custom engine and --workers 1, using the built CLI from origin/main (f99e80eb) and from this branch.

scenariomainthis branch
retries: 1, attempt 0 throws, attempt 1 process.exit(7)[[0, failed, WORKER_CRASH]][[0, failed, ERROR "first attempt fails"], [1, failed, WORKER_CRASH]]
serial retries: 1, step 2 throws, then exits on retrystep 1 and step 3 skipped, step 2 one WORKER_CRASH attempt, no group recordgroup failed with attempt 0 and attempt 1, step 1 passed, step 2 failed, step 3 skipped
retries: 1, test always throws, afterAll exitsone fabricated WORKER_CRASH attempt, real error lostone attempt with the real error, crash on it as a secondary error
# this branch, serial
   ✓ wizard > step 1 passes 1ms
   × wizard > step 2 fails, then crashes on retry 1ms
     → worker process exited during this test
   ↓ wizard > step 3 never passes [member 1 failed in this group attempt]
group failed
  attempt 0 failed ERROR [["passed"],["failed","ERROR","first attempt fails"],["skipped"]]
  attempt 1 failed WORKER_CRASH [["passed"],["failed","WORKER_CRASH"],["skipped"]]

New tests fail on main:

  • tests/integration/parallel-workers.test.ts: retry crash, crash in a retry beforeAll, afterAll crash after a failed attempt, serial retry crash, serial retry crash before any member, crash in a serial afterAll, setup attempt kept when afterAll crashes (passed and SESSION_CONTRACT).
  • tests/unit/scheduler.test.ts: forced interrupt during a retry (ordinary and serial, failed and flaky), forced interrupt mid group attempt, crash after a group finished, worker exiting on its own during the interrupt grace.
  • tests/unit/retry.test.ts: retryVerdict.