Graph State Backend: Model-Checking Results
Status: Draft, model of the Graph State Backend RFC (revision 5 as
amended), extended before phase 1.
Date: 2026-11-04
The concurrency protocol of the graph state backend is specified in TLA+ in specs/graph-state/
and checked with TLC. The specification, configurations, runner (check.sh), installation
instructions and per-configuration results are in specs/graph-state/README.md and
specs/graph-state/tlc_results.txt.
Scope
One state machine at the granularity of database transactions, process steps and cloud calls:
- Database: rows with revision, incarnation, intent fingerprint, evaluated input and its
revision, object,
stale_inputsmark and tombstones; reverse-edge generations; leases on entries, object identities, reverse-edge predicates, provider scopes and the app (IS/IX/S/SIX/X) through a queue with aging; expiring ownership; operation records with replacement sub-stages (delete_dispatched,delete_committed,create_dispatched), recovery epochs and the dispatching actor; commit history; the data-source observation cache. - Runs: plan (merge against a trustworthy baseline, then evaluation, with follow-ups propagating through intermediate entries), lease, validate, reserve, mark dispatched, send, commit; a deferred second round planned from committed rows and checked against the leases taken up front; outputs and state-only removals; rollback of creates after a provider error; loss of ownership terminal.
- Recoverers: several, each taking over by advancing the epoch, then aborting, ingesting, reporting or continuing a replacement's create; they crash and are taken over in turn.
- Checkpoint restore by an operator, state-only, with consumer and identity checks.
- Cloud: objects in provider scopes, in-flight calls, provider-assigned and client-chosen identities, provider errors.
Instances are small: 1 to 3 runs, up to 3 entries in a chain, up to 4 objects, 1 or 2 recoverers.
Results
With TLC2 2.19 (TLA+ Toolbox 1.7.4) on OpenJDK 21, all 104 configurations give their expected result, in about 12 minutes in total; the largest has 377,396 distinct states.
| Group | Count | Outcome |
|---|---|---|
| Intended design, safety | 47 | Every invariant holds, in every scenario, with and without crashes, expiry, concurrent recoverers and provider errors |
| Liveness | 7 | Queued requests are granted, quarantined operations resolved, interrupted replacements completed |
| Reachability probes | 7 | Violated as expected: concurrent calls, completion, recovered commits, a recoverer-completed replacement, a deferred round failing its coverage check, a restore, a stale mark |
| Regression variants | 37 | Each fails its named invariant (one deadlocks, as expected) |
| Lease queue, commit frontier | 6 | Aging and the RFC's counter row pass; their broken forms fail |
An independent Python re-implementation (specs/graph-state/mirror/) explores the same 91 safety
configurations, finds exactly TLC's distinct-state count for all 47 intended ones, and fails every
regression variant on its named invariant.
The invariants: no overlapping mutations; one object per address; no lost update; no unleased
mutation; no unleased consumption; consumed values current; fenced commits (authority judged at the
transition); ingestion at most once; recovery never admits overlap; no dangling dependents; unique
ownership; no silent revert; no lost replacement; accurate stale_inputs marks; restores respect
consumers; patch serializability on histories that actually succeeded, against an oracle
independent of the implementation's follow-up logic; outputs consistent.
Protocol Changes Required By The Model
New bugs in the amended revision 5:
- Rollback must restore re-created rows, not tombstone them (found by TLC). A's replacement of
pcommits its delete and A's lease expires; recovery reports, sopis gone (intent kept, no object). B re-createsp; B's next operation fails and its rollback deletes what it created, tombstoningp:d, which consumedpbefore B ran, is left dangling andp's intent is lost. Rollback should write a tombstone only for entries the run created from absence, and give a re-created entry back its previous intent with no object. - Declared observations must register reverse edges (found by reasoning, confirmed by TLC).
With
observes=pnot inedges(p), a run updatingpcannot see that another run just madexobservep, andxkeeps the old value: bug 1 of the first round, through a data source.
Requirements the RFC should state explicitly, each confirmed by a variant that breaks without it:
- Replacements are one operation through sub-stages; the footprint (address, identity, scope for the create) is held across the gap when recovery may continue; termination evidence applies to every dispatched sub-stage, including a create dispatched by a recoverer (evidence about that recoverer's process); recovery writes are fenced by the recovery epoch and idempotent by attempt.
- Client-chosen identities: such a create must lease the identity (
X); the scope'sSdoes not exclude two creates of the same name. - Deferred rounds: coverage includes provider-scope keys of creates whose scope is only known after an earlier round, and references returned by runtime functions; deferred deletes are leased up front; leases never grow (the growing variant deadlocks).
- Reverse edges: evaluation-induced follow-ups are value-changing writes (
Son their edges); moving a reference between targets bumps both generations. stale_inputsmarks are written in the input's commit transaction, or with a revision compare-and-swap whileSon the edges is held.- Outputs are never rewritten by runs that do not lease them (today's
_store_outputsbehaviour fails); rollback removes outputs the run created. - Observations are re-read after leasing; the cache is never used as provenance.
- Restore checks consumers under its leases (including
Son the entry's edges), takesXon any identity it restores and never waives identity uniqueness, even when forced. - Frontier: the counter row inside the commit transaction is required; a sequence allocated outside the transaction and then aborted freezes a contiguous frontier forever.
Original Model Bounds And Later Extensions
The original GraphState model excludes general concurrent operation graphs within a run sharing a footprint; pipelined commits (excluded by the
RFC's commit-before-completion rule); approval combined with in-flight operations; provider settings
and runtime checks; retention; general clocks (expiry in GraphState is a nondeterministic step);
larger instances. Termination evidence, the
identity of a create whose response was lost, and the completeness of read provenance are assumed,
not checked.
ApprovalLifetime.tla adds eight focused configurations alongside the original 104. Its two
atomic rounds share one grant. A finite approval clock advances independently of heartbeat renewal;
timeouts end the run, preserve previous rounds and release its grant. Late answers cannot resume
execution, and a mutated run cannot reacquire after a deferred timeout. Reachability probes cover
initial/deferred expiry and a late callback. Broken variants demonstrate missing release, accepting
late approval, reacquiring after mutation and rolling back on timeout. The combined models below
add operation, provider/check and database-clock execution to these focused checks.
SiblingScheduler.tla adds 13 focused configurations for one grant, a conflicting holder/waiter
and an independent state write sharing two execution slots. Its intended cases cover durable
success, known abort, uncertain/kept results and ownership loss; reachability probes show that
independent work proceeds while the holder is still running and that retained results stop the
waiter. Broken variants hold execution capacity, treat a returned response as durable, ignore
retained authority, repeat a call after its effect, count a wait as a failure or ignore loss.
All have their expected outcomes in specs/graph-state/sibling_results.txt. This abstraction does
not include general compatible-operation graphs, database rows, provenance or recovery epochs;
the combined models below supply bounded multi-operation execution and replay.
OwnedTransaction.tla adds seven focused configurations for run-row ownership held across SQL
work and receipt waits. It separates buffered response/claim/state/queue changes from atomic
publication, advances a bounded database clock and permits independent grant loss while epoch
changes wait for the row lock. Safety and fair completion each explore 778 states. Broken
variants publish after expiry, trust a lost grant, or validate before a delayed outer receipt;
reachability probes publish checkpoint/cutover receipts and recovery claims. Results are in
specs/graph-state/owned_transaction_results.txt. Grant installation, SQL rollback and provider
execution are abstracted. The combined apply extension below carries its publication decision
through operation/provider/check execution and real SQL replay.
The initial combined implementation corpus (specs/graph-state/histories/) now runs four curated
histories and all 20 completion orders of two parallel updates through the same interpreter in
memory and PostgreSQL. It uses real runtime/provider/check provenance, fixed plan admission,
operation records, kept-response journals, recovery attempts, queue grants and checkpoint APIs.
Its independent oracle checks actual consumed values against committed history, payloads against
those reads, overlapping physical targets, one ingestion per operation and stable historical
revisions. Client monotonic time and database lease expiry are controlled independently. An
independent create commits during the sibling calls, and restoring their consumed provider
revision is refused. Mutation tests establish that missing provider/check/value reads and a
substituted payload are detected.
This corpus found that a recovered observation (or a partial error response) could falsely claim
configuration convergence. With drift_correction=False, an update that never took effect could
then be silently accepted as drift. End-to-end regressions now require the next apply to reconcile
the requested value, while successful kept responses can remain ready. The original model's cloud
tracks existence, not returned configuration values, and cannot detect that distinction.
Those original implementation histories are curated rather than TLC-generated. The additional
bounded CombinedExecution.tla model now joins finite update DAGs, provider/check/value
inputs, independent client/database clocks, actual cloud/row values and convergence evidence.
Recovery and the original run race to resolve durable operations; input writers wait for every
retained sibling. Responses stored in the database and responses kept after loss are distinguished
from observations. The model therefore detects an observed-but-unacknowledged value being marked
ready, which the original GraphState cloud abstraction cannot detect.
All 36 configurations have their expected outcomes in
specs/graph-state/combined_execution_results.txt: 15 intended safety/liveness cases, nine broken
variants and twelve reachability probes. The model accepts a topological node order and a family
of dependency graphs. Every chain, fork, join and diamond case passes with and without failures;
an exhaustive family selects any of the 64 forward-edge DAGs on four ordered nodes, exploring
12,658,733 distinct states with failures and 39,203 without. Fair completion passes across
all 64 graphs without failures. Fair recovery on forks and diamonds resolves pending operations
and lets input writers proceed; unstarted dependents after loss remain for a fresh plan.
New invariants require parent commitment/convergence before a dependent sends and compare its
captured parent values with the intended new values. Broken variants also omit a dependency read
or send a dependent early, alongside missing provider/check/value reads, released input protection,
skipped database fences, ignored local loss and false observation convergence.
The twelve witnesses cover parallel sends, normal
completion, observed recovery with different cloud values, late kept-response ingestion, input
publication after sibling recovery, independent work, restore refusal and termination without an
effect, plus full chain/fork/join/diamond executions. execution_traces/ contains their complete
states exported directly by TLC, with hashes
binding them to the exact model and configuration.
The same memory/PostgreSQL interpreter now drives those states' events and compares row values,
statuses, physical cloud values, call settlements, response presence, persisted operation stages,
ingestion counts and input revisions after every action. Replay derives its graph from the initial
model event and re-evaluates each node's actual runtime inputs before reservation. Its independent
oracle requires committed parent operations and readiness. Missing parent reads, stale planned
parent payloads and invented cloud values are rejected even with an otherwise valid event list.
Regeneration instructions are in specs/graph-state/README.md.
Eight actual AWS provider workloads run the same four graph shapes against PostgreSQL and FakeCloud: cross-stack runtime values, declared pre-apply checks, deferred provider settings, outputs and replacement triggers. After create and update/replacement, every value and consumed revision agrees with committed state; the final unchanged apply sends no managed mutation. Each apply reports zero unattributed reads. The per-wire-call capability audit checks every managed RPC. Ordinary fork/diamond updates overlap, while creates/replacements serialize when adding or removing their common parent's reverse edges.
CombinedReplacement.tla extends that model with both calls of a replacement, actual absence,
retained identity and a competing provider alias. Seventeen configurations check two-node siblings
and chains, including fair recovery/input-writer/alias progress; six further TLC witnesses replay
normal completion, a sibling across the gap, dependent consumption, gap/delete recovery, kept
responses and observed creates. The independent oracle requires one operation through both calls,
one delete followed by at most one final write and a new incarnation.
CombinedApply.tla adds initial/deferred approval and SQL wait/buffer/publication stages. Two-node
chains and three-node joins combine independent approval/database/client clocks, original-grant
coverage, late callbacks, retained completed changes, replacement stages, alias exclusion and
recovery. Five regression variants reject omitted tail/grant checks, late approval, capability
expansion and reacquisition. Eight more witnesses replay actual bounded approval and deferred
validation. PostgreSQL replay observes a real operation-row lock wait, buffered row/operation facts
inside SQL, and old frontier/history outside it. An unrelated grant key is removed before the
writer locks grant rows; the complete-grant tail check must roll the buffered writes back.
Another witness lets database time expire while the writer holds its run-row lock, then recovers
the retained response after rollback. Fair checks require prompts/transactions to end, pending
operations to resolve and input writers and alias requests to proceed.
Four real AWS/FakeCloud pipeline cases also verify a buffered first-round commit followed by deferred approval expiry, under app/resource grants and checkpoint/rollback. They keep the parent, leave the child absent, release the grant, report zero unattributed reads and send exactly one managed call despite the late callback. There are now twenty-six TLC witnesses across the combined models; the original modules and artifacts retain their earlier results.
These are bounded scenario checks: fixed-grant admission and recovery claims remain atomic assumptions in the combined models, and restore remains a denied request whose blockers replay checks in the real backend. The update-DAG bound is four nodes; approval/SQL checks use three nodes with one replacement. Detailed admission, queue, administration and recovery models remain in use. Complete provenance beyond the audited workloads, broader provider/type contracts, public concurrency controls and high-fanout/multi-writer scale evidence remain backend delivery work.