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