gunk-dev/the-valley

integration.md

source181cd0391ab6main's published tip history
16.5 KiB · Rendered
1# Integration
2
3How a change lands. The position this implements is
4[dcr-439b771](../.the-valley/decisions/dcr-439b771-integration-occ-over-content-addressed-evidence.md):
5integration is optimistic concurrency control over content-addressed evidence. This document is the
6detailed design — the request's shape, the rules in the order they are applied, what the integrator
7writes down, and what it publishes. The bet behind it is
8[architecture.md](./architecture.md#bet-a-pull-based-integrator-not-a-pre-receive-gate)'s pull-based
9integrator, and the failure mode is staleness.
10
11The integrator runs no check. Verification happens where a change is authored
12([verification.md](./verification.md)), and the serialized section at the commit point is digest
13comparison and a ref write.
14
15## A request is a ref
16
17A contributor asks for integration by pushing one ref:
18
19```
20refs/the-valley/integration-requests/<target>/<change> -> commit
21```
22
23The target segment names the protected branch, so the stream is `refs/heads/<target>`; the last
24segment names the change. The commit is the change's head. Its tree is what the attestations were
25produced over, and the delta is the merge base with the target's tip up to that head. Nothing else
26is encoded, because nothing else has to be: a change is a diff targeting a stream
27([ida-93e4f91](../.the-valley/ideas/ida-93e4f91-changes-not-branches.md)), and every part of that is
28already in git.
29
30Who may push that ref is a grant. The pre-receive hook takes writes to the namespace only from a
31principal holding request
32([dcr-e544f20](../.the-valley/decisions/dcr-e544f20-access-is-verbs-on-projects.md)). Who holds it,
33together with which path classes demand approval statements, decides how much lands without a
34person. Among the holders, asking is authorship's final step. The author may be a person, an agent
35run, or tooling acting for either; an operator filing a request by hand is the transitional case,
36not the design. Where a person's judgment is required, it arrives as a signed statement among the
37change's evidence
38([ida-b7025b5](../.the-valley/ideas/ida-b7025b5-human-decisions-are-signed-acts.md)), never as the
39act of asking.
40
41This settles what [contribute.md](./contribute.md) left open at its step 7. The attestations
42themselves arrive the way that document already describes, at
43`refs/the-valley/attestations/<tree digest>/<signer key hash>`, and the integrator finds them by
44digesting the request's tree.
45
46## The controller polls, deliberately
47
48The integrator is a reconciliation loop over those refs. Each pass lists the pending requests,
49judges each against the current tip of its target, and acts where the answer has changed since the
50last pass. It subscribes to nothing.
51
52That is not a shortcut around the event bus; it is what the bus's own contract says to do. The bus
53is unauthenticated ([bd-d853d9c](../.the-valley/bugs/bd-d853d9c-bus-unauthenticated.md)), and that
54bug's gate is exactly "before any automated consumer acts on an event". And per
55[architecture.md](./architecture.md#bet-git-as-event-source--a-log-not-a-workflow-engine) the
56requests are durable in git with the bus as a projection over them, so level-triggering on the
57durable state is the converging shape and a subscription would be the lossy one. Consuming events
58arrives in a later phase, and the integrator does not become a different program when it does.
59
60Its memory of what it last decided is durable in git too, at
61`refs/the-valley/integration-outcomes/<target>/<change>`: the request's head, the tip it was judged
62against, a digest of the attestation namespace, and the outcome. Those are the three things a
63verdict is a function of, so a judgement is re-announced when one of them moves and not otherwise.
64That is what keeps a level-triggered loop from being a retry storm, and it is why evidence pushed
65after a no-evidence verdict is judged again rather than stranded. The digest covers the whole
66namespace rather than one change's subject, so an attestation for any change re-judges every pending
67request — the conservative direction, and bounded by how many are pending.
68
69Anyone with push access can write the request namespace, so a ref in it that is not a request is an
70ordinary thing to find. It is reported and skipped. One unreadable ref does not hold up the readable
71ones beside it.
72
73## The commit rule
74
75Applied in this order. The whole of it is a function of data, so it is stated once in
76`integrator/verdict.go` and exercised without a repository by the `integrator-unit` check.
77
78**1. The delta must apply cleanly to the tip.** A three-way merge of the tip and the head against
79the base the delta was authored against, with no working tree. A conflict means resolving it would
80produce a tree nobody has authored; that resolution is new authorship, and new authorship needs new
81evidence. So a conflict is stale with **every** required check named: retry is not partial from a
82tree nobody wrote.
83
84**2. The required checks come from the policy at the target tip.** The deriver of
85[dcr-f41f718](../.the-valley/decisions/dcr-f41f718-declared-verification-policy.md) —
86`valley checks` — matches the diff against the composed classes. Both layers are read from the
87integrator's own side: the project layer from a checkout of the target tip, the instance layer from
88where the integrator is configured to find it. A change never supplies the policy that gates it.
89
90Which rule governs a check is the policy's, never the attestation's. The policy names the runner,
91and the runner is what makes a check pure or effectful; a statement whose predicate type contradicts
92it is refused rather than judged by the rule it nominated for itself. Where a subject carries
93several attestations for one check — one per signer — the first admissible one is the evidence, and
94a note that does not verify is not displaced by a good one found after it. A check refused that way
95ends the judgement: the change is not behind, and redoing work would not change the answer.
96
97**3. A pure check transfers by closure-digest equality.** The integrator recomputes the check's
98input-closure digest over the tree that would land — `attest inputs`, which evaluates and digests
99and builds nothing — and compares it with the digest the attestation recorded. Equality means the
100landed tree presents the same computation over the same inputs, so the recorded result is the result
101on the new base too. Inequality means that check, and only that check, is stale. When the landed
102tree is the attested tree there is nothing to compare and the evidence stands by construction.
103
104**4. An effectful check transfers while its scope is untouched and its observation is fresh.** Both
105must hold: no intervening landed change touched the paths of a class that requires the check, and
106the observation is younger than the validity window Δ the policy declares for it. The first is asked
107of the deriver rather than matched here — the classes it reports over the intervening range are
108exactly the classes those landings touched. Absent a declared window the check is re-demanded: a
109window nobody wrote down is not a window a tool may invent.
110
111**5. Everything standing lands.** The protected ref is fast-forwarded by a compare-and-swap against
112the tip the verdict was computed over, so a request that lost a race lands nothing and is judged
113again next pass against the tip that won. That local ref write is the integrator's own privilege,
114and the structural invariant on the bare repo is what makes it the only one.
115
116That ref write is the commit point, and the order around it follows from that. Everything that can
117fail while the integrator is still deciding happens before it — including composing the transfer
118statement, because a claim it cannot write down is a claim it has not made, and a stream moved on a
119decision that cannot be stated is a landing nothing records. A failure there leaves the stream and
120the request exactly where they were, which is a transaction abandoned before it committed. Past the
121commit point the landing is a fact, and what is left is recording it: storing the evidence,
122consuming the request ref, and publishing. Each of those runs whatever the ones before it did, and a
123failure in any of them is reported against a landing that has already happened. In particular the
124request ref is consumed even then, because a request left pending for a change already in the stream
125is re-judged against an empty delta on every pass.
126
127The request ref is consumed only if it still names the head that landed. A resubmission can replace
128it while the pass works, since the asker reads the request before leasing its write against it. A
129request that moved is a new request, and it stands for the next pass.
130
131**A pass that cannot act on its own verdict records that it could not.** The level-trigger's memo is
132what keeps the controller from re-announcing an unchanged answer, and a failure is an answer of that
133kind: the same request, tip and evidence produce the same failure, so retrying at tick rate is a
134report repeated until it is worthless. The memo therefore records the failure and the instant, and
135the request is taken up again when any of the three moves or when a few minutes have passed —
136whichever comes first. The second half is for the failures that come from outside those three, a bus
137or a disk or a lock, which will be different later.
138
139**6. Anything invalidated is one `request-stale` naming exactly those checks.** The request ref is
140not consumed, so the answer to a stale verdict is to resubmit. Resubmission takes one of two shapes,
141and which one applies follows from why the evidence stopped standing.
142
143**The evidence expired.** An effectful check's observation aged past the validity window the policy
144declares for it, and nothing about the tree changed. Re-running that check over the same head
145produces a fresh observation. The request ref already names that head, so it does not move, and the
146resubmission is the new attestations alone. Publishing them is where this shape currently stops: the
147attestation namespace is create-only, so a second statement about a tree one signer has already
148attested has nowhere to go
149([bd-7b7d58f](../.the-valley/bugs/bd-7b7d58f-same-tree-re-attestation-cannot-be-published.md)).
150
151**The evidence no longer transfers.** A pure check's input closure changed, because the target moved
152through the paths that closure covers. No attestation over the submitted tree can transfer again:
153the tree that would land is not the tree that was attested, and re-running the check over the same
154head would recompute the same digest and hit the same mismatch. The only cure is a new head, rebased
155onto the moved target and attested there. That head is not a descendant of the one the request ref
156holds, so writing it replaces the ref rather than advancing it.
157
158Replacing it is legal where it happens. The request namespace is writable by anyone with push
159access, and the integrator judges whatever the ref points at on the pass after it moves. What
160replacement does need is a compare-and-swap. Two resubmissions of one change are two heads racing
161for one ref, and the loser has to lose visibly rather than quietly overwrite the winner. So the
162ref's current value is read before the push, and the push is leased against exactly that value.
163
164Reading that the ref is absent is a value like any other, and the lease covers it too — git spells
165the expectation with an empty value and refuses if the ref exists at all. So the first filing of a
166change is a compare-and-swap on the same terms as a replacement. Without it, two operators filing
167one change at once would have the second silently fast-forward the first away, which is the same
168loss the replacement case takes care to avoid.
169
170The refspec carries no `+`: a forced refspec defeats every rejection the push rules produce,
171including the lease's own, so the two together are a plain overwrite wearing a lease's name. A push
172whose lease refuses publishes nothing. What refused it is one of three things — another resubmission
173won, the integrator landed the change and consumed the ref, or the ref was never where the reader
174thought — and they are told apart by reading the ref again rather than reported as one.
175
176## What the integrator writes down
177
178Two statements, side by side in one attestation ref per subject.
179
180The contributor's original notes gain the integrator's signature as **sibling lines under the text
181they already carry** — several parties attesting to one statement, which is the composition
182[dcr-0de694f](../.the-valley/decisions/dcr-0de694f-phase2-attestation-shape.md) already provides.
183Nothing about the contributor's statement changes; it stays about the tree it was made over, and it
184stays at a ref keyed by that tree's digest.
185
186The **transfer statement** is the integrator's own claim, and it is a separate statement because it
187is about a different tree: the one that landed. Its predicate type is
188`the-valley/integration/transfer/v1`, and it records the change, the target stream, the base the
189evidence was produced over, the policy the verdict was derived under, and the per-check verdicts —
190each citing the statement it is about by a digest of the bytes that statement's signature covers. A
191policy that required nothing of the change writes `predicate.required none` in place of the
192verdicts, which is the same claim with an empty answer rather than a different kind of claim. The
193policy it names is the one the integrator composed from its own checkout at the target tip, never
194the submitted tree, which is the direction
195[bd-eaefe82](../.the-valley/bugs/bd-eaefe82-check-definitions-come-from-the-branch.md) points at.
196
197When nothing intervened the two trees are the same tree and both notes sit under one ref. When the
198delta landed on a moved tip they are two refs, each keyed by the tree its statement is about.
199
200## What it publishes
201
202Two events, in [schema/events.cue](../schema/events.cue), on
203`valley.git.<repo>.integration-succeeded` and `valley.git.<repo>.request-stale`. The mechanism is
204the post-receive hook's, exactly: one `nats pub`, best-effort, never fatal — git is the source of
205truth and the bus is the replaceable component.
206
207**There is no rejection event, on purpose.** A note whose signature does not check out, text that is
208not the written form of what it says, or a statement about a different tree is not staleness:
209re-attesting would not fix it, and calling it stale would tell a contributor to redo work that is
210not the problem. Rather than stretch either event to cover a case they do not describe, the
211vocabulary stays as it is and a refusal is the integrator's own output. Naming that case is a
212decision this build deliberately does not take alone.
213
214## Identity, for now
215
216The integrator signs with a key given by configuration, and accepts attestations from the signers in
217a known-signers file — one verifier key per line, the format
218[dcr-de9d996](../.the-valley/decisions/dcr-de9d996-statement-text-and-signed-note.md) fixes.
219
220That file is the registry's interim compilation. Identity is a governed registry
221([dcr-b87f6e8](../.the-valley/decisions/dcr-b87f6e8-identity-is-a-governed-registry.md)) whose
222entries compile into what each enforcement boundary checks, and no compiler exists yet, so the
223compiled artifact is supplied directly. Nothing here parses a registry, and nothing should start to
224until that decision's first compiler ships.
225
226An attestation signed by nobody in the file does not transfer, and that is reported per check rather
227than treated as a forgery. What to do about an unknown attester — re-verification, trust
228measurement, a threshold — belongs to [Phase 6](./roadmap.md#phase-6--trust-backstop) and is
229deliberately absent.
230
231## What is deliberately absent
232
233- **Bus consumption.** Above.
234- **Batching, reservations, sharding.** The known knobs for queue semantics under contention
235 ([dcr-439b771](../.the-valley/decisions/dcr-439b771-integration-occ-over-content-addressed-evidence.md),
236 _Open_). None is designed, and the verdict stays per-change so none is precluded.
237- **Trust thresholds and re-verification.** Above.
238- **Self-integration.** The integrator is code in a repo; how its own changes land is open where it
239 already is ([openquestions.md](./openquestions.md)).
240- **Any transport but refs.** The verdict is a function of a change, a snapshot and the known
241 signers, with no git, nix or clock inside it, so a second transport supplies those three and
242 reuses the rule unchanged.
243- **Check definitions from the instance's pin.** The policy comes from the integrator's side; the
244 check derivations still come from the tree being gated. That is
245 [bd-eaefe82](../.the-valley/bugs/bd-eaefe82-check-definitions-come-from-the-branch.md), and an
246 enforcement point existing now is what turns it from a structural defect into a live one.