kind; structural helpers, such as document-tree building, run inside those dispatched stages. The queue manages claiming, execution, and retry. Failed work remains inspectable with its error and execution history.
Work Item Lifecycle
The table uses JSON status values. The Rust enum variants use title case.
Active Work Kinds
Ingestion
Evidence (Document Processing)
render_doc also invokes the document-tree builder, which splits the active revision into hierarchical doc_node records. That helper is part of the active runtime flow but is not a standalone dispatched work item in the current worker match table.
Extraction
Truth Maintenance
Maintenance
Lease-Based Claiming
Workers claim items using optimistic concurrency control:- Poll: the work queue selects runnable items by descending priority within its claim lanes. The active worker reserves bounded capacity for extraction before filling remaining permits from the general queue, so global priority alone does not determine execution order.
- Filter: items with a
run_aftertimestamp in the future are skipped. - Claim: an atomic conditional update sets the status to
Runningand records theworker_idandlease_expires_at. - Execute: the worker runs the work item handler.
- Complete/Fail: the worker marks the item as
DoneorFailed.
The default lease duration is 300 seconds (5 minutes). If a worker crashes without completing, the lease expires and the item becomes claimable again after a 60-second grace period.
Expired Lease Recovery
Before each poll cycle, the work queue checks for running items whose leases have expired (with a 60-second grace period to avoid races). Expired items are released back toRunnable status so another worker can pick them up.
If a worker finishes work after its lease was recovered, it attempts a force-complete since the work was already done.
Retry with Exponential Backoff
When a work item fails with a transient error (DB write conflict, connection reset, rate limit, timeout), the system applies exponential backoff:
Transient errors are identified by pattern matching on error messages and types:
read or write conflict/transaction can be retriedtemporarily unavailable/timeout/timed outrate limit/too many requestsconnection reset/broken pipeStorageError::Conflict/StorageError::ConnectionErrorPipelineError::LeaseConflict
PIPELINE_WORK_ITEM_TIMEOUT_SECS deadline is handled separately: a
handler that exceeds that lifecycle bound is marked failed. Managed wiki
reconciliation has its own longer bound and extends its lease accordingly.
Inspect and retry failed work
- List work items with
status: "failed"usinglist_work_itemson/mcp/full, orGET /v1/work-items?status=failed. Inspectkind,last_error, andattempts; use the recorded IDs to correlate worker logs. - Correct the cause, such as unavailable credentials, a missing skill, invalid input, or storage contention.
- Call
retry_work_itemwith{"id":"work_item:<returned UUID>"}on/mcp/full. The caller needswrite:work_itemin the same space. This resets a failed item torunnable, clears its lease and error, and resets the attempt count. It does not retry a currently running item. - Verify that this stage and its dependent stages finish. A successful retry request means the work was queued, not that the document finished processing.
work_deadletter record and a dead-letter
library helper. The active worker failure path marks the work item failed;
it does not automatically call that helper or guarantee a separate dead-letter
record. Monitor failed work items as the operational failure surface.
Priority
Work items have an integerpriority field. Higher values are claimed first. Typical priority assignments:
