fix(run): a worker crash during a retry keeps the attempts before it
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-startandattemptfor ordinary and setup pairs,serial-memberandserial-attemptfor 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
beforeAllincluded): the kept attempts, then aWORKER_CRASHattempt with the indexattempt-startnamed. - Crash between attempts (an
afterAllafter the last one): recorded on the last attempt as a secondary error withcleanup: '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.SerialGroupProgressis inserial.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
afterAlland the session saves, with theSESSION_CONTRACTcheck 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,
flakyincluded. A serial attempt in flight is recordedinterruptedand keeps the members it finished. That verdict comes from one pure helper,retryVerdictinretry.ts, whichrunWithRetriesuses too. - Worker
sendnow hands each message to the IPC channel right away instead of chaining it on the previous message's ack. Before, apair-startsent just before a body calledprocess.exitnever 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.
| scenario | main | this 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 retry | step 1 and step 3 skipped, step 2 one WORKER_CRASH attempt, no group record | group failed with attempt 0 and attempt 1, step 1 passed, step 2 failed, step 3 skipped |
retries: 1, test always throws, afterAll exits | one fabricated WORKER_CRASH attempt, real error lost | one 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 retrybeforeAll,afterAllcrash after a failed attempt, serial retry crash, serial retry crash before any member, crash in a serialafterAll, setup attempt kept whenafterAllcrashes (passed andSESSION_CONTRACT).tests/unit/scheduler.test.ts: forced interrupt during a retry (ordinary and serial,failedandflaky), 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.