Stage orchestration and durable execution for LLM-in-the-loop batch pipelines: single-pass and convergence-loop shapes, gates, work-unit strategies, and the SQLite-backed run store with its controller and worker protocol.
This area is the pipeline layer: the code that turns a batch of work units into LLM-driven outputs. It splits into an orchestration plane (the Stage protocol, two pipeline shapes, gates, work-unit strategies, and the convergence gate) and a durable execution plane (a SQLite run store, a prepare/finalize controller, a versioned JSON worker protocol, and operational machinery for deadlines, failure caching, interrupts, and status). The orchestration logic is pure and testable in isolation; execution adds the I/O, concurrency, and durability a real batch job needs. Smaller sub-packages handle audit and provenance analysis, and the LLM backend interface the execution plane calls through.
Where to start
packages/katsoft-llm-kit/src/llm_kit/pipeline/core/__init__.py for the orchestration shapes and their composition rules, or packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/__init__.py for the durable run plane and its module-by-module map.
Routes
- Single-pass run
- packages/katsoft-llm-kit/src/llm_kit/pipeline/core/stage.py -- Stage protocol and compose fold
- packages/katsoft-llm-kit/src/llm_kit/pipeline/core/single_pass.py -- run() delegates to stage.compose; seed_for() for per-unit RNG
- packages/katsoft-llm-kit/src/llm_kit/pipeline/core/gate.py -- Gate and run_gates: the ordered pre-generation gate sequence
- packages/katsoft-llm-kit/src/llm_kit/pipeline/core/workunit.py -- WorkUnit, flat-chunk and graph-walk strategies
- Convergence loop
- packages/katsoft-llm-kit/src/llm_kit/pipeline/core/convergence_loop.py -- grade, select, apply, fill in fixed order, driven to a verdict
- packages/katsoft-llm-kit/src/llm_kit/pipeline/core/convergence.py -- ProgressEvaluator and the four verdicts; the loop stopping rule
- packages/katsoft-llm-kit/src/llm_kit/pipeline/core/cell_policy.py -- consumer cell classification tallied into the Round the gate reads
- Durable run lifecycle
- packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/store.py -- SQLite-backed store: claims, leases, fencing tokens, interrupts
- packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/controller.py -- prepare_run / finalize_run bracket a run; halt handling
- packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/protocol.py -- versioned JSON worker protocol as mountable handlers
- Worker protocol mount
- packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/protocol.py -- build_handlers closes over one store, one adapter, one policy
- packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/adapter.py -- RunAdapter: four responsibilities the consumer implements
- packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/store.py -- the store every verb resolves against
Stage protocol and pipeline shapes
packages/katsoft-llm-kit/src/llm_kit/pipeline/core/stage.py -- the Stage protocol and compose; both pipeline shapes are compositions of it. Open this first when adding a new stage.
packages/katsoft-llm-kit/src/llm_kit/pipeline/core/single_pass.py -- the single-pass entry point: run() folds stages once, seed_for() derives a per-unit RNG seed, Gate and run_gates re-exported.
packages/katsoft-llm-kit/src/llm_kit/pipeline/core/convergence_loop.py -- the four-stage cycle (grade, select, apply, fill) in fixed order, driven to a verdict by the convergence gate. Grade-first ordering is structural and not caller-controllable.
packages/katsoft-llm-kit/src/llm_kit/pipeline/core/convergence.py -- ProgressEvaluator and the CONVERGED, STALLED, CONTINUE, FAILED verdicts. Tunable via stall_window and converge_window.
packages/katsoft-llm-kit/src/llm_kit/pipeline/core/cell_policy.py -- consumer-owned CellPolicy protocol and tally/measure_from; turns a store into the per-cycle Round the loop consumes.
packages/katsoft-llm-kit/src/llm_kit/pipeline/core/gate.py -- Gate dataclass and run_gates: the ordered pre-generation gate sequence the controller consumes.
packages/katsoft-llm-kit/src/llm_kit/pipeline/core/workunit.py -- WorkUnit, FlatChunkStrategy, and GraphWalkStrategy: how a pipeline iterates its units.
packages/katsoft-llm-kit/src/llm_kit/pipeline/core/seed.py -- deterministic per-unit seeding so stochastic gate decisions never churn freshness hashes across runs.
packages/katsoft-llm-kit/src/llm_kit/pipeline/core/vcs_seam.py -- the VcsBackend protocol (open, add, changeset, revert) shared by null, git, and Perforce backends.
Durable run store and controller
packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/store.py -- the SQLite-backed ExecutionStore: the only place run truth lives. WAL mode, per-verb connections, atomic claims with monotonically increasing fencing tokens, lease expiry, append-only attempt log, and opt-in durable interrupts.
packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/model.py -- record dataclasses, the unit state machine (PENDING through five terminal states), and the error taxonomy. Pure data, no SQLite.
packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/controller.py -- prepare_run and finalize_run bracket a run. Also halt handling (record_halt, pause_run, resume_run) and the terminal-skip convention.
packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/adapter.py -- RunAdapter: the consumer's four-responsibility worker contract (reconstruct unit, build request, provide ValidationSpec, apply repeat-safely), plus adapter-version-gated resume.
packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/protocol.py -- the versioned JSON worker protocol (ten verbs) as mountable handlers a consumer wires onto its own entry point. Ships no runnable tool of its own.
Concurrency, scheduling, and deadlines
packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/scheduler.py -- in-memory DAG scheduler with bounded capacity, FIFO ordering, deferred-node priority, and a thread-pool runner (run_graph). Standard library only.
packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/parallel_graph.py -- ParallelGraphStrategy: explicit per-unit dependencies run up to a capacity at once against the durable store. Validates the graph at construction.
packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/deadlines.py -- per-unit wall-time budget, run-wide sticky deadline circuit, and a JSON deadline-notes file for ordering slow units behind fast ones.
Operational records and projection
packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/events.py -- read-side projection of the attempt log into execution-event envelopes (schema v1, plus v2 for interrupts). Requires the bootstrap execution-event module.
packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/failure_cache.py -- negative cache of deterministic failures keyed by the consumer's attempt key. Record only deterministic failures; deadlines and transport errors are transient.
packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/interrupts.py -- the durable interrupt contract: check_request, validate_input, resolution documents, expiry and lapse rules. Reaches the shared interrupt contract and schema validator lazily.
packages/katsoft-llm-kit/src/llm_kit/pipeline/execution/status.py -- bounded read-only RunStatus digest: counts, ages, throughput, capped failure groups, halt state. Never contains prompts, payloads, or outputs.
Analysis, validation, and runtime
The analysis sub-package (with audit and provenance sub-directories) holds audit reports, reasoning chains, provenance tracking, call audits, and replay. The validate sub-package under core defines the output-contract validation spec the adapter and protocol layers consume. The drivers sub-package under execution holds the inline wave driver that executes a prepared wave through the store. The runtime sub-package exposes the LLM backend platform (submit, validate, halt) that the execution plane calls through for every unit dispatch.