Skip to content

Commit 11c4b5e

Browse files
committed
fix(tlaplus): restore VeriSimDB TLA+ specs removed by the extraction
verify-tlaplus.yml model-checks verisimdb/verification/proofs/tlaplus, but the extraction in ea2ecfd deleted that directory. The specs (V5 OctadAtomicity, V9 Normalizer, V10 Serializability) have no counterpart in hyperpolymath/verisimdb, so the check failed on a missing working directory. Restore them verbatim from ea2ecfd^; TLC reports no error for all three.
1 parent 7049960 commit 11c4b5e

8 files changed

Lines changed: 682 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-License-Identifier: MPL-2.0
2+
# TLC model-checker scratch output.
3+
states/
4+
tlc.log
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
\* SPDX-License-Identifier: MPL-2.0
2+
\* TLC configuration for Normalizer.tla (V9).
3+
\*
4+
\* Bounded instance: 4 modalities (abstracted from 8), 3 distinct values,
5+
\* MaxSteps=3. State space = |Values|^|Modalities| initial states (3^4=81)
6+
\* times up to MaxSteps transitions. Convergence happens in 1 step, so
7+
\* effective space ~= 81 * 2 = 162 reachable states. Finishes instantly.
8+
\*
9+
\* Run with:
10+
\* java -cp tla2tools.jar tlc2.TLC -config Normalizer.cfg Normalizer.tla
11+
\* or via `just verify-tlaplus`.
12+
13+
SPECIFICATION Spec
14+
15+
CONSTANTS
16+
Values = {"v0", "v1", "v2"}
17+
MaxSteps = 3
18+
19+
INVARIANTS
20+
NormalizerSafe
21+
22+
PROPERTIES
23+
Convergence
24+
25+
CHECK_DEADLOCK FALSE
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
------------------------------- MODULE Normalizer -------------------------------
2+
\* SPDX-License-Identifier: MPL-2.0
3+
\* Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
4+
\*
5+
\* V9: Normalizer determinism + convergence.
6+
\* Corresponds to rust-core/verisim-normalizer/src/lib.rs (StorageRegenerator).
7+
\*
8+
\* The verisim-normalizer resolves drift between the 8 modalities of an octad
9+
\* by picking an authoritative source modality and regenerating the others
10+
\* from it. The real system has a (source, target) strategy table -- Document
11+
\* is the usual authoritative source for Vector/Semantic/Graph regeneration,
12+
\* with cosine-similarity drift measured against Vector and Jaccard against
13+
\* Semantic. This spec abstracts that machinery into its essential claim:
14+
\*
15+
\* - Determinism: normalisation is a *function* of state. Given the same
16+
\* input octad, normalisation always produces the same output octad;
17+
\* there is no schedule-dependent or source-rank-tie non-determinism.
18+
\* - Convergence: starting from any drift-ed state, repeated normalisation
19+
\* reaches a drift-free fixed point in bounded time.
20+
\*
21+
\* The spec also checks that the fixed point is *stable* (Normalize is
22+
\* identity on a drift-free state).
23+
24+
EXTENDS Naturals, FiniteSets, TLC
25+
26+
CONSTANTS
27+
Values, \* abstract set of possible modality payload hashes
28+
MaxSteps \* bound on normalisation rounds for model-checking
29+
30+
\* Modalities and their deterministic priority ordering are module-level (TLC
31+
\* config files cannot represent record literals, and the real system has a
32+
\* fixed strategy table anyway). Priority is strictly injective by
33+
\* construction here -- that injectivity is exactly what makes the CHOOSE in
34+
\* SourceOf deterministic, and it is the spec's central structural claim.
35+
Modalities == {"graph", "vector", "semantic", "document"}
36+
37+
Priority == [graph |-> 1, vector |-> 2, semantic |-> 3, document |-> 4]
38+
39+
ASSUME Cardinality(Values) >= 1
40+
ASSUME MaxSteps \in Nat
41+
ASSUME \A m1, m2 \in Modalities: (m1 /= m2) => (Priority[m1] /= Priority[m2])
42+
43+
VARIABLES
44+
state, \* [Modalities -> Values] -- current octad snapshot
45+
steps \* Nat -- normalisation rounds elapsed
46+
47+
vars == <<state, steps>>
48+
49+
TypeOK ==
50+
/\ state \in [Modalities -> Values]
51+
/\ steps \in 0..MaxSteps
52+
53+
\* Drift holds when any two modalities disagree on the payload.
54+
HasDrift(s) ==
55+
\E m1, m2 \in Modalities: s[m1] /= s[m2]
56+
57+
\* The deterministic authoritative-source function. Under the injectivity
58+
\* ASSUME above, CHOOSE returns the unique highest-priority modality. This
59+
\* is the single piece of the spec that, if wrong, would make the whole
60+
\* normaliser non-deterministic -- so it is the thing determinism hinges on.
61+
SourceOf(s) ==
62+
CHOOSE m \in Modalities:
63+
\A other \in Modalities: Priority[m] >= Priority[other]
64+
65+
\* The normaliser: rewrite every modality to the source's value.
66+
Normalize(s) ==
67+
[m \in Modalities |-> s[SourceOf(s)]]
68+
69+
\* Non-deterministic initial state; all octads are possible starting points
70+
\* for the model-check.
71+
Init ==
72+
/\ state \in [Modalities -> Values]
73+
/\ steps = 0
74+
75+
\* One round of normalisation. Guard by HasDrift so converged states are
76+
\* stuttering; guard by MaxSteps for finite model-check.
77+
Step ==
78+
/\ steps < MaxSteps
79+
/\ HasDrift(state)
80+
/\ state' = Normalize(state)
81+
/\ steps' = steps + 1
82+
83+
Next == Step
84+
85+
\* Weak fairness forces Step to fire while drift remains, which is what makes
86+
\* Convergence true. Without it, the system could stutter forever in a drifted
87+
\* state (that would be a real bug in the implementation, not the spec).
88+
Spec == Init /\ [][Next]_vars /\ WF_vars(Step)
89+
90+
--------------------------------------------------------------------------------
91+
\* Safety
92+
--------------------------------------------------------------------------------
93+
94+
\* I1. SourceOf is well-defined: the CHOOSE always returns an element of
95+
\* Modalities, and that element is the unique priority-maximum. Trivial from
96+
\* the ASSUME, but stated explicitly so TLC exercises it on every state.
97+
SourceIsMaximal ==
98+
\A other \in Modalities:
99+
Priority[SourceOf(state)] >= Priority[other]
100+
101+
\* I2. Idempotence of Normalize: normalising a normalised state is a no-op.
102+
\* This is a property of the *definition* of Normalize; TLC checks it across
103+
\* all reachable states including the non-deterministic Init.
104+
NormalizeIdempotent ==
105+
Normalize(Normalize(state)) = Normalize(state)
106+
107+
\* I3. Post-Step drift-free: immediately after Step, no drift remains.
108+
\* Implementation: Step replaces state with Normalize(state), which makes
109+
\* every modality equal to state[SourceOf(state)] -- so any two modalities
110+
\* agree, i.e. ~HasDrift. TLC verifies by exploring.
111+
PostStepNoDrift ==
112+
(steps > 0) => ~HasDrift(state)
113+
114+
\* I4. Stability of fixed point: in any drift-free state, Normalize is the
115+
\* identity. This is the "once converged, stay converged" guarantee.
116+
FixedPointStable ==
117+
~HasDrift(state) => (Normalize(state) = state)
118+
119+
NormalizerSafe ==
120+
/\ TypeOK
121+
/\ SourceIsMaximal
122+
/\ NormalizeIdempotent
123+
/\ PostStepNoDrift
124+
/\ FixedPointStable
125+
126+
--------------------------------------------------------------------------------
127+
\* Liveness / convergence
128+
--------------------------------------------------------------------------------
129+
130+
\* Eventually, drift is gone and stays gone. Stronger than "eventually no
131+
\* drift" because the system could in principle re-drift if Step non-
132+
\* deterministically reintroduced disagreement -- the <>[] form forbids that.
133+
Convergence ==
134+
<>[]~HasDrift(state)
135+
136+
THEOREM NormalizerSafety == Spec => []NormalizerSafe
137+
THEOREM NormalizerConverges == Spec => Convergence
138+
139+
================================================================================
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
\* SPDX-License-Identifier: MPL-2.0
2+
\* TLC configuration for OctadAtomicity.tla (V5).
3+
\*
4+
\* Bounded instance: 2 transactions, up to 2 crashes per run. With 8 modalities
5+
\* and 3 status values, state space is bounded by
6+
\* (3 * 2^8)^2 * 3 ~ 1.8M states upper bound; in practice < 100k reachable.
7+
\*
8+
\* Run with:
9+
\* java -cp tla2tools.jar tlc2.TLC -config OctadAtomicity.cfg OctadAtomicity.tla
10+
\* or via the repo `just verify-tlaplus` recipe (see verisimdb Justfile).
11+
12+
SPECIFICATION Spec
13+
14+
CONSTANTS
15+
Txns = {"t1", "t2"}
16+
MaxCrashes = 2
17+
18+
INVARIANTS
19+
OctadSafe
20+
21+
PROPERTIES
22+
EveryTxnResolves
23+
24+
CHECK_DEADLOCK FALSE
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
------------------------------ MODULE OctadAtomicity ------------------------------
2+
\* SPDX-License-Identifier: MPL-2.0
3+
\* Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
4+
\*
5+
\* V5: Transaction atomicity across the 8 modalities of a VeriSimDB octad.
6+
\* Corresponds to rust-core/verisim-octad/src/transaction.rs.
7+
\*
8+
\* A VeriSimDB octad is a record with 8 per-modality projections. A transaction
9+
\* touches a subset of the 8 modality projections and must be either fully
10+
\* committed (all 8 projections updated) or fully aborted (none visible). No
11+
\* PARTIAL state is ever observable outside a transaction's own PENDING scope.
12+
\*
13+
\* This spec models the transaction lifecycle (PENDING -> COMMITTED | ABORTED)
14+
\* together with fault injection (crashes during a PENDING transaction) and
15+
\* proves the Atomicity invariant under an adversary that can interleave
16+
\* multiple concurrent transactions and crashes.
17+
18+
EXTENDS Naturals, FiniteSets, TLC
19+
20+
CONSTANTS
21+
Txns, \* finite set of transaction identifiers
22+
MaxCrashes \* bound on the number of crash events per run
23+
24+
ASSUME Cardinality(Txns) >= 1
25+
ASSUME MaxCrashes \in Nat
26+
27+
\* The 8 modalities of a VeriSimDB octad.
28+
Modalities == {"graph", "vector", "tensor", "semantic",
29+
"document", "temporal", "provenance", "spatial"}
30+
31+
Status == {"PENDING", "COMMITTED", "ABORTED"}
32+
33+
VARIABLES
34+
txnStatus, \* [Txns -> Status] - each transaction's lifecycle stage
35+
modalityUpdates, \* [Txns -> SUBSET Modalities] - modalities already applied
36+
crashes \* Nat - bounded counter for fault-injection events
37+
38+
vars == <<txnStatus, modalityUpdates, crashes>>
39+
40+
TypeOK ==
41+
/\ txnStatus \in [Txns -> Status]
42+
/\ modalityUpdates \in [Txns -> SUBSET Modalities]
43+
/\ crashes \in 0..MaxCrashes
44+
45+
Init ==
46+
/\ txnStatus = [t \in Txns |-> "PENDING"]
47+
/\ modalityUpdates = [t \in Txns |-> {}]
48+
/\ crashes = 0
49+
50+
--------------------------------------------------------------------------------
51+
\* Incremental per-modality application during a PENDING transaction.
52+
\* Each modality can be applied at most once per transaction (enforced by the
53+
\* set-union: \cup already-applied is idempotent, but we also disallow reapply
54+
\* via the `m \notin` guard so TLC bounds the state space by 2^|Modalities|).
55+
--------------------------------------------------------------------------------
56+
ApplyModality(t, m) ==
57+
/\ txnStatus[t] = "PENDING"
58+
/\ m \notin modalityUpdates[t]
59+
/\ modalityUpdates' = [modalityUpdates EXCEPT ![t] = @ \cup {m}]
60+
/\ UNCHANGED <<txnStatus, crashes>>
61+
62+
--------------------------------------------------------------------------------
63+
\* Commit: only allowed once all 8 modalities have been applied. The commit
64+
\* is itself atomic in the spec (single state transition); the Rust source is
65+
\* expected to implement this via a 2-phase commit or equivalent mechanism.
66+
--------------------------------------------------------------------------------
67+
Commit(t) ==
68+
/\ txnStatus[t] = "PENDING"
69+
/\ modalityUpdates[t] = Modalities
70+
/\ txnStatus' = [txnStatus EXCEPT ![t] = "COMMITTED"]
71+
/\ UNCHANGED <<modalityUpdates, crashes>>
72+
73+
--------------------------------------------------------------------------------
74+
\* Abort: unilateral rollback. Clears all applied updates and transitions to
75+
\* ABORTED. Can fire at any time during PENDING.
76+
--------------------------------------------------------------------------------
77+
Abort(t) ==
78+
/\ txnStatus[t] = "PENDING"
79+
/\ txnStatus' = [txnStatus EXCEPT ![t] = "ABORTED"]
80+
/\ modalityUpdates' = [modalityUpdates EXCEPT ![t] = {}]
81+
/\ UNCHANGED crashes
82+
83+
--------------------------------------------------------------------------------
84+
\* Crash during PENDING. Recovery must act as an abort: rollback applied
85+
\* updates, transition to ABORTED. This is the adversarial event that the
86+
\* Atomicity invariant is designed to defeat: without the rollback, a crash
87+
\* mid-transaction would leave some modalities updated and the txnStatus
88+
\* visible, i.e. a partial commit.
89+
--------------------------------------------------------------------------------
90+
Crash(t) ==
91+
/\ crashes < MaxCrashes
92+
/\ txnStatus[t] = "PENDING"
93+
/\ txnStatus' = [txnStatus EXCEPT ![t] = "ABORTED"]
94+
/\ modalityUpdates' = [modalityUpdates EXCEPT ![t] = {}]
95+
/\ crashes' = crashes + 1
96+
97+
Next ==
98+
\/ \E t \in Txns, m \in Modalities: ApplyModality(t, m)
99+
\/ \E t \in Txns: Commit(t)
100+
\/ \E t \in Txns: Abort(t)
101+
\/ \E t \in Txns: Crash(t)
102+
103+
\* Fairness: every transaction eventually resolves (either commits or aborts).
104+
\* WF on (Commit \/ Abort) is sufficient because Abort is always enabled while
105+
\* the transaction is PENDING, so the disjunction is continuously enabled.
106+
Spec == Init
107+
/\ [][Next]_vars
108+
/\ \A t \in Txns: WF_vars(Commit(t) \/ Abort(t))
109+
110+
--------------------------------------------------------------------------------
111+
\* Safety properties
112+
--------------------------------------------------------------------------------
113+
114+
\* I1. The central atomicity claim:
115+
\* COMMITTED => all 8 modalities updated
116+
\* ABORTED => no modalities updated
117+
\* This is the "all-or-nothing" observation externally visible on an octad.
118+
Atomicity ==
119+
\A t \in Txns:
120+
/\ (txnStatus[t] = "COMMITTED" => modalityUpdates[t] = Modalities)
121+
/\ (txnStatus[t] = "ABORTED" => modalityUpdates[t] = {})
122+
123+
\* I2. No observable partial state: once a transaction is no longer PENDING,
124+
\* its modalityUpdates set is either empty or the full 8. This is derivable
125+
\* from Atomicity but stated separately because it is the property consumers
126+
\* of the octad actually rely on ("if I read a committed octad, I never see a
127+
\* half-update").
128+
NoObservablePartial ==
129+
\A t \in Txns:
130+
(txnStatus[t] \in {"COMMITTED", "ABORTED"}) =>
131+
(modalityUpdates[t] = Modalities \/ modalityUpdates[t] = {})
132+
133+
\* I3. Status monotonicity: PENDING can move to COMMITTED or ABORTED, but
134+
\* never the reverse. (This is implicitly enforced by Next -- every action
135+
\* that changes txnStatus requires it was PENDING -- but stating it as an
136+
\* invariant on (txnStatus, txnStatus') is not trivial without action vars;
137+
\* instead we check a weaker "never COMMITTED AND ABORTED" which is trivially
138+
\* true by type but confirms no action flips between terminal statuses.)
139+
StatusMonotone ==
140+
\A t \in Txns:
141+
\neg (txnStatus[t] = "COMMITTED" /\ modalityUpdates[t] = {})
142+
143+
OctadSafe ==
144+
/\ TypeOK
145+
/\ Atomicity
146+
/\ NoObservablePartial
147+
/\ StatusMonotone
148+
149+
--------------------------------------------------------------------------------
150+
\* Liveness
151+
--------------------------------------------------------------------------------
152+
153+
\* Every transaction eventually reaches a terminal state.
154+
EveryTxnResolves ==
155+
\A t \in Txns: <>(txnStatus[t] \in {"COMMITTED", "ABORTED"})
156+
157+
THEOREM AtomicitySafety == Spec => []OctadSafe
158+
THEOREM Resolution == Spec => EveryTxnResolves
159+
160+
================================================================================

0 commit comments

Comments
 (0)