| 1 | # Scenarios |
| 2 | |
| 3 | End-to-end walk-throughs of how the architecture handles real situations. Forces the design to be honest, and surfaces gaps that the abstract docs miss. |
| 4 | |
| 5 | Conventions used in the flows below: |
| 6 | |
| 7 | - `▶` is a contributor or external actor doing something. |
| 8 | - `→` is an event landing on the bus. |
| 9 | - `↺` is a controller reacting to an event. |
| 10 | - `✓` / `✗` is an integration outcome. |
| 11 | |
| 12 | --- |
| 13 | |
| 14 | ## 1. Solo dev: edit → integrate → deploy |
| 15 | |
| 16 | The everyday case. A human edits code, runs local checks, and ships a change. |
| 17 | |
| 18 | ``` |
| 19 | ▶ edit, save |
| 20 | ▶ git push --integrate topic/x (atomic: refs/heads/topic/x + refs/attestations/<sha>) |
| 21 | → ref-updated topic/x, <sha> |
| 22 | → integration-requested { repo, branch=topic/x, target=main, attestations=[A1, A2] } |
| 23 | ↺ integrator verify signature, attestation contents, signer trust score |
| 24 | ↺ integrator topic/x merges cleanly into main, fast-forward |
| 25 | ✓ → integration-succeeded { commit=<sha>, target=main } |
| 26 | ↺ deploy controller build artifact derivation D from <sha> |
| 27 | → derivation-built { commit, D, hash } |
| 28 | ↺ deploy controller deploy D to staging |
| 29 | → deployed { commit, env=staging, D } |
| 30 | ↺ witness re-derive A1's pure check |
| 31 | → attestation-confirmed { commit, attestation=A1 } |
| 32 | ↺ trust controller bump signer's confirm rate |
| 33 | ``` |
| 34 | |
| 35 | **Latency observed by the developer:** `git push` returns immediately. Integration outcome lands within seconds. Deploy completes within minutes. Witness confirmation arrives async — the dev never waits on it. |
| 36 | |
| 37 | **Stress points:** |
| 38 | |
| 39 | - The integrator policy must decide whether to wait for witness confirmation before integrating. For a trusted, well-attested signer: probably not. For a new signer: probably yes. This is policy, not architecture, but the policy needs to exist. |
| 40 | - The "local checks are sufficient" assumption is load-bearing. If the contributor's environment drifts from canonical (different Nix version, host-specific paths bleeding in), attestations will land but witnesses will reject them. This is a *bug* in the contributor's setup, surfaced as trust-score drift — the system should make this debuggable. |
| 41 | |
| 42 | --- |
| 43 | |
| 44 | ## 2. klaus-style agent change |
| 45 | |
| 46 | An agent dispatched by klaus does the work. Same flow as a human, but identity and trust live in different places. |
| 47 | |
| 48 | ``` |
| 49 | ▶ klaus launch "fix the auth bug ..." |
| 50 | → agent-dispatched { run_id, repo, prompt, agent_key=<key> } |
| 51 | ↺ agent (in worktree) edits, runs local checks, signs attestation with agent_key |
| 52 | ▶ agent push --integrate |
| 53 | → integration-requested { repo, branch, attestations, signer=agent_key } |
| 54 | ↺ integrator verify signature, look up agent_key trust policy |
| 55 | ↺ integrator policy says "agent changes auto-integrate if attestations re-derive cleanly OR a witness pre-confirms" |
| 56 | ↺ integrator either: (a) wait for witness confirm event, or (b) integrate now and accept the risk |
| 57 | ✓ → integration-succeeded ... |
| 58 | ``` |
| 59 | |
| 60 | **Stress points:** |
| 61 | |
| 62 | - **Agent identity.** What key signs the attestation? Three plausible models: |
| 63 | - *Ephemeral per-run key* — klaus mints a key, signs it with klaus's own root, key is bound to one run. Strong audit trail, key compromise is bounded. |
| 64 | - *Long-lived per-agent key* — one key per agent type. Simpler. Compromise has wider blast radius but is easy to revoke at the trust controller. |
| 65 | - *Delegated from dispatcher* — the dispatching human's key authorizes the agent; the agent signs with a derived key. Aligns trust with the human responsible. |
| 66 | This is an unresolved design question. The architecture supports any of them — the trust controller doesn't care about key shape, only about confirm/deny rates per signer. |
| 67 | - **Klaus's own events** (agent-completed, pr-created in the current klaus design) become first-class on the bus. The "PR" concept dissolves — what klaus today calls "PR created" is just `integration-requested` with the agent as signer. |
| 68 | - **Agent loops.** An agent reacting to a regression event (Scenario 3) dispatches another agent run. Easy to imagine pathological loops; the architecture needs a cap (klaus's existing run-budget mechanism extends naturally). |
| 69 | |
| 70 | --- |
| 71 | |
| 72 | ## 3. Post-deploy regression |
| 73 | |
| 74 | A change makes it to production. Some time later, runtime signals indicate something is wrong. The system closes the loop back to the change. |
| 75 | |
| 76 | ``` |
| 77 | ↺ monitoring error rate on /api/foo crosses threshold |
| 78 | → regression-suspected { service, indicator, severity, observed_at, attributed_commits=[<sha-1>, <sha-2>, <sha-3>] } |
| 79 | ↺ rollback controller policy: severity >= P1 AND attributed deploy < 30min ago |
| 80 | ↺ rollback controller revert to previous artifact |
| 81 | → deployed { commit=<previous-sha>, env=prod, reason=rollback, evidence=regression-suspected } |
| 82 | ↺ thread router open/update threads for each attributed commit |
| 83 | → thread-event { thread, kind=regression-attributed, evidence } |
| 84 | ↺ priority router thread now has high-severity event; promote to human attention |
| 85 | ↺ agent dispatcher spawn klaus run: "investigate regression Z, propose fix" |
| 86 | → agent-dispatched ... |
| 87 | ``` |
| 88 | |
| 89 | **Stress points:** |
| 90 | |
| 91 | - **Attribution.** Monitoring rarely *knows* which commit caused a regression. The honest fields here are *attributed_commits* (a window or best-guess) and a confidence. Probably: most recent N deploys in the window where the metric degraded. The thread router and the dispatched agent both treat this as a lead, not a verdict. |
| 92 | - **Auto-rollback vs human-in-the-loop.** Different orgs/repos want different thresholds. This is per-environment policy, not architecture — but the policy needs to be expressible and observable. The rollback controller's decision logic should itself emit its reasoning as events. |
| 93 | - **Trust score implications.** A regression in itself doesn't lower the signer's trust score (regressions ≠ attestation forgery). But a *correlation* — "this signer's changes account for a disproportionate share of regressions" — is interesting. Probably a separate signal from witness divergence, surfaced to humans rather than auto-acted. |
| 94 | - **Closing the loop on the thread.** When the regression is fixed (a follow-up commit, an explicit revert), the thread can mark itself resolved. The "did this thing actually get fixed" event is necessary for the system to know what to forget. |
| 95 | |
| 96 | --- |
| 97 | |
| 98 | ## 5. Untrusted contributor |
| 99 | |
| 100 | A new contributor wants to land a change. They have no attestation history, so the trust controller has no signal on them. |
| 101 | |
| 102 | ``` |
| 103 | ▶ alice (new) git push --integrate topic/welcome-fix |
| 104 | → integration-requested { signer=alice, attestations, ... } |
| 105 | ↺ integrator alice has no trust score, policy says "do not auto-integrate" |
| 106 | ↺ integrator create a thread, surface the request as needing review |
| 107 | → thread-event { thread, kind=integration-pending, signer=alice } |
| 108 | ↺ priority router surfaces thread to maintainer attention |
| 109 | ▶ maintainer reviews diff in the thread view |
| 110 | ▶ maintainer approves (signed approval event) |
| 111 | → approval { thread, by=maintainer, target=alice's integration-request } |
| 112 | ↺ integrator sees approval from someone with integration-approval authority; integrates |
| 113 | ✓ → integration-succeeded { signer=alice, approved_by=maintainer } |
| 114 | ↺ trust controller alice now has 1 successful integration co-signed by a trusted party |
| 115 | (policy: after N co-signed integrations, alice's attestations can auto-integrate) |
| 116 | ``` |
| 117 | |
| 118 | **Stress points:** |
| 119 | |
| 120 | - **The trust state machine.** "Co-signed by trusted party" → "trusted enough to auto-integrate" is a discrete transition that needs clear policy. How many? Which kinds of changes count? Does trust decay with inactivity? Should the contributor see their own trust state? All policy questions, not architecture. |
| 121 | - **Threads as the coordination focal point.** This scenario is the most thread-centric — review happens *in* the thread, which subsumes what GitHub calls a PR. The thread holds the request, the diff view, the attestations, the maintainer's comments, the approval event, and the eventual integration outcome. Every event is part of the same chronology. |
| 122 | - **The "approval has authority" claim.** The integrator trusts the maintainer's approval because the maintainer's key is on a known list. That list is itself a piece of policy that needs versioning, audit, and a way to grant/revoke. Probably stored as a signed config event on the bus, not a YAML file in a repo. |
| 123 | - **Sybil concerns.** The trust model is permissive by default — anyone can push a topic branch and request integration. That's fine for invite-only / personal use. For public projects, the request-rate and the priority router need to handle spam. Probably out of scope for the first cut, worth naming. |
| 124 | |
| 125 | --- |
| 126 | |
| 127 | ## 4. Cross-repo schema change (sketch) |
| 128 | |
| 129 | armstrong's CUE schema changes. Multiple downstream repos depend on it. |
| 130 | |
| 131 | ``` |
| 132 | ✓ integration-succeeded { repo=armstrong, schema-updated=yes, prev_hash, new_hash } |
| 133 | ↺ schema-watcher (in each consumer repo) notices a dependency's schema changed |
| 134 | ↺ schema-watcher runs validation: does my current usage compile against the new schema? |
| 135 | → schema-compatibility { consumer, schema, status=ok|broken } |
| 136 | ↺ schema-rollout coordinator (if present) aggregates compatibility events |
| 137 | ↺ schema-rollout coordinator if all known consumers ok: cut a versioned release of the schema |
| 138 | ↺ schema-rollout coordinator if some broken: open threads in those repos with a fix-suggestion |
| 139 | ``` |
| 140 | |
| 141 | **What this tests:** that events flow across repo boundaries on the same bus, that controllers can be scoped per-repo but consume cross-repo events. |
| 142 | |
| 143 | **Open:** how does a consumer *declare* its interest in another repo's events? Per-repo subscription config? Discovery via schema metadata? Probably explicit config — implicit discovery is too magical. |
| 144 | |
| 145 | --- |
| 146 | |
| 147 | ## 6. Scheduled task (sketch) |
| 148 | |
| 149 | A weekly dependency bump. |
| 150 | |
| 151 | ``` |
| 152 | ↺ time source weekly tick |
| 153 | → scheduled-tick { name="weekly-deps", at=... } |
| 154 | ↺ dep-updater controller runs `nix flake update` in worktrees for repos it watches |
| 155 | ↺ dep-updater controller for each repo: generate change, sign attestation, push, request integration |
| 156 | → integration-requested { signer=dep-updater, ... } |
| 157 | ``` |
| 158 | |
| 159 | From the integrator's perspective, indistinguishable from a human or agent contribution. The dep-updater has its own signing key and its own trust score, accruing confirmations like any other signer. |
| 160 | |
| 161 | **What this tests:** time is just another event source. There's no "scheduled workflows" subsystem — scheduling is one controller emitting `scheduled-tick` events. |
| 162 | |
| 163 | --- |
| 164 | |
| 165 | ## What these scenarios collectively prove (or fail to prove) |
| 166 | |
| 167 | | Architectural claim | Tested by | Result | |
| 168 | | --- | --- | --- | |
| 169 | | Local attestations replace CI gates | 1, 2 | Works if reproducibility policy holds and witnesses are present | |
| 170 | | Integrator pattern handles real cases | 1, 2, 5 | Works; policy variation per-signer is essential | |
| 171 | | Feedback closes the loop post-merge | 3 | Works; attribution is the weakest link | |
| 172 | | Threads subsume PR review | 5 | Works; the "approval has authority" claim needs concrete policy mechanism | |
| 173 | | Cross-repo flows on one bus | 4 | Plausible; subscription/discovery is unsolved | |
| 174 | | Time integrates as just another event source | 6 | Clean fit | |
| 175 | | Agents are first-class contributors | 2 | Architecturally yes; agent identity model unresolved | |
| 176 | |
| 177 | ## What's still uncovered |
| 178 | |
| 179 | - **Forensic walk-back.** Replaying the log to debug "why did this happen?" The architecture promises it works; nothing in these scenarios actually exercises it as a workflow. |
| 180 | - **Multi-author / stacked changes.** A chain of dependent commits with multiple signers. The integrator doc names this as open; scenarios should eventually test it. |
| 181 | - **Recovery from bus loss.** What if the NATS log is corrupted or rebuilt? Per-repo request refs in git provide some durability for in-flight integrations, but a deeper story is needed. |
| 182 | - **Onboarding a new repo.** Not a runtime scenario — addressed in the migration plan. |