gunk-dev/the-valley

integration.md

sourcef961a59e125emain's published tip history
11.3 KiB · Rendered
1# Integration
2
3The integrator evaluates a requested change against the current target and governing policy. It
4lands the change when the delta applies and every required check has acceptable evidence that still
5applies to the resulting tree.
6
7The integrator does not run checks. It evaluates their inputs, verifies statements, and compares
8digests. [Verification](./verification.md) defines that evidence. The
9[integration decision](../.the-valley/decisions/dcr-439b771-integration-occ-over-content-addressed-evidence.md)
10describes the approach as optimistic concurrency control: work is prepared independently, then
11validated against the state present when it commits.
12
13## Request refs
14
15A request is a Git ref pointing to the submitted head:
16
17```text
18refs/the-valley/integration-requests/<target>/<change> -> commit
19```
20
21The target identifies `refs/heads/<target>`. The final segment identifies the change. The integrator
22computes the delta from the merge base of the submitted head and the target tip.
23
24The submitted head's tree is the subject of the contributor's attestations. The integrator digests
25that tree and finds its evidence beneath:
26
27```text
28refs/the-valley/attestations/<tree digest>/<signer key hash>
29```
30
31A person, agent, or tool can submit a request under the access granted to it. Requesting integration
32and approving a change are separate acts. Where policy requires human judgment, the intended
33approval is a signed statement about the change, as described in the
34[approval decision](../.the-valley/decisions/dcr-9c75283-substrate-adoption-and-the-core.md).
35
36The ref is the current transport. A
37[change](../.the-valley/ideas/ida-93e4f91-changes-not-branches.md) is conceptually a delta targeting
38a stream, independent of the branch used to carry it.
39
40## Request reconciliation
41
42The current controller polls Git refs. Each pass lists pending requests and evaluates those whose
43recorded inputs have changed. It does not subscribe to the event bus. Requests remain available even
44if event publication fails.
45
46The controller stores its last answer at:
47
48```text
49refs/the-valley/integration-outcomes/<target>/<change>
50```
51
52The stored comparison key contains the request head, the target tip, and a digest of the attestation
53namespace. New evidence therefore triggers reconsideration even when the request head has not moved.
54The digest covers the entire namespace, so evidence for one change may cause other pending requests
55to be reconsidered too.
56
57An unchanged answer is not announced every polling interval. Operational failures are recorded with
58a timestamp and retried after ten minutes, or sooner if one of those inputs changes. Malformed or
59unreadable request refs are reported and skipped so other requests can proceed.
60
61This describes the current retry mechanism. Changes to governing policy or signer state outside
62those three inputs also matter to a decision. Whether they should invalidate the stored answer is a
63remaining [reconciliation question](./openquestions.md#integration-and-evidence).
64
65## Evaluating a request
66
67The rule is implemented as a function of supplied data in
68[integrator/verdict/verdict.go](../integrator/verdict/verdict.go). Repository access, policy
69resolution, input evaluation, and the current time are collected before calling it.
70
71### 1. Apply the delta
72
73The integrator attempts a three-way merge of the target tip and submitted head using their merge
74base. A conflict makes the request stale.
75
76Resolving a conflict creates newly authored content. The contributor must resolve it and produce new
77evidence for every check required of that resolution. The integrator does not invent a resolution
78and reuse evidence for a tree no one checked.
79
80### 2. Derive the required checks
81
82[Policy composition](../.the-valley/decisions/dcr-f41f718-declared-verification-policy.md) selects
83checks from the paths touched by the change. The project layer comes from the target's integrated
84tip. The floor comes from the owning valley's integrated repository. The submitted tree cannot
85supply the policy that admits itself.
86
87The policy's runner selects the transfer rule: `nix` uses the pure rule, and `command` uses the
88effectful rule. An attestation claiming a different kind is rejected.
89
90Reading policy from governing state does not yet secure the check implementation. Check derivations
91still come from the candidate tree. The
92[check-definition bug](../.the-valley/bugs/bd-eaefe82-check-definitions-come-from-the-branch.md)
93tracks this gap.
94
95### 3. Establish admissible evidence
96
97For each required check, the integrator verifies the selected note's text, schema, signatures, and
98subject.
99
100- A passing statement signed by a recognized signer can be considered for transfer.
101- Missing evidence, an unknown signer, or a recorded failure does not establish that the check
102 passed.
103- Invalid signatures, noncanonical text, a wrong subject, or an incompatible predicate are rejection
104 cases.
105
106Unknown signers are reported as evidence that does not transfer. The current integrator does not
107assign them a trust score or arrange independent verification.
108
109Several signers may supply notes for the same check. The intended rule must not allow invalid
110evidence to be hidden by later valid evidence. The current collector's selection behavior needs
111review against that rule; see [open questions](./openquestions.md#integration-and-evidence). Note
112verification itself rejects an invalid signature by a recognized key even when that same note has a
113valid sibling signature.
114
115### 4. Transfer pure evidence
116
117If the resulting tree is the attested tree, acceptable pure evidence applies directly.
118
119If the tree changed, the integrator runs `attest inputs` over the tree that would land. This
120evaluates the check and computes its input and derivation digests without building it. Both must
121equal the values in the attestation.
122
123Equal digests identify the same computation over the same inputs. A mismatch or failure to compute
124them makes that check stale. Other checks whose evidence transfers do not need to be repeated merely
125because this one failed to transfer.
126
127Pure evidence has no age-based expiry in this rule. Whether the material needed for later
128re-verification remains available is a separate retention question.
129
130### 5. Transfer effectful evidence
131
132An effectful observation transfers only when both conditions hold:
133
134- Intervening integrated changes have not touched any path class that requires the check.
135- The observation is younger than the validity window declared in policy.
136
137The policy deriver identifies classes touched between the submitted change's base and the current
138target tip. A missing validity window does not receive an invented default; the check is requested
139again.
140
141This rule permits bounded staleness in an observation of the external world. It does not establish
142that the observed service or environment has remained unchanged.
143
144### 6. Land or report what prevents landing
145
146If all required evidence transfers, the integrator prepares the landing and updates the protected
147ref. If evidence is missing or stale, it leaves the request pending and reports the affected checks.
148A signature or statement rejection is reported as such rather than disguised as a request to rerun
149ordinary checks.
150
151A request requiring no checks can also land. The record explicitly states that no checks were
152required.
153
154## The ref update and its consequences
155
156The protected-ref write is the commit point. It uses compare-and-swap against the tip used for the
157decision. If another write won the race, nothing from this attempt lands and the request must be
158evaluated against the new tip.
159
160Before that write, the integrator composes, validates, and signs the transfer statement and prepares
161the evidence it will store. A failure during preparation leaves the target and request unchanged.
162
163After the ref moves, the landing has happened. The integrator then attempts each remaining step:
164
1651. Store the evidence.
1662. Delete the consumed request ref.
1673. Publish the landing event.
168
169A failure in one step does not skip the later steps. In particular, the controller attempts to
170consume the request even if storing evidence fails. Otherwise an already landed change could remain
171pending and be repeatedly evaluated as an empty delta.
172
173These writes are not one atomic transaction. A post-landing storage or deletion failure is reported
174as an incompletely recorded landing. Event publication is best-effort. Recovery must distinguish
175these cases from a change that never landed.
176
177## Evidence recorded at landing
178
179The integrator records two kinds of statement.
180
181The contributor's accepted notes gain the integrator's signature under their existing text. Their
182subject remains the originally checked tree. The original signatures are preserved.
183
184A separate **transfer statement** describes the integrator's own decision about the landed tree. Its
185predicate type is `the-valley/integration/transfer/v1`. It records:
186
187- The change and target ref.
188- The originally attested tree.
189- The composed policy digest and the target tip used for the decision.
190- Each required check's transfer rule and the digest of the statement text it relies on.
191
192If no checks were required, it records `predicate.required none` instead of a checks array.
193[Verification](./verification.md#line-order) defines the exact field order.
194
195When the original and landed trees match, their notes can be stored under the same subject. When
196they differ, each statement remains stored under the digest of the tree it describes. The transfer
197statement connects them.
198
199## Published outcomes
200
201[schema/events.cue](../schema/events.cue) defines the two currently published outcomes:
202
203| Subject | Meaning |
204| ----------------------------------------- | ---------------------------------------------------------------------- |
205| `valley.git.<repo>.integration-succeeded` | The protected ref was updated |
206| `valley.git.<repo>.request-stale` | The request needs conflict resolution or evidence for the named checks |
207
208Publication uses the same best-effort mechanism as ref-update projection. Bus failure does not undo
209a landing.
210
211There is currently no rejection event. Invalid evidence is reported through the integrator's output,
212and the outcome is remembered in Git. Adding a distinct event remains a design decision; the absence
213of that event does not mean the integrator has no rejection case.
214
215## Identity and remaining work
216
217The integrator signs with its configured key and verifies attestations against a known-signers file.
218The [identity registry](../.the-valley/decisions/dcr-b87f6e8-identity-is-a-governed-registry.md) now
219has a compiler that produces verifier and access artifacts from accepted governing state. The
220integrator consumes those artifacts rather than parsing the registry itself.
221
222The current design still needs trusted sources for mandated check definitions, verified delegation
223and physical approval, and a trust process for unknown signers. It also needs a complete procedure
224for changes to the integrator and its governing policy.
225
226Contention policy, batching, reservations, and sharding remain open. Bus events may later wake the
227reconciliation loop, but event consumption requires the
228[bus authorization work](../.the-valley/bugs/bd-d853d9c-bus-unauthenticated.md). Other request
229transports could reuse the verdict function by supplying the same change and snapshot data.