9. Change: patches, transactions, diffs and code push
9.1 Patches#
Definition 9 (Patch). A patch is a typed double-pushout rule with monic legs that preserve identity on , together with nested application conditions [159] and a base revision. Applying at a match constructs as the pushout complement of and as the pushout of (Figure 14).
Identifiers fix the match: is the inclusion of the elements that names, so applying a patch requires no subgraph-isomorphism search and costs index lookups. The dangling condition makes deleting a node without its ports and incidences a rejected rule rather than a dangling reference. The primitive operations are adding and removing nodes, ports, hyperedges and incidences, re-parenting, and setting an attribute against an expected value. Every graph change is a composite of these, including the elaboration of source code, an agent’s proposal, a migration and a release. Patches are data. They have identities and digests, and they live in the source layer as Artifacts.
Proposition 9 (Local preservation). For every primitive operation there is a precondition , checkable in time proportional to the operation and its declared read set, such that .
Validation is therefore incremental: a transaction checks each operation’s precondition and never re-validates the whole graph. Global constraints (uniqueness, exclusive binding, acyclicity) declare predicate read sets, which commit re-checks. This replaces “apply, then check everything”, which the stable-foundations audit rejects as a definition of validity [295].
Figure 14. Left: applying a patch is a double pushout. Right: parallel-independent patches commute (Theorem 10); their merge is order-free and needs no review beyond each patch’s own.
9.2 Transactions#
A definition commit is a transaction at the graph authority of one consistency domain (a workspace, or a partition of a large one). It carries a base revision, a patch and a read set of predicates. It commits if the base is current, or if no predicate in the read set changed since the base; this is optimistic concurrency with serializable outcome. Readers see either the old revision or the new one. The laws are those of the stable-foundations audit: a failed patch leaves state unchanged; a successful patch advances the revision and preserves ; and at most one patch commits from a given base [295]. Four kinds of change stay distinct, because different authorities commit them:
definition commit (graph authority) activation (host, under an epoch) data transaction (a Store) external effect (a provider).
A change that spans them is a plan executed as a protocol, with an outbox or a saga [140, 166]. It is never a distributed ACID transaction. The word “transactional” in R17 therefore means: transactional for definitions, and planned with receipts for everything else.
Refs and proposals#
The graph authority keeps named refs, each pointing to a revision, and proposals, each a patch with a base revision, an author principal, its checks and a status. A branch, a worktree or an agent’s line of work is a ref. Review and merge act on proposals, and Theorem 10 decides which of them merge without review. A data transaction at a store enforces the invariants that its datasets declare (Section 6) and rejects a violation with a witness. Figure 15 shows the path every change takes.
Figure 15. One path for every change, from a person or an agent alike. A rejected check returns findings; an approval binds the plan’s fingerprint and can never come from the proposal’s author. Execution happens under an epoch, and the receipt becomes an observation that the next query sees.
9.3 Concurrent change and merge#
Theorem 10 (Commutation). Let and be patches applied to at matches and with , so that neither deletes what the other uses, and suppose that each preserves the other’s application conditions. Then applies after and after , both orders give the same graph, and the parallel rule applies to directly.
This is the Local Church–Rosser and Parallelism theorem for adhesive categories [102, 210], which applies by Proposition 1. With identity-preserving rules, “the same graph” means equal, not merely isomorphic. Three consequences follow. Merging independent changes from two people or agents is automatic and order-free. Conflicts are exactly the overlapping delete–use pairs plus violated application conditions, and for a finite rule catalogue they can be enumerated in advance as critical pairs. Application conditions over global predicates can still make two independent patches jointly invalid, for example two providers bound to one exclusive consumer. The commit’s read-set check catches this case: individually valid is not jointly valid. Presentation state (layout, folds, comments) has no invariants and is merged by CRDTs instead, including the tree-move CRDT for regrouping [203, 310].
9.4 Graph diffs replace textual diffs#
The diff between revisions and is the span , where the intersection is computed by joining on identifiers: an merge of sorted identifier columns, or from the change log. A diff is itself a patch. Diffs therefore compose. They invert, because is again a rule. And they apply to any graph that contains their left side, which is the embedding theorem: a change to a region applies wherever the region is mounted. The categorical theory of patches [248] reaches the same structure for files. A reviewer of an RG diff sees typed changes, grouped by layer and ranked by risk. Examples are “Session send gains interceptor Auth at position 0”, “Dataset messages: field roomId now references rooms.id”, and “Scope chat: effect ceiling widened to payments.*”. Textual diffs remain only for the opaque bodies of code entries, attached to the Components they implement. Listing 4 and Listing 5 show a patch written by an agent and the diff a reviewer sees.
val addAuth = patch(base = ref("main"), author = principal("agent:reviewer")) {
addIncidence(edge = "chat.api", role = Interceptor, port = "auth.verify", ordinal = 0)
setAttribute("chat.timeline", Retention, expect = 7.days, to = 30.days)
}
Listing 4.
A patch as data (proposed API).
~ Session chat.api + interceptor auth.verify @0 risk medium
~ Channel chat.timeline retention 7d -> 30d risk low
impact 2 scopes; claim timeline.retention-budget is stale
merge commutes with 3 open proposals; conflicts with none
Listing 5.
The graph diff of Listing 4, as a reviewer sees it.
Each scope has one edit owner. For a source-owned scope, elaboration is a function from a source revision to a graph patch. The graph diff of a commit is then , computed in CI and reviewed instead of the text. For a graph-owned scope (Blueprint behaviour, deployment, data schema, policy), the patch is primary and source is generated. Edits from both sides must satisfy the lens laws on the supported subset [138]. Moving ownership between the two is an explicit migration patch. This is how graph diffs replace git diffs: version control stores and transports bodies, while review, merge, impact analysis and evidence invalidation work on patches. As agents write more of the code and people read less of it, the patch becomes the artefact that people review.
9.5 Code push as a region release#
A region is a scope selected for replacement. Its compatibility closure is the least fixpoint where adds four kinds of element that must change with : elements joined to by a Bind or a or incidence without an adapter, since in-process references do not cross a version boundary; participants of sessions whose global type changes; datasets whose schema changes, with their accessors, unless a migration preserves compatibility; and regions fused with into one compiled artefact. is monotone, so is computed by a traversal (Theorem 6). This generalises the closure bound of Reaktor’s engine preprint [288] to hyperedges: a multi-party session cannot be split by a cut without its relation identity. In Figure 2 the region social-ui is closed in this sense. Its binds leave it only through FFI adapters whose contracts the installed app binary fixes; it calls no session and owns no dataset; and it compiles to its own bytecode. It therefore ships without a store release.
A release is an Artifact containing:
base and candidate digests, and the definition patch;
the code artefacts: Kotlin/JS compiled to Hermes bytecode for a pinned engine version;
the exported contract fingerprints, and the capability manifest of host imports;
the effect ceiling, the state migration with its pre- and postconditions, the activation mode and the rollback class;
claims with evidence, and a signature with update-framework metadata [305].
A host admits a release when all of the following hold: the bytes are trusted; the host profile (Section 13.1) is compatible; the boundary contracts are compatible; the required capabilities are available; the effect ceiling lies within a grant; the state plan is valid; the evidence is fresh for the candidate digest; and the distribution policy permits the release. The last condition is decided by platform rules, not by the graph [19]. The host prepares the image privately and publishes it by switching one local root. In next-entry mode, new invocations use the new image and old ones finish on the old. In drain-and-swap mode, the host stops admission, drains, migrates and resumes. Callbacks and handles of a retired generation are rejected or routed to the pinned generation. Writes are fenced by epoch at the owning authority. Rollback is a new forward release under a new epoch; a release with a non-invertible migration declares that rollback is unsafe. Dynamic software updating [170], version consistency [262] and Erlang release handling [129] are the precedents. Corollary 5 states the semantic condition on the boundary, the bounded models below check the two protocols this activation relies on, and Listing 6 specifies the activation itself. Figure 16 summarises the sequence.
Figure 16. Code push as a region release (Section 9.5). The closure is a least fixpoint computed by a traversal. Admission is decided on each host, and activation switches one local root, in one of two modes. Writes from a retired generation are refused at the owning authority by epoch.
Release in TLA#
Listing 6 specifies next-entry activation. A call binds to the generation that is active when it enters, and it may leave a deferred callback that outlives it. A release activates the next generation. Retiring the oldest generation fences its epoch at the owning authority, and with draining it waits for that generation’s calls. Two invariants state what code push must never do: accept a write from a retired generation, or refuse the write of a call that was admitted. TLC checks three generations and three calls. With fencing and draining, both invariants hold over 3,858 states. Without the fence, a callback of a retired generation writes after six steps; without draining, an admitted call’s write is refused after four (Table 34).
---------------------------- MODULE RegionRelease ----------------------------
EXTENDS Naturals
CONSTANTS MaxGen, MaxCalls, Fence, Drain
VARIABLES active, retired, fence, calls, deferred, writes, entered
vars == <<active, retired, fence, calls, deferred, writes, entered>>
Init ==
/\ active = 1
/\ retired = {}
/\ fence = 0
/\ calls = {}
/\ deferred = {}
/\ writes = {}
/\ entered = 0
Write(g, kind) ==
[gen |-> g, kind |-> kind, accepted |-> g >= fence, retiredGen |-> g \in retired]
Enter ==
/\ entered < MaxCalls
/\ calls' = calls \cup {[id |-> entered, gen |-> active]}
/\ entered' = entered + 1
/\ UNCHANGED <<active, retired, fence, deferred, writes>>
Defer(c) ==
/\ c \notin deferred
/\ deferred' = deferred \cup {c}
/\ UNCHANGED <<active, retired, fence, calls, writes, entered>>
Finish(c) ==
/\ calls' = calls \ {c}
/\ writes' = writes \cup {Write(c.gen, "call")}
/\ UNCHANGED <<active, retired, fence, deferred, entered>>
Fire(d) ==
/\ d \notin calls
/\ deferred' = deferred \ {d}
/\ writes' = writes \cup {Write(d.gen, "callback")}
/\ UNCHANGED <<active, retired, fence, calls, entered>>
Release ==
/\ active < MaxGen
/\ active' = active + 1
/\ UNCHANGED <<retired, fence, calls, deferred, writes, entered>>
Retire(g) ==
/\ g < active
/\ g \notin retired
/\ \A h \in 1..(g - 1) : h \in retired
/\ Drain => \A c \in calls : c.gen # g
/\ retired' = retired \cup {g}
/\ fence' = IF Fence THEN g + 1 ELSE fence
/\ UNCHANGED <<active, calls, deferred, writes, entered>>
Next ==
\/ Enter
\/ \E c \in calls : Defer(c) \/ Finish(c)
\/ \E d \in deferred : Fire(d)
\/ Release
\/ \E g \in 1..MaxGen : Retire(g)
Spec == Init /\ [][Next]_vars
NoWriteFromRetired == \A w \in writes : w.accepted => ~w.retiredGen
NoLostCallWrite == \A w \in writes : w.kind = "call" => w.accepted
=============================================================================
Listing 6.
Region release with next-entry activation, in TLA (anc/RegionRelease.tla).
| Model | Bound | States | Trans. | Result |
|---|---|---|---|---|
| Handover, no fencing | owners, 1 write each, 1 handover | 12 | 13 | violated: send(A,1); handover(AB,2); accept(A,1) |
| Handover, fenced at authority | same | 15 | 19 | holds |
| Handover, sender checks its lease | same | 17 | 20 | violated (same 3 steps) |
| Handover, no fencing | owners, 2 writes, 2 handovers | 32 | 39 | violated (same 3 steps) |
| Handover, fenced at authority | owners, 2 writes, 2 handovers | 379 | 812 | holds |
| Handover, sender checks its lease | owners, 2 writes, 2 handovers | 40 | 51 | violated (same 3 steps) |
| Handover, fenced at authority | owners, 2 writes, 3 handovers | 4 555 | 13 928 | holds |
| Effect, no deduplication | effect, 3 attempts, loss, 1 duplicate | 23 | 27 | violated: applied twice in 4 steps |
| Effect, deduplicated by effect id, timeout read as UNKNOWN | same | 87 | 268 | holds |
| Effect, timeout read as NOT_APPLIED | same, deduplicated | 83 | 248 | violated: client concludes “not applied” after commit |