Add durable state graphs, checkpoints, and resumable execution (#12) #31
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nsaspy/prolog-rlm!31
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feature/issue-12-durable-graph"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #12.
Durable Prolog state graphs
Replace the
rlm_graphstub with a validated graph runtime built around declarative state schemas, nodes, fixed/conditional edges, closed reducers, bounded loops, subgraphs, interrupts, checkpoints, history, streaming events, resume, wall-time limits, and cancellation.Graph specs contain only IDs and declarative data. Trusted node/router callables and compiled subgraphs live in a separate host registry; model-produced data never becomes a callable.
Compile-time validation
The compiler rejects invalid graphs before execution, including duplicate state fields/nodes, reserved node names, missing registry entries, invalid edge targets, duplicate route keys, unreachable nodes, nodes without a structural path to
end, and malformed start/end topology.State and reducers
Schemas declare field type/default/reducer. Supported types are
any,atom,string,integer,number,boolean,list, anddict. Reducers are intentionally closed toreplace,append, andsum.Runtime bounds
Execution is independently bounded by total node steps, per-node visits, and hard wall time. A router may create runtime loops, but those loops cannot execute without bound.
Interrupt / resume
A node can return
interrupt(Reason, Patch). The patch is applied and the next edge is resolved before checkpointing, so resume continues from the next node rather than repeating the interrupting side effect. Resume values are exposed asContext.resume;resume(Value, Patch)may also atomically update state.Checkpoints and history
Add memory and SWI
library(persistency)backends. Persistent checkpoints/events contain only ground serializable graph state—not trusted closures. Event payload dict tags are canonicalized before persistence/streaming so JSON-style anonymous tags cannot make otherwise-ground events non-ground.The acceptance suite proves both in-process detach/reattach and a literal process restart: one fresh
swiplprocess pauses/persists and exits; a second freshswiplprocess loads the graph definition/registry from scratch, reattaches the journal, resumes, and completes.Cancellation
Graph cancellation tokens actively signal a currently executing graph thread. Nested inline subgraphs share the same token and use reference-counted thread registration, preventing a child graph from removing its parent's cancellation boundary.
Subgraphs
Compiled subgraphs can be registered as node implementations. Completed child state is converted to reducer-aware deltas before merging into the parent;
sumandappendtherefore preserve semantics instead of double-applying absolute child state.Public API
Expose graph defaults, compilation, backend lifecycle, run/resume, checkpoint/history, and graph cancellation through the main
rlmmodule.Deterministic acceptance
Exact-head deterministic CI is green and covers:
Safety / cleanup
Temporary branch-only write-capable patch workflows/helpers used during connector-only development are removed from the final tree. Normal CI remains
contents: read.Do not merge until exact-head deterministic CI and the same-repository REAL OpenRouter regression job are both green, the PR is mergeable, and the final diff/credential scan is clean.