Skip to content

feat: concurrent test execution across worker processes - #4

Merged
okwasniewski merged 3 commits into
mainfrom
oskar/concurrent-workers
Jul 27, 2026
Merged

okwasniewski merged 3 commits into
mainfrom
oskar/concurrent-workers

Conversation

@okwasniewski

Copy link
Copy Markdown
Member

Implements the workers setting: execution now schedules file-target units across child worker processes per spec/11-lifecycle.md. Closes the "accepted but serial" gap documented in the READMEs.

Design

Scheduling (spec 11-lifecycle.md "Execution hierarchy")

  • Unit of scheduling = one file-target realm: all runnable pairs of one file for one target run on one worker, preserving realm reuse between passing non-serial tests and inline serial-group execution.
  • Per target, setup units complete before ordinary units dispatch; the scheduler tracks failed sessions and emits setup-failed skips at dispatch time.
  • Workers are bound to one target and run one unit at a time. A worker is discarded after any unit containing a failed/timed-out result, and on any infrastructure fault.

Worker processes (spec 09-drivers.md driver concurrency contract)

  • Each worker re-loads the config module itself (configs may hold live driver instances/closures that cannot cross IPC) and verifies the resolved configDigest matches the runner's. This also yields exactly one driver instance per worker with strictly serialized sessions.
  • Results/serial groups/run errors stream back over the IPC channel; ResolvedTarget never crosses the wire (results carry targetName, the runner rehydrates).
  • Session state: the per-run AES key transfers once over IPC at worker init (never disk/env/argv); workers share the encrypted on-disk session store, so a setup produced in one worker restores in another.
  • Worker crash mid-unit: the in-flight pair records a synthetic WORKER_CRASH failed attempt, unfinished pairs skip as infrastructure-unavailable, and a WORKER_EXIT run error is recorded (infra failures are not retry eligible). Two consecutive boot failures fail the target's remaining units.
  • Interrupts broadcast over IPC (workers ignore direct SIGINT), with a timeout + cleanupTimeout force-kill budget.

Fallback: in-memory configs (programmatic rawConfig) cannot cross process boundaries and keep the sequential in-process path.

Reporting: serial groups are now sorted file → declarationIndex → target index like results, keeping report order independent of completion time (spec 13-reporting.md).

Changes

  • src/run/units.ts — work-unit planner (setup units, file units, immediate non-run pairs)
  • src/run/worker/{protocol,entry,handle}.ts — IPC protocol, worker process entry, runner-side process lifecycle
  • src/run/scheduler.ts — dispatch loop, setup gating, worker pool with target affinity, discard/crash handling
  • src/run/execute.ts — TargetExecutor.run split into reusable runSetupUnit/runFileUnit; new onSerialGroup/onPairStart events
  • src/run/runner.ts — parallel path for file-backed configs (all worker counts), fallback otherwise
  • src/run/sessions.ts — injectable session key
  • src/report/build.ts — deterministic serial-group ordering

Testing

  • New unit tests: work-unit planning, non-run/unstarted result shapes, wire round-trip
  • New integration tests (real worker processes + browsers): distinct worker PIDs proven, cross-worker session restore, setup-failure gating across workers, atomic serial groups, worker crash recovery, interrupt → exit 130
  • Full suite: 309 tests / 31 files pass; testbed 30/30 through the worker path, ~2.4x wall-clock vs --workers 1

Note: found a pre-existing ~10s process-exit lag (two lingering socket handles) that reproduces on the sequential path too — left out of scope, worth a separate issue.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 1 additional finding in Devin Review.

Open in Devin Review

Comment thread packages/e2e/src/run/scheduler.ts Resolved
Implements the workers setting (spec 11-lifecycle.md): file-target units
are scheduled across child worker processes. Each worker re-loads the
config module, owns one driver instance, and runs one unit at a time;
per-target setup tests gate ordinary units, serial groups stay atomic on
one worker, and workers are discarded after failing units or
infrastructure faults. In-memory configs keep the sequential in-process
path.
The worker scheduler was only reachable with a file-backed config; an
in-memory rawConfig fell back to a separate sequential loop in the runner.
That duplicated setup gating, non-run record construction, and interrupt
handling, and left the whole test suite exercising the fallback while users
only ever hit the scheduler.

Introduce a UnitRunner transport seam. The scheduler is now the only engine
and spawns either a child process or an in-process worker; both drive the
same TargetWorker core. Dispatch-time gating moves entirely to the scheduler,
so TargetExecutor.run, dependencySkip, failedSetupSessions, and its duplicate
non-run emitters are deleted.

Split TestIdentity out of CollectedTest and point ResultRecord at it. Wire
messages carry identities, which removes the CollectedTest cast in
decodeResult, the synthesized test with a fake fn in the worker, and stops
test functions leaking into records.

Fix scheduler defects:
- take a unit before acquiring a worker, so a spawn is never left idle
- count retired-but-live workers against the cap
- snapshot the worker list before retiring during interrupt broadcast
- derive setup gating instead of tracking a hand-maintained counter
- requeue a worker's queued unit on exit before failing its target, which
  otherwise deadlocked the run loop after repeated boot failures
- drop unused unitId fields; validate the one that remains

Add scheduler unit tests against a fake transport, now possible via the seam.
@okwasniewski
okwasniewski force-pushed the oskar/concurrent-workers branch from 4e93a8d to 816ba7b Compare July 27, 2026 14:34
A worker that dies before becoming ready owns a unit that is already off its
queue. Requeueing it in onExit before the target is failed is what keeps those
pairs in the report; without it the setup case reports nothing at all.

Add regression coverage for the setup-unit case and for an interrupt arriving
while a worker is still starting, and document why retire() drops a queued
unit rather than requeueing it.
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