gunk-dev/the-valley

ida-594df79-klaus-s3-requirements-oracle.md

source9ee0a5aa589dmain's published tip history
7.8 KiB · Rendered
1---
2type: idea
3id: ida-594df79
4status: exploring
5title: klaus is the requirements oracle for S3
6created: 2026-07-13
7source: directed review, 2026-07-13
8---
9
10# klaus is the requirements oracle for S3
11
12**Thesis.** [klaus](https://github.com/patflynn/klaus) — the operator's daily agent orchestrator,
13S3's anchor in the [ladder](../../design/user-scenarios.md#the-ladder) — is a _working_ system whose
14observed behaviors are S3's requirements. It is GitHub-shaped end to end: PR-indexed pipeline FSM,
15`gh`-mediated state, webhook-relay feed. The migration story is therefore not "rebuild klaus" but
16**swap the GitHub feed for valley events** — klaus already anticipates this (its
17`pr:approval-changed` event is documented as "deliberately backend-agnostic … for non-GitHub
18merge-readiness sources", `internal/event/event.go`).
19
20## Behavior → valley concept
21
22| klaus behavior (today) | valley concept | phase |
23| ------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ----- |
24| github-relay webhook feed + poll reconcile — events are _invalidation signals_; GitHub API is the state store | event log as the consumer feed (`ref-updated`, …) | 1 |
25| `klaus approve` / `auto_merge_on_approval` / trusted-reviewer config | integrator policy | 3 |
26| agent opens a PR (hard-coded in the default agent prompt, `internal/config/config.go`) | integration request | 3 |
27| `klaus launch --issue` / prompt-carried dispatch | dispatch against an outcome node ([[ida-eac723e]], [ida-eac723e-outcome-dag.md](./ida-eac723e-outcome-dag.md)) | 4 |
28| run state files + `refs/klaus/data` artifacts + dashboard + `klaus watch` JSONL | one queryable history | 5 |
29| trusted-reviewer PR comment → fix-agent dispatch | threads / review-as-feedback | 7 |
30| budget-pause: draft PR + `klaus:budget-paused` label + comment _is_ the persisted state; `klaus launch --pr` is the only resume | **no valley equivalent yet** — needs paused-work persistence, likely a node + branch | gap |
31
32## Evidence: one week of S1 direct-push (the-valley, qinling)
33
34| # | observed | precise cause in klaus |
35| --- | ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
36| 1 | agent pushed a branch, ended as bare `exited`; the operator finds work via `git ls-remote` | no event kind carries a pushed branch; `determineStatus` knows only PR/merged states (`internal/cmd/status.go`); default `klaus watch` filter omits `agent:completed` (`internal/cmd/watch.go`) |
37| 2 | budget-capped direct-push agent has **no** persistence/resume story | `draft.HandleBudgetPause` pushes WIP fine (pure git) but then needs `gh pr create --draft` + label; on a sovereign origin that fails and `_finalize` falls through to a normal completion — no `agent:paused`, nothing to resume against |
38| 3 | no "branch awaiting integration" state anywhere | pipeline FSM keyed by PR number (`internal/pipeline/pipeline.go`); `track`/`approve`/`merge` all take PR refs |
39| 4 | a run got labeled with an upstream repo's PR #130 it merely _mentioned_ | `_finalize` regex-scrapes any `github.com/.../pull/N` URL from the transcript, last match wins, never checked against the run's target repo (`internal/cmd/hidden.go`) |
40| 5 | agent killed by a usage limit died silently; only the log tail said why | crash detection reads only the final `result` JSONL line; a killed stream sets no `FailureReason` → false `agent:completed`; `agent:needs-attention` is also absent from the default watch filter |
41
42Gap 5 is [[ida-3145b7a]]'s stall row "agent run died silently"
43([ida-3145b7a-demand-pressure.md](./ida-3145b7a-demand-pressure.md)), observed in production — klaus
44is the spawn-delivery mechanism that idea's demand pressure schedules, and it needs the
45lease/re-dispatch machinery sketched there.
46
47## What Phases 1/3/4 must minimally satisfy for klaus to swap feeds
48
49- **Phase 1 (events).** `ref-updated` carrying repo, ref, old/new sha, and pusher identity — that
50 alone kills gaps 1 and 5's silence (a branch push and a _missing_ expected push are both
51 observable). Remotely subscribable (klaus runs on the workstation, not classic-laddie) and
52 deterministically replayable, since klaus treats events as invalidation + reconcile, never as the
53 store.
54- **Phase 3 (integrator).** `integration-requested` addressable by branch/request id, not PR number
55 — klaus's FSM re-keys from PR to request id; `integration-succeeded` / `request-stale` replace
56 what `gh pr view` answers today; plus a _queryable_ per-request status, because klaus's controller
57 is level-triggered and reconciles state, it doesn't just react. "Awaiting integration" (gap 3)
58 becomes a first-class stage. `klaus approve` becomes integrator policy input.
59- **Phase 4 (dispatch + attribution).** Dispatch targets an outcome node — but klaus doctrine says
60 the prompt is the agent's _entire briefing_ (`docs/PIPELINE.md`), so the node body must be
61 brief-quality or dispatch stays prompt+node. A run holds no key of its own; attribution rides as
62 provenance inside the host-signed attestation ([[dcr-0de694f]]
63 ([dcr-0de694f-phase2-attestation-shape.md](../decisions/dcr-0de694f-phase2-attestation-shape.md))),
64 which retires gap 4's transcript-scraping for good. Paused work (gap 2) persists as a node + WIP
65 branch — klaus already syncs the resume trajectory over plain git (`refs/klaus/data`), so only the
66 pause _marker_ and resume index need valley-native homes.
67
68## Related
69
70- Dispatch semantics and the outcome DAG this feeds: [[ida-eac723e]]
71 ([ida-eac723e-outcome-dag.md](./ida-eac723e-outcome-dag.md))
72- Demand pressure / anti-stall, whose failure taxonomy gap 5 instantiates: [[ida-3145b7a]]
73 ([ida-3145b7a-demand-pressure.md](./ida-3145b7a-demand-pressure.md))
74- Near-term operational fixes filed upstream: patflynn/klaus issues (branch-push visibility,
75 sovereign budget-pause, PR-URL misattribution)