| 1 | # Integration |
| 2 | |
| 3 | How a change makes it into `main` (or any protected ref) without a central platform gate. |
| 4 | |
| 5 | ## The choice: gate vs. controller |
| 6 | |
| 7 | The simplest option is a `pre-receive` hook on the bare git repo: every push to a protected branch is intercepted, the hook checks for valid attestations, push is accepted or rejected. This works. |
| 8 | |
| 9 | But it makes integration a different *shape* from the rest of the system. Everything else is "controllers reacting to events on the log." A `pre-receive` hook is a synchronous gate at the git boundary — a special case. And its failure mode is a terse line of stderr to whoever ran `git push`. |
| 10 | |
| 11 | The alternative — and the one this design adopts — is a **pull-based integrator**: a controller subscribing to events, performing integration as a reaction, emitting outcome events back into the log. |
| 12 | |
| 13 | | | Pre-receive gate | Pull-based integrator | |
| 14 | | --- | --- | --- | |
| 15 | | Where policy lives | Hook script on git server | Controller subscribing to events | |
| 16 | | Failure mode | Push error to stderr | Outcome event in log, threadable | |
| 17 | | Multiple policies | Hard (one hook per repo) | Trivial (multiple subscribers) | |
| 18 | | Async validation | No — must answer before push completes | Yes — controller takes its time | |
| 19 | | Re-running on transient failure | Re-push | Re-fire the event | |
| 20 | | Architectural consistency | Special case | Same pattern as everything else | |
| 21 | |
| 22 | ## The minimal invariant |
| 23 | |
| 24 | The bare git repo still needs to prevent *direct* writes to protected refs (`refs/heads/main`, deploy branches, anything authoritative). Otherwise contributors bypass the integrator by pushing directly. |
| 25 | |
| 26 | But the gate this requires is trivial: **only the integrator's key may write protected refs**. Everything else — topic branches, attestation refs, integration request refs — is wide open to anyone with push access. |
| 27 | |
| 28 | That's a one-line pre-receive hook, or just filesystem ACLs on the bare repo. The complex policy lives in the integrator; the git boundary only enforces the one structural invariant. |
| 29 | |
| 30 | ## Mechanism |
| 31 | |
| 32 | ``` |
| 33 | contributor bus integrator |
| 34 | ───────────────────────────────────────────────────────────────────── |
| 35 | push topic + attestations ──► refs updated |
| 36 | ──► integration-requested |
| 37 | │ |
| 38 | ├──► fetch topic + attestations |
| 39 | ├──► verify signatures, attestations |
| 40 | ├──► check trust score |
| 41 | ├──► await witness confirmation (if policy) |
| 42 | ├──► check conflicts with main |
| 43 | ├──► integrate (FF / rebase / merge) |
| 44 | └──► emit outcome |
| 45 | ◄── integration-succeeded / -failed |
| 46 | ``` |
| 47 | |
| 48 | Steps in more detail: |
| 49 | |
| 50 | 1. **Contributor pushes.** Topic branch, attestation refs, anything else relevant — pushed atomically to the bare repo. No protected refs are touched. The push always succeeds at the git layer as long as the contributor has push rights. |
| 51 | 2. **Contributor signals intent to integrate.** Three reasonable options: |
| 52 | - **Bus event** — `integration-requested { repo, branch, attestations, target }`. Most consistent with the rest of the architecture. Canonical mechanism. |
| 53 | - **Request ref** — push `refs/integration-requests/<name>` alongside the topic branch. Atomic with the push, observable via git, can be queued/dequeued by deleting the ref. |
| 54 | - **Branch naming convention** — `integrate/<name>`. UX shorthand only. Tooling translates this into one of the above when the contributor runs `git push --integrate`. |
| 55 | The system probably wants the bus event as the canonical signal, with the request ref as a durable backup that can be replayed if the bus is rebuilt. |
| 56 | 3. **Integrator reacts.** Subscribes to `integration-requested` events for repos it owns. Fetches the topic branch and attestations. |
| 57 | 4. **Verification.** Runs whatever policy this integrator implements: |
| 58 | - Verify signatures on the attestations. |
| 59 | - Validate attestation contents — derivation hashes, claimed checks, signer. |
| 60 | - Check the signer's current trust score. |
| 61 | - Optionally wait for or fetch witness re-derivation results. |
| 62 | - Check the topic branch merges cleanly into the current target. |
| 63 | 5. **Integration.** Whatever strategy this integrator implements — fast-forward only, rebase-then-FF, merge commit, squash. The integrator is the only entity with permission to write the target ref; the bare repo enforces this. |
| 64 | 6. **Outcome emission.** `integration-succeeded { commit, signer, attestations }` on success, or `request-stale { reason }` when the request cannot progress against current policy. Downstream subscribers (deploy controller, thread view, notification routing) consume the outcome. See [integrator-internals.md](./integrator-internals.md) for the staleness model and the integrator's loop. |
| 65 | |
| 66 | ## Properties this gives you |
| 67 | |
| 68 | - **Merge queue semantics for free.** Multiple requests targeting the same ref get serialized by the integrator. If A is in flight and B arrives, the integrator finishes A, rebases B on the new tip, re-verifies, integrates. Standard queue, no special infrastructure. |
| 69 | - **Multiple integrators are tractable.** Different repos, different branches, different audiences can have different controller instances with different policies. Same event type, different consumer behavior. A fast-forward-only integrator for a deploy branch; a more permissive one for a docs branch; a human-required one for a sensitive path. |
| 70 | - **Bad branches don't pollute protected refs.** A topic with a broken attestation just sits in the repo. The contributor can fix it and re-request, or abandon it. Garbage collection of unintegrated topic branches is a separate housekeeping concern. |
| 71 | - **Failure is observable.** Every integration outcome is an event with full reasoning. Threads for a change accumulate the outcome alongside review comments, build results, deploy status — one chronology, no "merge result hidden in CI logs." |
| 72 | - **Latency is modest and observable.** Push completes in milliseconds; integration follows within seconds. Tooling subscribes to outcome events; humans need not wait staring at a terminal. |
| 73 | |
| 74 | ## Failure modes worth naming |
| 75 | |
| 76 | - **Integrator crash or backlog.** Requests pile up. The bus is durable, so nothing is lost, but contributors see delayed integration. Need an "integrator alive" health event and visibility into queue depth. |
| 77 | - **Conflict with concurrent integration.** Two contributors targeting the same area. The integrator processes serially; the second arrival is a trivial rebase (attestation invariant) if no conflicts, or goes stale if it would change the tree. See [integrator-internals.md](./integrator-internals.md) for the invariance model. |
| 78 | - **Witness disagreement post-integration.** A witness re-derives a pure attestation and the result differs from what the contributor claimed. The change is *already integrated*. The outcome is a `divergence-detected` event, which downstream feeds trust-score recalculation, potential revert events, and a thread for human attention. |
| 79 | - **Compromised contributor key.** Same problem as anywhere — but now bounded by trust score and visible in the log. Trust controller revokes; future requests from that signer require additional gating. |
| 80 | |
| 81 | ## Open questions |
| 82 | |
| 83 | See [openquestions.md](./openquestions.md) — items raised here live under *Workflow patterns*, *Cross-repo coordination*, and *Identity & trust bootstrapping*. The "Signaling" question was resolved by [contribute.md](./contribute.md). |