gunk-dev/the-valley

architecture.md

source58e68be0d151main's published tip history
21.1 KiB · Rendered
1# Architecture
2
3The-valley separates repository hosting, verification, integration, automation, and project
4knowledge into components with explicit contracts. This document explains those choices and the
5[requirements](./requirements.md) they serve. Detailed formats and algorithms belong in
6[verification](./verification.md) and [integration](./integration.md).
7
8The repository implements hosting, event projection, local attestations, policy derivation, an
9integrator, and an identity compiler. The broader automation, product interface, and trust system
10are still being developed. A decision in the graph records an adopted design; it does not establish
11that every part has shipped.
12
13## Responsibilities
14
15| Concern | Responsibility | Current implementation or proposed direction |
16| ------------------- | --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
17| Hosting | Keep repositories available and recoverable | Bare Git over SSH, publication mirrors, and offsite backup |
18| Identity and access | Identify principals and enforce their permissions | A valley registry compiled into boundary-specific files; finer project permissions remain to be implemented |
19| Verification | Establish which checks passed over which inputs | Local runners produce signed attestations; Nix is the reference runner |
20| Artifacts | Preserve identifiable build results | Nix outputs and caches; retention policy remains open |
21| Integration | Apply policy and update protected history | A controller evaluates requests stored as Git refs |
22| Automation | Perform and record consequences of changes | Independent controllers; a shared event history is the proposed coordination mechanism |
23| Feedback | Make discussion, approvals, and problems accessible | Views over recorded work, with attention routing still to be designed |
24| Project knowledge | Preserve requirements, reasoning, and work state | Typed Markdown nodes stored with the code |
25
26A component can use another component's records without owning its workflow. For example, a build
27controller can observe an integrated change without controlling how contributors submit changes.
28
29## Events and reconciliation
30
31Git records repository state. Hooks project ref updates onto the event bus so other components can
32observe them. The bus currently uses NATS JetStream.
33
34The automation design aims to connect a change, its build, its deployment, and its notifications in
35one queryable history. Each controller owns its reaction and lifecycle. Adding a reaction should not
36require editing every other reaction or a central workflow.
37
38Events and reconciliation have different jobs. An event can tell a controller that something may
39have changed. Reconciliation reads the current authoritative state and decides what remains to be
40done. The current integrator polls request refs directly and publishes outcomes; it does not consume
41bus events.
42
43```mermaid
44flowchart LR
45 contributor["Contributor"] -->|"topic, evidence, request"| git["Git repository"]
46 git -->|"ref-update projection"| bus["Event bus"]
47 git -->|"requests and current state"| integrator["Integrator"]
48 integrator -->|"protected history and evidence"| git
49 integrator -->|"outcome projection"| bus
50 bus -.->|"planned authenticated consumers"| reactions["Build, deploy, notify, dispatch"]
51```
52
53Current refs can be projected onto a new bus. That reconstructs a view of current state, not every
54event that occurred. Deleted branches, overwritten refs, and external effects need their own
55retained history. Replaying an effectful reaction also requires rules for avoiding repeated
56deployments or notifications. Replay alone does not supply those rules.
57
58The [signal contract](../.the-valley/decisions/dcr-62ecc36-signal-contracts.md) defines the existing
59projection. [Open questions](./openquestions.md#storage-retention-and-evolution) records the
60remaining durability requirements. Bus
61[authentication](../.the-valley/bugs/bd-d853d9c-bus-unauthenticated.md) and
62[service isolation](../.the-valley/bugs/bd-500adf7-bus-shares-git-user.md) must be addressed before
63the relevant consumers or wider access are enabled.
64
65## Verification during authorship
66
67A contributor runs the required checks where the change is authored and publishes signed statements
68of their results. Each statement identifies the checked tree and the computation or observation
69being claimed. The integrator can use this evidence without running every check again.
70
71This serves the requirement for prompt integration. It also gives a human and an agent the same
72submission contract. Both must provide evidence that satisfies policy.
73
74The trust assumption is explicit: a valid signature establishes who made a claim, not whether that
75claim is true. A recognized signer can make a false claim. Independent re-verification, transparency
76publication, and trust adjustment are planned ways to detect and respond to that failure. They are
77not part of the current local-attestation guarantee.
78
79This choice trades the delay of verification before every landing for the risk that a false claim
80may be discovered after a change lands. Whether that trade is acceptable depends on the project and
81the consequences of a bad change. Revocation can restrict future work; recovery from work already
82accepted is a separate problem.
83
84[Verification](./verification.md) defines the evidence and its limits. The
85[post-landing recovery risk](../.the-valley/bugs/bd-e63bac8-cascading-revocation-on-divergence.md)
86keeps the unresolved consequences visible.
87
88## Integration through a controller
89
90A contributor requests integration by publishing a ref that names a change and its target. A
91controller reads the request, evaluates it against governing policy, and updates the protected
92branch when it can.
93
94Using a controller separates submission from the integration decision. A contributor can publish
95work before it is ready to land. The controller can report missing evidence, reconsider a request
96when the target changes, and retry an operational failure without holding a receive hook open.
97
98Requests targeting the same protected ref must serialize at the ref update. The integrator checks
99whether the proposed delta applies and whether each required check's evidence remains valid for the
100resulting tree. It uses a compare-and-swap update so a concurrent change cannot invalidate the
101decision unnoticed.
102
103Evidence can be stale, missing, or invalid. Stale evidence names work that needs refreshing. Invalid
104signatures, malformed statements, and incompatible claim types are rejected. These are different
105outcomes because they require different responses from a contributor.
106
107The integrator evaluates and compares evidence; it does not execute checks. That removes check
108execution from the serialized integration step. It does not prove adequate throughput or fairness
109under contention. The
110[starvation risk](../.the-valley/bugs/bd-c324184-occ-starvation-under-contention.md) remains open.
111
112### Protected refs
113
114Only the integrator is intended to write protected refs. Contributors can create attestation refs
115but cannot rewrite or delete existing ones through the receive boundary. Complex verification policy
116belongs in the integrator.
117
118The host schema can declare additional protected-ref writers, so deployment must preserve this
119restriction. The
120[access decision](../.the-valley/decisions/dcr-e544f20-access-is-verbs-on-projects.md) treats
121integrator authority as part of the machinery, not a permission to grant to ordinary contributors.
122Host root access remains outside this enforcement boundary.
123
124Today, the remaining ref namespaces are available to callers with push access. The decided
125project-scoped `push`, `fetch`, `request`, and `observe` permissions require further enforcement
126work. A declaration is not a permission boundary until a component checks it.
127
128## Review, approval, and feedback
129
130A pull request commonly combines four needs:
131
132| Need | What must be available |
133| ------------ | ------------------------------------------------------------ |
134| Coordination | Discussion connected to the relevant change or outcome |
135| Gating | Evidence and approvals required before integration |
136| Record | A durable account of what was decided and why |
137| Notification | A way to reach the person or agent whose attention is needed |
138
139These needs can share records without depending on a single pull-request object. A view can show the
140discussion, evidence, approval, and outcome associated with a change. The underlying records remain
141accessible to other views and to agents.
142
143Discussion and approval are distinct. An approval that authorizes a change must be a signed act with
144an identifiable subject. The
145[core approval decision](../.the-valley/decisions/dcr-9c75283-substrate-adoption-and-the-core.md)
146requires physical human approval by default. Policy may exempt ordinary work, such as implementation
147under previously approved intent. Changes to policy itself still require physical approval. The
148approval mechanism must ship before that requirement is activated.
149
150The [interface proposal](../.the-valley/ideas/ida-23aa413-project-surfaces-are-derived-views.md)
151explores a product interface over these records. Attention routing remains separate: it must decide
152what a person needs to see and when, without requiring them to watch every event.
153
154## Project knowledge
155
156The graph stores outcomes, bugs, ideas, and decisions as Markdown files with typed metadata. It
157clones, changes, and receives backup with the code. Humans can read it directly, and agents can use
158the same files.
159
160The [graph conventions](../.the-valley/README.md) define the four implemented node types and their
161relationships. Earlier proposals also describe discussion, principles, and configuration as nodes.
162Those extensions are not in the current schema. In particular, a proposed principle does not become
163an enforced requirement merely by appearing in the graph.
164
165The graph's purpose extends beyond tracking tasks. It preserves the reasons behind decisions so a
166later contributor can reconstruct the design and assess a proposed change. Keeping that reasoning
167readable matters as much as keeping the metadata valid.
168
169## Work from outcomes and dependencies
170
171An outcome describes something someone wants to exist. Dependencies record what must be resolved
172before work on it can finish.
173
174The scheduling proposal uses this graph to choose work. A requested outcome supplies demand. Its
175priority influences the work needed to satisfy it. Open outcomes whose blockers have cleared form
176the set available for dispatch. An agent can then work on one of those outcomes and update the
177record as it proceeds.
178
179The current schema supports `blocked_by` and defines when each kind of blocker clears. Priority
180propagation, dispatch policy, completion links, and concurrency controls are further design work.
181The [outcome proposal](../.the-valley/ideas/ida-eac723e-outcome-dag.md) contains the full reasoning.
182
183Choosing work and requesting human attention are separate decisions. One asks what can make progress
184toward a requested outcome. The other asks which uncertainty or stalled decision needs a person.
185Continuing demand also requires limits on retries and total spending; the
186[unbounded-work risk](../.the-valley/bugs/bd-5cb2034-unbounded-loops-under-demand-pressure.md)
187describes the failure to avoid.
188
189## Valleys, projects, and hosts
190
191A **valley** is a set of people, machines, services, and projects governed together. It has a
192repository containing its identity registry and shared policy. A project belongs to one valley and
193currently has one Git repository.
194
195A host provides the machinery serving those repositories. It does not define the valley's policy.
196The design allows several valleys on a host while requiring separate access and service state. A
197valley spanning several hosts is deferred.
198
199The-valley supplies common software, schemas, and policy templates. A valley adopts policy by
200integrating it into its own repository. An update to supplied templates does not silently change
201what a valley has adopted. The small deployed core is the explicit exception described by the
202[adoption decision](../.the-valley/decisions/dcr-9c75283-substrate-adoption-and-the-core.md).
203
204### Policy and identity
205
206The valley's shared verification policy is called its **floor**. A project can add requirements and
207choose optional defaults; it cannot remove mandatory floor requirements. Required checks come from
208every path class touched by the change.
209
210The integrator reads the floor from the valley's integrated state and the project's policy from the
211target branch's integrated state. A proposed policy change is therefore judged under the rules that
212precede it.
213[Policy composition](../.the-valley/decisions/dcr-f41f718-declared-verification-policy.md) defines
214this contract. Supplying trusted implementations of mandated checks remains a
215[separate gap](../.the-valley/bugs/bd-eaefe82-check-definitions-come-from-the-branch.md).
216
217The identity registry declares principals, their keys, and grants. Its compiler produces the files
218checked at enforcement boundaries. A human, machine, or service may be recognized by several
219valleys, each independently granting authority.
220
221An agent run acts under delegated authority and has no registry key of its own. Host-signed
222provenance attributes the work to the run. Recording a delegation chain does not yet verify that
223chain.
224
225### Relationships and counts
226
227These counts describe the adopted model. The remaining work for sharing hosts is recorded in the
228[host isolation decision](../.the-valley/decisions/dcr-9b5da04-hosts-serve-isolated-valleys.md).
229
230| Relationship | Model |
231| ------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
232| Valley to governing repository | One repository per valley |
233| Valley to registry and floor | One registry and one adopted floor; operation under the core alone is decided but not enabled by current tooling |
234| Valley to projects | A valley governs several projects; each project has one owning valley |
235| Project to stores and policy | One Git store today, with other stores possible; project policy is optional |
236| Host to valleys | Several valleys may share a host; one valley across several hosts is deferred |
237| Valley to push access | One separate Unix push user per valley on a serving host |
238| Principal to valleys | A principal may be recognized independently by several valleys |
239| Principal to keys | A principal may have several keys, each with its own lifetime |
240| Grant to enforcement | Each grant needs a boundary that checks the permitted action and scope |
241| Valley to integrator identity | One integrator principal; several controllers may sign as it |
242| Controller to protected history | A controller serves a protected project or target; writes to the same target must be ordered |
243| Agent run to authority | The run uses delegated authority and records its provenance; it is not a new registry principal |
244| Statement to signatures | Several signatures may cover the same statement text |
245| Signing name to verifier key | The name and public key jointly identify a verifier key; one raw key under two names produces two verifier identities |
246| Project to mirrors | Zero or more publication mirrors; the schema already permits a list |
247| Request to landing | A pending request may land or remain unresolved; a landed request is consumed |
248
249Valleys sharing a host must not receive one another's credentials or events by default. The bus
250could be separated per valley or use authenticated subjects scoped to each valley; that choice is
251open. Host administrators retain root access, so independence from an administrator requires a
252separate hosting boundary.
253
254### Bootstrap and recovery
255
256Several parts of the system govern their own changes: the registry controls who can amend it, policy
257determines how its amendments land, and a host may serve the repository that declares its
258configuration.
259
260Ordinary updates use the previous accepted state to judge the next state. The integrator records the
261policy used in its transfer statement. A new rule begins governing subsequent changes after its own
262adoption has passed the existing rules.
263
264The first state is different. It must be established before these mechanisms can enforce it.
265Recovery must also remain possible when the mechanism being repaired cannot operate.
266
267| Governed component | Initial setup | Recovery boundary |
268| ------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
269| Registry | Seed recognized principals before enabling compilation | Host administration; recovery after compromise of the initial governing identity remains open |
270| Verification policy | Seed the governing repository before its integrator depends on it | Host administration and a recorded recovery procedure |
271| Repository access | Supply initial keys until the registry can compile them | Retain the last valid artifacts after a failed compile; reject a render with no unexpired governing key |
272| Host configuration | Install the first host manually | Restore from offsite backup and reapply configuration |
273
274Retaining old compiled credentials has its own cost: a failed convergence can retain a credential
275that has since expired. Recovery availability and timely revocation need to be considered together.
276
277Introducing the integrator's own key is another bootstrap case. The intended anchor is approval by
278an already authorized human, rather than relying only on the new key's signature. The complete
279approval and recovery procedures remain part of the open
280[self-transparency proposal](./self-transparency.md).
281
282## Components
283
284| Component | Role and status |
285| ------------------------------- | -------------------------------------------------------------------------------------------------------- |
286| Bare Git and SSH | Current repository transport and storage |
287| NATS JetStream | Current ref-event projection and inspection |
288| Nix | Reference build and verification runner |
289| CUE | Shared schemas for hosts, events, nodes, evidence, identity, and policy |
290| Integrator | Current request reconciliation and protected-ref updates |
291| Tessera-backed transparency log | Proposed external publication and inclusion proofs for Phase 6 |
292| Armstrong | Proposed controller for builds and external effects |
293| Klaus | Existing agent orchestrator to adapt to valley outcomes and integration |
294| Repository and graph interface | Product work proposed in the graph; browsing, editing, and review should use the same underlying records |
295
296These choices can be revised as the [roadmap](./roadmap.md) tests them. The schemas and observable
297contracts are intended to outlast any one implementation.