| 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. These are solution-space — architecture walk-throughs in event notation; the problem-space counterpart, what a user needs with no mechanisms, is [user-scenarios.md](./user-scenarios.md). |
| 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 | **Stress points:** |
| 36 | |
| 37 | - Whether the integrator waits for witness confirmation before integrating is policy, not architecture — but the policy needs to exist (trusted signer: probably not; new signer: probably yes). |
| 38 | - The "local checks are sufficient" assumption is load-bearing. Environment drift from canonical surfaces as witness rejections and trust-score drift; the system should make that debuggable. |
| 39 | |
| 40 | --- |
| 41 | |
| 42 | ## 2. klaus-style agent change |
| 43 | |
| 44 | An agent dispatched by klaus does the work. Same flow as a human, but identity and trust live in different places. |
| 45 | |
| 46 | ``` |
| 47 | ▶ klaus launch "fix the auth bug ..." |
| 48 | → agent-dispatched { run_id, repo, prompt, agent_key=<key> } |
| 49 | ↺ agent (in worktree) edits, runs local checks, signs attestation with agent_key |
| 50 | ▶ agent push --integrate |
| 51 | → integration-requested { repo, branch, attestations, signer=agent_key } |
| 52 | ↺ integrator verify signature, look up agent_key trust policy |
| 53 | ↺ integrator policy says "agent changes auto-integrate if attestations re-derive cleanly OR a witness pre-confirms" |
| 54 | ↺ integrator either: (a) wait for witness confirm event, or (b) integrate now and accept the risk |
| 55 | ✓ → integration-succeeded ... |
| 56 | ``` |
| 57 | |
| 58 | **Stress points:** |
| 59 | |
| 60 | - **Agent identity is unresolved.** Ephemeral per-run key, long-lived per-agent key, or delegated from the dispatching human — the architecture supports any; the trust controller cares only about confirm/deny rates per signer. |
| 61 | - **The "PR" concept dissolves.** What klaus today calls "PR created" is just `integration-requested` with the agent as signer. |
| 62 | - **Agent loops.** An agent reacting to a regression event (Scenario 3) dispatches another agent run; the architecture needs a cap (klaus's existing run-budget mechanism extends naturally). |
| 63 | |
| 64 | --- |
| 65 | |
| 66 | ## 3. Post-deploy regression |
| 67 | |
| 68 | A change makes it to production. Some time later, runtime signals indicate something is wrong. The system closes the loop back to the change. |
| 69 | |
| 70 | ``` |
| 71 | ↺ monitoring error rate on /api/foo crosses threshold |
| 72 | → regression-suspected { service, indicator, severity, observed_at, attributed_commits=[<sha-1>, <sha-2>, <sha-3>] } |
| 73 | ↺ rollback controller policy: severity >= P1 AND attributed deploy < 30min ago |
| 74 | ↺ rollback controller revert to previous artifact |
| 75 | → deployed { commit=<previous-sha>, env=prod, reason=rollback, evidence=regression-suspected } |
| 76 | ↺ thread router open/update threads for each attributed commit |
| 77 | → thread-event { thread, kind=regression-attributed, evidence } |
| 78 | ↺ priority router thread now has high-severity event; promote to human attention |
| 79 | ↺ agent dispatcher spawn klaus run: "investigate regression Z, propose fix" |
| 80 | → agent-dispatched ... |
| 81 | ``` |
| 82 | |
| 83 | **Stress points:** |
| 84 | |
| 85 | - **Attribution.** Monitoring rarely *knows* which commit caused a regression; `attributed_commits` is a lead with a confidence, not a verdict. |
| 86 | - **Auto-rollback vs human-in-the-loop** is per-environment policy — but the policy must be expressible and observable, with the controller emitting its reasoning as events. |
| 87 | - **Trust implications.** A regression alone doesn't lower a signer's trust score (regressions ≠ forgery); a *correlation* of regressions per signer is a separate signal, surfaced to humans rather than auto-acted. |
| 88 | |
| 89 | --- |
| 90 | |
| 91 | ## 4. Untrusted contributor |
| 92 | |
| 93 | A new contributor wants to land a change. They have no attestation history, so the trust controller has no signal on them. |
| 94 | |
| 95 | ``` |
| 96 | ▶ alice (new) git push --integrate topic/welcome-fix |
| 97 | → integration-requested { signer=alice, attestations, ... } |
| 98 | ↺ integrator alice has no trust score, policy says "do not auto-integrate" |
| 99 | ↺ integrator create a thread, surface the request as needing review |
| 100 | → thread-event { thread, kind=integration-pending, signer=alice } |
| 101 | ↺ priority router surfaces thread to maintainer attention |
| 102 | ▶ maintainer reviews diff in the thread view |
| 103 | ▶ maintainer approves (signed approval event) |
| 104 | → approval { thread, by=maintainer, target=alice's integration-request } |
| 105 | ↺ integrator sees approval from someone with integration-approval authority; integrates |
| 106 | ✓ → integration-succeeded { signer=alice, approved_by=maintainer } |
| 107 | ↺ trust controller alice now has 1 successful integration co-signed by a trusted party |
| 108 | (policy: after N co-signed integrations, alice's attestations can auto-integrate) |
| 109 | ``` |
| 110 | |
| 111 | **Stress points:** |
| 112 | |
| 113 | - **The trust state machine.** "Co-signed by trusted party" → "trusted enough to auto-integrate" is a discrete transition needing concrete policy: how many, which changes count, does trust decay. |
| 114 | - **Threads subsume the PR.** Request, diff, attestations, comments, approval, and outcome are one chronology in one thread. |
| 115 | - **Approval authority.** The maintainer's key being on a known list is itself policy needing versioning, audit, and grant/revoke. |
| 116 | |
| 117 | --- |
| 118 | |
| 119 | ## 5. Cross-repo schema change (sketch) |
| 120 | |
| 121 | armstrong's CUE schema changes. Multiple downstream repos depend on it. |
| 122 | |
| 123 | ``` |
| 124 | ✓ integration-succeeded { repo=armstrong, schema-updated=yes, prev_hash, new_hash } |
| 125 | ↺ schema-watcher (in each consumer repo) notices a dependency's schema changed |
| 126 | ↺ schema-watcher runs validation: does my current usage compile against the new schema? |
| 127 | → schema-compatibility { consumer, schema, status=ok|broken } |
| 128 | ↺ schema-rollout coordinator (if present) aggregates compatibility events |
| 129 | ↺ schema-rollout coordinator if all known consumers ok: cut a versioned release of the schema |
| 130 | ↺ schema-rollout coordinator if some broken: open threads in those repos with a fix-suggestion |
| 131 | ``` |
| 132 | |
| 133 | **Stress points:** |
| 134 | |
| 135 | - Tests that events flow across repo boundaries on the same bus, with per-repo controllers consuming cross-repo events. |
| 136 | - How a consumer *declares* interest in another repo's events is open — probably explicit config; implicit discovery is too magical. |
| 137 | |
| 138 | --- |
| 139 | |
| 140 | ## 6. Scheduled task (sketch) |
| 141 | |
| 142 | A weekly dependency bump. |
| 143 | |
| 144 | ``` |
| 145 | ↺ time source weekly tick |
| 146 | → scheduled-tick { name="weekly-deps", at=... } |
| 147 | ↺ dep-updater controller runs `nix flake update` in worktrees for repos it watches |
| 148 | ↺ dep-updater controller for each repo: generate change, sign attestation, push, request integration |
| 149 | → integration-requested { signer=dep-updater, ... } |
| 150 | ``` |
| 151 | |
| 152 | **Stress points:** |
| 153 | |
| 154 | - From the integrator's perspective, indistinguishable from a human or agent contribution; the dep-updater has its own key and trust score. |
| 155 | - Time is just another event source — no "scheduled workflows" subsystem, only a controller emitting `scheduled-tick` events. |
| 156 | |
| 157 | --- |
| 158 | |
| 159 | ## What these scenarios collectively prove (or fail to prove) |
| 160 | |
| 161 | | Architectural claim | Tested by | Result | |
| 162 | | --- | --- | --- | |
| 163 | | Local attestations replace CI gates | 1, 2 | Works if reproducibility policy holds and witnesses are present | |
| 164 | | Integrator pattern handles real cases | 1, 2, 4 | Works; policy variation per-signer is essential | |
| 165 | | Feedback closes the loop post-merge | 3 | Works; attribution is the weakest link | |
| 166 | | Threads subsume PR review | 4 | Works; the "approval has authority" claim needs concrete policy mechanism | |
| 167 | | Cross-repo flows on one bus | 5 | Plausible; subscription/discovery is unsolved | |
| 168 | | Time integrates as just another event source | 6 | Clean fit | |
| 169 | | Agents are first-class contributors | 2 | Architecturally yes; agent identity model unresolved | |
| 170 | |
| 171 | ## What's still uncovered |
| 172 | |
| 173 | - **Forensic walk-back.** Replaying the log to debug "why did this happen?" The architecture promises it works; nothing here exercises it as a workflow. |
| 174 | - **Multi-author / stacked changes.** A chain of dependent commits with multiple signers. |
| 175 | - **Recovery from bus loss.** Per-repo request refs in git provide some durability for in-flight integrations, but a deeper story is needed. |