Repository navigation
16 Invariants
A constraint written as a fact: a key, a statement, a machine probe and a path:line origin that must exist. The set is append-only, removal takes two parts, verification reads the whole state, and a violation rolls back the whole declared mutation.
Edition: Pro (invariant-pin, six operations). Operations: invariant_pin, invariant_release,
invariant_unpin, invariant_list, invariant_verify, invariant_mutation.
Implicit constraints are the part of a system that no test names. A sequence of small edits can drop one without any file looking wrong: the fifth change breaks something it never touched. Recording the constraint as a sentence is not enough — a sentence does not fail. Recording it as a test is better, but a test can be deleted quietly along with the code it guards.
An invariant is a fact with three parts that cannot be faked: what is asserted, how it is checked, and where in the corpus the assertion comes from. The origin must exist; a pin that points nowhere is refused.
-
Append-only is enforced by the database, not by convention. The
invariantrow cannot be updated or deleted: triggers refuse. A second pin on the same key is refused too. -
Removal takes two parts.
invariant_releaserecords that the constraint is gone from the system, with a reason and a place.invariant_unpinthen removes the entry — and it refuses without the first part, refuses while the probe still holds (constraint_present), and refuses when there is no verdict (unverifiable_constraint).retireis a separate fact: "this was never an invariant", kept in the journal. -
Verification reads the state, not a diff.
invariant_verifyruns every probe against the current corpus: symbol existence, an edge with its direction checked, the corpus checksum, a declared script, or an honestmanual. There is no "list of changed files" parameter — a diff answers a different question. -
Verdicts are named:
hold,partial,broken,empty. Two runs on unchanged state produce the samedigest. -
A violation rolls back the whole area.
invariant_mutationdeclares an area by patterns, snapshots it under.ragraf/mutations/, verifies after the change, and on a violation restores the WHOLE area rather than repairing the place that broke. Files changed outside the declared area are named (outside_scope), and the status becomespartial_rollback— an honest partial, not a success.
- It does not decide what matters: a probe that asserts nothing useful passes forever.
- It does not replace tests: a test proves behaviour on a case, an invariant proves a property of the state.
- It does not repair: rollback returns the declared area to the snapshot; the change itself is the author's business.
invariant_pin key=graph.direction statement="M·v gives predecessors" probe={kind: symbol, name: _neighbors} anchor="src/ragraf/graph_algo.py:1"
invariant_verify
invariant_mutation action=begin paths=["src/ragraf/graph_algo.py"]
# ... change ...
invariant_mutation action=end mutation_id=<id>
Details and limits: docs/03_implementation/INVARIANTS.md in the repository.