Chunk Lifecycle
How run_chunks.status protects worker ownership and prevents stale workers from completing or releasing chunks they no longer own.
Notes
- Run creation inserts chunks as
pendingin their assigned execution placement. They cannot be dispatched while the control run iscreating; dispatch cursors are created only after all placements are seeded. - Each chunk receives a stable
run_shardin the 128-shard logical range. Child execution, attempt, aggregate, and evaluator result rows inherit that shard. - Each coordinator dispatch operation selects a bounded window from one run shard, marks each selected pending chunk with
dispatched_at, and inserts onerun.chunk.readyoutbox event record per chunk with its execution database alias and write epoch. - Coordinator recovery scans expired
leasedchunks on open or draining shards. It incrementsrecovery_count, resets recoverable chunks topending, and inserts a recovery-scopedrun.chunk.readyoutbox event record. A worker can claim the pending chunk once the current shard admission is open. - Chunks at the configured recovery limit are marked
failedand receive a terminal receipt even if some execution rows were never created. - Workers can claim a chunk only when the owning run is
running. - A chunk is completed only after all executions in its case range are terminal and the local shard admission still accepts the claimed write epoch. If any execution is
retry_scheduled, the worker releases the chunk and delays the chunk-ready broker message until the nextretry_afterwindow. - Completion and release validate the opaque chunk claim token, live lease, and local write epoch.
- Completion, terminal failure, exhausted recovery, and cancellation commit a receipt in the same transaction as terminal chunk state. The chunk lock serializes result writers before unfinished authority is retired. Receipt identity and disposition cannot subsequently change.
- Coordinators consume receipts asynchronously; workers acknowledge after local settlement. See settlement and partial results.