matrx-runtime
The durable-execution substrate for the Matrx platform.
Every unit of work — a utility call, a workflow run, an agent session — is one
row on a single global_execution spine that can nest inside any other. The
substrate owns the concerns all three flavors share, so they compose freely and
share one lifecycle, one nesting tree, one cost ledger, and one enforced state
machine:
- run identity + lineage (
parent_execution_id, denormalized root_execution_id)
- the lifecycle state machine (
transition() — the only legal way to change status)
- the cost ledger + tree-wide budget and quantity limits
- cancellation, deadlines, and down-tree propagation
- generalized checkpoints, leases, recovery, and lifecycle events
- pluggable durable stores (
InMemoryExecutionStore and OrmExecutionStore)
- immutable per-execution context snapshots with explicit inheritance modes
ContextMode.INHERIT deep-copies the parent's snapshot, SCOPE overlays
explicit narrower values, and destructive REPLACE requires a complete
replacement context. Omitting that replacement raises
MissingReplacementContext both at the engine spawn boundary and in
ExecutionContext.derive; silent context erasure is not a valid operation.
Executors plug in as strategies and are NOT owned here: the agent loop
(matrx-ai), the superstep DAG (matrx-graph), utility implementations
(matrx-scraper).
Status: active. The decision core, durable ORM store, context propagation,
metering, budget/cancel/deadline gates, leases, recovery, checkpoints, and
request/execution lifecycle are implemented. aidream adopts them through its
host integration; domain payloads and entity lookup remain host-owned so this
package stays independent and payload-blind.
Durable frontier consumers use runtime.work_item. A provider poll that is
still in progress calls defer_work_item(...): it returns the claim to
pending, schedules not_before, and does not consume the retry budget.
Actual call failures continue through fail_work_item(...) and its bounded
retry/dead-letter policy. pending_work_execution_ids(type, limit) is the
payload-blind discovery seam for host drainers; providers and domain payloads
remain outside this package.
Expired leases obey the same attempt budget: a final expired attempt becomes
dead_letter with a typed error instead of returning to pending. Consumers
that intentionally encode a resumable terminal wait can use the CAS-fenced
resume_failed_work_item(...); it matches the full expected error and restores
the claim attempt consumed while discovering that wait.
Large mixed backlogs use generic priority (lower claims first, seq breaks
ties). Long workers call renew_work_item_lease(...); coordinators use the
bounded list_work_items(...), exact get_work_item(...), and dependency-state
lookup without importing ORM rows.
Design + phased plan: docs/runtime/EXECUTION_SPINE.md.