aien-architecture-mv
Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.
Brought by drakestapleton
aien-architecture-mv / formal / invariants / sequence-stale-id-v1.toml
| 1 | schema_version = 0 |
| 2 | id = "AIEN.INV.SEQUENCE.STALE_ID.V1" |
| 3 | version = 1 |
| 4 | status = "SEEDED" |
| 5 | |
| 6 | statement = """ |
| 7 | A sequence id is a pair (slot, generation). An id resolves to a live record only when its slot exists, the slot's current \ |
| 8 | generation equals the id's generation, and the slot holds a record. Freeing a live id removes the record and changes the \ |
| 9 | slot's generation, so the freed id and every copy of it stop resolving; freeing a stale, unknown or already freed id changes \ |
| 10 | nothing and reports failure. Generation 0 is never issued. Allocation is refused exactly when every slot is occupied, so the \ |
| 11 | active count never exceeds the capacity, rises by one on a successful allocation or fork and falls by one on a successful free. \ |
| 12 | Fork from an id that does not resolve is refused. Re-allocating a just freed slot never returns the freed id. The generation field \ |
| 13 | is finite (u32): after exactly 2^32 - 1 frees of one slot the generation repeats, so a stale id from before the cycle would resolve \ |
| 14 | again. This limitation is part of the invariant and is NOT eternal ABA freedom.""" |
| 15 | |
| 16 | assumptions = [ |
| 17 | "Single scheduler thread owns the arena (no concurrency model; the Rust arena has no locks).", |
| 18 | "Generation arithmetic is the u32 rule next = max((g + 1) mod 2^32, 1); the model carries it exactly.", |
| 19 | "Record contents are not modelled, only whether a record is present.", |
| 20 | "Callers do not keep an id across 2^32 - 1 frees of its slot; the code does not enforce this, and the runtime arena has no retire path (the scheduler arena retires the slot at u32::MAX instead).", |
| 21 | ] |
| 22 | |
| 23 | semantic_types = ["SequenceId", "SequenceArena", "SlotGeneration", "ActiveCount", "Capacity"] |
| 24 | |
| 25 | oracle_models = ["lean"] |
| 26 | |
| 27 | evidence_requirements = [ |
| 28 | "positive corpus: first allocation, free then reuse with a new generation, live fork", |
| 29 | "negative corpus: never allocated, stale after free, stale free refused, wrong generation, generation zero, slot out of range, stale fork, capacity exhausted", |
| 30 | "deliberate mutants that must not survive: free keeps generation, resolution ignores generation, wrap yields generation 0, free keeps active count, fork skips the parent check", |
| 31 | "the generation wrap limitation stated as a theorem (iterGen genMax g = g) next to the no-reuse-before-wrap theorem", |
| 32 | "existing implementation unit tests and the PREFILL-E2E runtime tests keep passing", |
| 33 | ] |
| 34 | |
| 35 | required_counterexamples = [ |
| 36 | "free_keeps_generation", |
| 37 | "resolution_ignores_generation", |
| 38 | "wrap_to_generation_zero", |
| 39 | "free_keeps_active_count", |
| 40 | "fork_from_stale_parent", |
| 41 | ] |
| 42 | |
| 43 | omega_takeover_condition = """ |
| 44 | Omega expresses the arena rules as native propositions over (slot, generation) records, accepts the positive corpus, rejects the \ |
| 45 | negative corpus, kills the required counterexample mutants, states the finite-generation limitation as an explicit assumption, and \ |
| 46 | emits a canonical proof/evidence identity that the gates consume, with Lean absent.""" |
| 47 | |
| 48 | [[positive_examples]] |
| 49 | name = "free_then_reuse" |
| 50 | description = "Allocate (0,1), free it, allocate again: the slot comes back as (0,2). The old id (0,1) does not resolve." |
| 51 | |
| 52 | [[positive_examples]] |
| 53 | name = "live_fork" |
| 54 | description = "Fork from a live parent id succeeds and returns a new live id." |
| 55 | |
| 56 | [[negative_examples]] |
| 57 | name = "stale_id_after_free" |
| 58 | description = "An id used after its record was freed does not resolve, and freeing it again is refused." |
| 59 | |
| 60 | [[negative_examples]] |
| 61 | name = "wrong_generation" |
| 62 | description = "Right slot, generation that is not the slot's current one: does not resolve." |
| 63 | |
| 64 | [[negative_examples]] |
| 65 | name = "capacity_exhausted" |
| 66 | description = "Allocation when every slot is occupied is refused." |
| 67 | |
| 68 | [[counterexamples]] |
| 69 | name = "free_keeps_generation" |
| 70 | description = "Free leaves the generation unchanged, so a reallocated slot reissues the freed id." |
| 71 | |
| 72 | [[counterexamples]] |
| 73 | name = "resolution_ignores_generation" |
| 74 | description = "get resolves any id whose slot holds a record, whatever generation it carries." |
| 75 | |
| 76 | [[counterexamples]] |
| 77 | name = "wrap_to_generation_zero" |
| 78 | description = "The generation wrap produces 0, which the scheduler arena treats as invalid." |
| 79 | |
| 80 | [[counterexamples]] |
| 81 | name = "free_keeps_active_count" |
| 82 | description = "Free forgets to lower the active count, so capacity accounting drifts." |
| 83 | |
| 84 | [[counterexamples]] |
| 85 | name = "fork_from_stale_parent" |
| 86 | description = "Fork allocates a child even though the parent id does not resolve." |
| 87 | |
| 88 | [[implementation_surfaces]] |
| 89 | repo = "aien-dev/sovereign-core" |
| 90 | path = "crates/aien-runtime/src/sequence.rs" |
| 91 | kind = "production" |
| 92 | observed_at = "dd1fe323d5fc774ff0fe6faaadebfea6450563c0" |
| 93 | note = "SequenceArena: new (line 76 onward), allocate (98), fork (131), get (178), free (197, wrapping_add(1).max(1) at 202), active_count." |
| 94 | |
| 95 | [[implementation_surfaces]] |
| 96 | repo = "aien-dev/sovereign-core" |
| 97 | path = "crates/aien-scheduler/src/sequence.rs" |
| 98 | kind = "production" |
| 99 | observed_at = "dd1fe323d5fc774ff0fe6faaadebfea6450563c0" |
| 100 | note = "Second SequenceArena: free_sequence (512) retires the slot at u32::MAX (523) instead of wrapping. Modelled only as the pure rule retireNext." |
| 101 | |
| 102 | [[observations]] |
| 103 | surface = "crates/aien-runtime/src/sequence.rs" |
| 104 | text = """ |
| 105 | free (197 to 209) bumps the generation with wrapping_add(1).max(1), so the runtime arena has no retire path: a slot freed 2^32 - 1 times \ |
| 106 | reissues an old id. get (178) resolves on slot-in-range, equal generation and a present record. allocate and fork pop a free slot and \ |
| 107 | hand out its current generation. active_count is incremented on both and decremented with saturating_sub on free; the model proves the \ |
| 108 | subtraction never saturates for a well formed arena.""" |
| 109 | |
| 110 | [[observations]] |
| 111 | surface = "crates/aien-scheduler/src/sequence.rs" |
| 112 | text = """ |
| 113 | divergence between the two arenas: the scheduler arena retires a slot when its generation reaches u32::MAX (free_sequence, 512 to 523) \ |
| 114 | and never reuses it, so it has no ABA window at the cost of capacity; the runtime arena wraps. Both are in production code in the same \ |
| 115 | workspace. Recorded, not asserted either way. insert_with_id in the scheduler arena also accepts a caller supplied generation and sets the \ |
| 116 | slot generation to it, which the model does not cover.""" |