ADR-0020: Execution model in 0.2¶
Architecture: Section 8, Execution and scheduler
Amends ADR-0006, ADR-0007 and ADR-0010.
Context¶
0.2 is the first release that runs plans. The scheduler, the executors and the unit events need one agreed shape before the model runner, the process executor and the console rendering are built on them.
Options¶
- An
executorconfig key. Flexible, but a second knob that can contradictboundary. - The boundary picks the executor. One setting, one meaning.
- Multiprocessing for the process executor. Shares state implicitly and behaves differently per platform.
- A subprocess that runs
pipeloom run --select unit:<id>. Only argv crosses the boundary, so the same path works from an orchestrator.
Decision¶
- The boundary picks the executor.
boundary: processuses a thread pool and one engine session shared by the invocation;boundary: taskstarts a subprocess per unit. There is noexecutorkey and no multiprocessing. - The scheduler is a ready-queue loop with no level barrier. Ready units sit in a heap ordered by
(-downstream, unit_id), so a given completion order always yields the same start order. Parents outside the selection count as satisfied. - It talks to an
Executorprotocol:submit, a blockingwait_any,cancel(unused until 0.3) andshutdown. The thread executor and a simulated executor for tests implement it. - Unit states are checked against one transition table.
queued -> skippedandqueued -> cancelledexist besides the section 8 transitions, because a unit waits in the queue while a failure or a stop arrives.retrying,timed_outandrunning -> cancelledare in the table and unused until 0.3. - A failure skips every pending or queued descendant in topological order with reason
upstream_failedand the failed unit id.--fail-fastskips every other pending or queued unit with reasonfail_fast; running units finish. A stop request cancels pending and queued units and lets running units finish. - An internal error (a bug in the runner or executor, not a failed unit) stops dequeuing, drains the running units and is re-raised after the scheduler result is built.
- The scheduler emits
unit.queued,unit.skippedandunit.cancelled. The invocation that executes a unit emitsunit.started, the terminal unit event and themodel.*events. Withboundary: taskthe child emits its own and the owning invocation forwards them, keeping the child's invocation id and sequence. Attempt files are written by the runner, and the child's attempt file is the authoritative result. - A unit invocation (
--select unit:<id>only) takes no run lock, emits norun.*events and does not finalize. - The run lock is a lease (60 s, heartbeat every 20 s), not a process liveness check.
- Refinements made with the process executor. A child gets
PIPELOOM_PARENT_INVOCATION_IDand then opens only its stderr jsonl sink and its own run file sink, never the project's sinks. The parent relays every child event exceptinvocation.*anddiagnostic, and sinks that setforwarded = False(the run file sink) do not receive relayed events. In unit mode the scheduler does not announceunit.queued,unit.skippedorunit.cancelled; the owner does. A child that exits without an attempt file is reported by the parent as PLX106: it writes the failed attempt file at the number above the pre-launch maximum and emits the oneunit.failedevent. A held run lock is PLX105 (holder, run and lease expiry).--expect-plan-hashis checked before any work (PLX103), and a manifest of another project or target, or one edited after it was written, is PLX107.
Consequences¶
- Scheduler events are deterministic for a given completion order; with one worker or the simulator the whole stream is.
- Property tests run the scheduler on random graphs with the simulator and check the invariants.
- The thread executor cannot stop a running unit. Cooperative cancellation, retries and timeouts come in 0.3 and change
wait_anyandcancelin an additive way. - Starting a subprocess per unit costs about a second per unit.
Status¶
Accepted
Date¶
2026-11-04