Implementation plan · September 22, 2026 · sageox-attest-e3s
Let independent scenarios use the available session slots.
Dispatch scenario instances concurrently, in input order, and let the existing session pool admit complete persona gangs. Keep the current default of four session slots. Add explicit failure draining so concurrency cannot leave work running after the journal closes.
Status: analysis complete; implementation has not started. This restores behavior lost in the initial extraction. The admission algorithm and event/report formats already support it.
One scenario can leave most of the pool idle
Example: A needs one session, B needs two, C needs one, and D needs one. With four slots, A, B and C can run together; D waits for a slot.
Keep one capacity authority
The pool already limits session usage, admits persona gangs atomically, and preserves FIFO fairness. A second runner semaphore would duplicate that policy.
The old monorepo limiter avoided long HTTP admission waits. Attest now calls an embedded orchestrator; queued scenarios open no provider connection until admitted.
Keep one evidence stream
Start events are emitted in input order. Subsequent events carry scenario identity, so operations can interleave without mixing steps or evidence.
Report order remains input order. Replaying the same journal remains exact; separate concurrent runs need not have identical event interleaving.
Biggest implementation risk: cancellation races
A plain Promise.all replacement can reject while sibling scenarios are still provisioning or writing evidence. It also exposes a queue race: cancelling a blocked gang can briefly admit the next scenario before its abort listener fires.
The fix must cancel queued work immediately, recheck cancellation after admission and before provisioning, and drain every started task before an unexpected exception returns. Keep the existing real-process interrupt sweep and exit behavior.
Delivery sequence
| Step | Concrete outcome |
|---|---|
| 1. Prove overlap and safe admission | Add deterministic session gates and a failing test showing two scenarios must enter execution before either completes. Add the cancellation race at the orchestrator boundary. |
| 2. Restore concurrent dispatch | Launch groups in input order. Reuse pool capacity and gang scheduling, including FIFO and immediate refusal of oversized gangs. |
| 3. Make failure completion explicit | Record the first unexpected error, trigger shared cleanup once, settle every scenario and persona bootstrap, then rethrow before final reporting. Budget listeners for the run-owned abort signal. |
| 4. Verify evidence and failure behavior | Prove ordered reports, interleaved journal replay, isolation, queue refill, held teardown slots, and complete cancellation. Update two tests that assume serial event order. |
| 5. Validate and document | Run focused tests and all repository quality gates. Document parallel-by-default scenarios, session-slot units, and the current absence of a CLI serial override. |
Scope and rollout
The recommended regression fix changes the runner, adds one orchestrator admission guard, and extends tests and execution documentation. It requires no new event/report version, pool algorithm, provider interface, app configuration, or CLI option. Warm-up remains a prerequisite that completes before the visible run.
Parallel scenarios must isolate external mutable state. The CLI currently has no serial fallback; track that separately as sageox-attest-334. A pool cap of one serializes singleton scenarios but cannot fit a multi-persona gang. It must not be described as a universal serial mode.
The existing 60-minute capacity-wait timer starts when each request is queued. Large runs will now exercise this policy; retain its value and document it rather than silently changing the timeout.
<!-- ox:details -->Implementation notes
Verified baseline and design constraints
- Current source:
f7718f1. The serial loop issrc/runtime/runner/runner.ts:595; the first extracted runner (217d739, July 24) already had it. - Old monorepo
tests/bdd/compiler/src/exec.ts:841–912explains its HTTP limiter and launches concurrent dispatches. This is a restoration of scenario overlap, not a port of obsolete transport machinery. - ADR-003 requires gang atomicity and caller-asserted outcomes. ADR-004 keeps lifecycle in the orchestrator/provider. ADR-007 requires report = terminal fold of the single event stream; never sort or patch an independent report accumulator.
- First-principles conclusion: the old client window solved a remote-transport limit. Once admission is local, the existing pool supplies the required backpressure without that extra window.
Production edits
src/runtime/runner/runner.ts: replace the serial loop with eagerly created scenario promises, called in the iteration order ofgroups. Preserve the synchronous pre-awaitscenario-startedemit. Await settlement of all tasks before finalize/run-finished/report publication.- Add a run-scoped first-error recorder and memoized cleanup trigger. A scenario's unexpected rejection starts cancellation immediately; a normal failed assertion, timeout envelope, or
{ok:false}bootstrap result remains a reportable scenario result and does not cancel unrelated scenarios. After every task settles, await cleanup if started and rethrow the original first error. Keep signal listeners and the journal alive through that drain. Keep cancellation scoped to this run; never call the shared pool's global drain method. - Pass the failure recorder to the scenario context. Persona bootstrap needs the same discipline: attach a catch to each request, trigger cancellation immediately on unexpected rejection, and use
allSettledto drain the other requests before throwing. The outer drain alone cannot see requests detached by an inner fail-fastPromise.all. - Use
node:events.setMaxListenerson this run's owned abort signal, with a budget derived from the total distinct-persona requests across groups. Fan-out can put more than ten requests on one signal in supported Node 22. Do not change process-wide listener defaults; verify listeners are removed on admission/cancellation. src/runtime/orchestrator/orchestrator.ts: after successfulpool.admitand the existing deleted-record check, recheckopts.signal.abortedand the run's running status before callingprovider.provision. Fail the still-pending record using existing failure conventions and release its acquired slot exactly once. Keep the post-provision guard for cancellation that happens during provisioning.- Retain existing real SIGINT/SIGTERM behavior: abort queued admissions, mark the run closed before deleting live sessions, and preserve Shuru's synchronous VM/staging sweep and process exit. Do not make a real interrupt wait indefinitely for every scenario task. The drain-before-return rule applies to unexpected exceptions and normal library completion; an interrupted process may leave a partial journal.
- Update the runner's one-at-a-time documentation and add a short execution/concurrency explanation in
docs/guides/getting-started.md. No new scheduling input enters freshness hashing.
Test placement and acceptance
Use the real runner and orchestrator with the existing shared fake. Extend tests/runtime/orchestrator/fake-provider.ts with optional session-keyed provision/teardown gates (tracked as sageox-attest-5ev). Reuse deferred and per-client invocation/preparation hooks. Avoid sleeps, global call counters, and order-dependent failNext* injection.
| Home | Required observable behavior |
|---|---|
tests/runtime/runner/runner.test.ts | Cap two: A and B overlap, C queues; completing B admits C while A remains held. Cap one: singleton scenarios serialize. Mixed gang sizes preserve atomicity and strict FIFO; oversized gangs fail promptly. Collection and teardown retain slots until completion. |
tests/runtime/orchestrator/orchestrator.test.ts | Cap two, active A singleton, queued B gang of two, then C singleton: abort while B blocks the spare slot. C must never reach provision even if cancellation repumps the queue and momentarily admits it. All acquired slots return exactly once. This admission race was reproduced against the actual SessionPool during analysis: abort rejected both B members but returned success for C. |
| Runner failure tests | Independent scenarios survive an ordinary assertion/provision failure. Unexpected failure with a live scenario, in-flight bootstrap and queued scenario cancels admission immediately and waits for gated work to settle before returning; no terminal report, unhandled rejection, or post-close journal write. Cover a rejecting persona request while its sibling is still bootstrapping. |
| Runner cancellation tests | Multiple live, provisioning and queued scenarios; repeated cleanup is safe. More than ten queued requests add no listener warning and leave no queued entries/listeners after cancellation. Use an injected signal handler; preserve existing adapter interrupt tests. Run two runs through one orchestrator and prove cancelling one does not cancel the other. |
tests/events/event-log.test.ts | Finish B before A but retain A/B report order. Strict-parse the written report and each event; replay equals returned report. Update the partial-journal assumption near line 179 and abnormal-exit assumption near line 470 using explicit gates. Same journal must replay identically; normalize volatile IDs/timing only for cross-run comparisons. |
| Evidence and live dashboard suites | Identical persona/export/artifact names in different scenarios retain distinct values and bytes. Extend tests/runtime/runner/evidence-sink.test.ts and tests/dashboard/live-view-identity.test.ts so overlapping scenarios route sessions, operations and evidence correctly. |
Seed the old serial loop to prove the overlap test fails. Remove the post-admission guard to prove the cancellation-race test fails. Restore fail-fast waiting to prove the abnormal-exit test detects detached work. These are implementation-time mutation checks, not tests executed during this planning pass.
pnpm exec vitest run tests/runtime/runner tests/runtime/orchestrator tests/events tests/dashboard/live-view-identity.test.ts
pnpm typecheck && pnpm lint && pnpm test
The full test command runs the build through pretest. No packaging or ADR change is planned. No commit, push, or publishing is authorized by this analysis request.
Prior art
Playwright's parallelism guide separates scheduling limits and test isolation; Cucumber-JS parallel execution documents coordinating parallel scenarios. These confirm conventional behavior. Attest's existing session-weighted gang pool is the appropriate mechanism here; neither framework's worker topology needs to be imported.
Work tracking: main implementation sageox-attest-e3s; shared test gates sageox-attest-5ev; deferred serial control sageox-attest-334. All implementation remains outstanding.
<!-- /ox:details -->
