gunk-dev/the-valley

dcr-f41f718-declared-verification-policy.md

source68dab279fa3bmain's published tip history
22.6 KiB · Rendered
1---
2type: decision
3id: dcr-f41f718
4status: decided
5title: Verification policy is declared in CUE, composed from an instance floor and a project layer
6created: 2026-07-31
7source: cosmo-readiness design pass, 2026-07-31
8---
9
10# Declared verification policy
11
12Verification policy — the mapping from path classes to required checks — is declared in CUE. It has
13two layers, and each layer is a policy directory: a CUE package unifies every file in it, so a layer
14is one or more documents and the file count carries no meaning. The valley's instance repository
15carries a mandatory floor and a set of project-type templates; the project's own repository carries
16everything above the floor. The effective policy is the unification of the two layers. The schema is
17[schema/verification.cue](../../../schema/verification.cue), with a worked example at
18[examples/policy/](../../../examples/policy/), so the shape can be read rather than imagined.
19
20The design this gives a home to is already written down. [[ida-1ec03b1]]
21([ida-1ec03b1-path-scoped-verification-policy.md](../ideas/ida-1ec03b1-path-scoped-verification-policy.md))
22establishes that required checks are derived from the actual tree diff and never from a
23contributor's claim, that `.the-valley/**` takes signature plus knowledge lint while code takes the
24full suite and a mixed diff takes the max, and — the sentence this node acts on — that the policy
25itself is data, so it is expressed in CUE and versioned in-repo. This node supplies the schema and
26the answer to _in which repo_.
27
28## Why this is needed now
29
30cosmo gates every change through a pull-request workflow, and branch protection makes that gate the
31condition of merging; what the gate contains is inventoried in [[ida-7638082]]
32([ida-7638082-host-has-no-check-runner.md](../ideas/ida-7638082-host-has-no-check-runner.md)). S1
33direct-push mode has no pull request object, so migrating cosmo to a valley instance does not weaken
34that gate — it deletes it. The repository that builds five machines would land changes with nothing
35checking them, and nothing on the instance runs a check today. Declared verification policy is the
36piece that has to exist before cosmo can be hosted here. The wider readiness picture is tracked
37separately in the cosmo-readiness outcome [[oc-87deec8]]
38([oc-87deec8-valley-can-host-cosmo.md](../outcomes/oc-87deec8-valley-can-host-cosmo.md)).
39
40## The two layers
41
42Both layers are the same schema and the same kind of thing: a policy directory versioned in the
43repository it belongs to. The weight sits in the project layer, and the floor is deliberately small.
44
45The **instance layer** is the valley's policy. A valley owns one repository ([[dcr-8f069dd]]
46([dcr-8f069dd-valley-is-the-unit.md](./dcr-8f069dd-valley-is-the-unit.md))), so the instance
47repository is the valley's repository, and for the gunk-dev valley that is qinling. It states the
48minimum: the checks no project in the valley may decline, plus project-type templates that give a
49project of a known type a sensible starting set.
50
51The **project layer** is the project's own policy, a policy directory versioned in its own tree. It
52states everything else: the classes the project cares about, the checks it adds, and the template
53defaults it declines.
54
55The two compose by unification, which can only narrow, so the floor is a floor by construction: the
56project layer can add to it and cannot subtract from it. Both layers say what; they differ only in
57whether a project can answer back. That is what keeps the two halves from being two vocabularies to
58learn, and what makes the composition a single `cue vet`.
59
60The discipline this asks for is keeping the floor minimal. The floor is the minimum a valley is
61willing to enforce on projects it has not read; a floor that keeps absorbing checks until it
62describes every class of every project has stopped being a floor.
63
64Policy has no business at a lower layer than the valley. Valley to host deliberately is not 1-to-1:
65a valley runs on a single machine and is equally runnable as a distributed system, with git hosting
66sharding across hosts and nothing in the architecture assuming co-location. classic-laddie being the
67whole of the gunk-dev valley today is a fact about deployment, not about the design. A policy field
68on a host would therefore be a policy field on _one of several_ possible carriers of the same
69valley, free to diverge from its siblings with neither one wrong. The host is not involved at any
70point, and [schema/valley.cue](../../../schema/valley.cue) carries nothing about verification.
71
72## A layer that is not there defaults in the safe direction of that layer's job
73
74Each layer's absence is answered by what that layer is for, and because the two layers have opposite
75jobs the two answers point in opposite directions.
76
77**A project layer that is not there composes the floor alone.** The project layer can only add,
78which is the section above in one sentence, and the identity of "adds" is "adds nothing". Absence
79therefore has a reading that takes nothing away from anyone, and that reading is used. It is an
80ordinary composition rather than an error, and a pass under it is worth a journal line and nothing
81more.
82
83The alternative reading, refusing to judge a target that carries no layer, makes a repository
84unlandable until its first policy commit — and that commit cannot land either, because a change
85never supplies the policy that gates it. Every project would have to have its policy installed by
86hand, around the gate, which is the one thing the gate exists to prevent.
87
88**A floor that is not there is refused, and refused loudly.** The floor is the minimum a valley
89enforces on projects it has not read, and a missing minimum has no safe reading. Nothing
90distinguishes a controller pointed at the wrong directory from an instance repository nobody has
91seeded from a floor that was deleted, and composing against nothing would answer all three the same
92way: by requiring nothing of every project in the valley, silently. The refusal names the
93repository, the directory and the ref that was looked in, because those three are what an operator
94compares against the repository in front of them, and it says why absence is refused — a valley
95without a written floor is not a valley whose changes land.
96
97**Emptiness a document states is not absence.** A floor whose `checks`, `classes` and `unclassified`
98are all empty is a decision that was written down, reviewed, and landed in the instance repository
99under that repository's own policy: a valley that has chosen to run ungated, with the history to
100show who chose it. It composes and judges like any other floor, and every change under it lands
101owing nothing. What is refused is the missing document, because no decision was made and no history
102records one. The floor is mandatory even when what it requires is nothing.
103
104## Mandatory versus overridable is one bit per check, in CUE's own semantics
105
106This is why CUE suits the model rather than merely carrying it. Unification can only narrow, so the
107_form_ of a value decides whether a project can answer back, and the schema needs no flag it would
108have to interpret.
109
110- A **concrete** constraint from the floor — a check required with the value `true` — cannot be
111 unset. A project supplying `false` conflicts, and `cue vet` fails naming the field.
112- A **template default** — written as the disjunction `bool | *true` — is overridable. It reads as
113 `true` when nobody says otherwise, and a project supplying `false` unifies cleanly to `false`.
114- **Open structs** mean a project may always add classes and checks, and can never remove the
115 floor's.
116- **Project-type templates** are policy fragments a project selects by name and then narrows, so a
117 project that is an ordinary instance of its type works with very little configuration and can
118 still override the non-mandatory parts or define its own.
119
120## Everything that composes is keyed, never a list
121
122CUE unifies lists positionally and requires equal length, so two lists that were written
123independently simply conflict. Every part of the policy that has to compose across the two layers
124therefore cannot be a list.
125
126The path classes are keyed by class name rather than held in a list of class values. A class's
127required checks, the `unclassified` set, and a class's path patterns are all sets written as structs
128from name to `bool` rather than lists of names. When both layers name the same class, it is one
129class: its coverage and its requirements are the union of what each layer contributed, and nothing
130either layer made concrete can be taken back.
131
132Keying a class's `paths` the same way is load-bearing and easy to miss. If coverage were a list, a
133project could rewrite a floor class's patterns wholesale; keyed and concrete, a floor class's
134coverage cannot be narrowed to a path the project never touches, which would otherwise escape the
135floor everywhere else.
136
137## Forcing comes from the floor's provenance, not from CUE
138
139Unification on its own forces nothing. A project that vendored a copy of the floor into its own tree
140and edited the copy would unify perfectly well; the copy is simply not the floor. What makes a floor
141a floor is where it is read from: the instance repository's integrated tip, never the project's
142tree.
143
144Weakening the floor therefore takes two landings. Changing the floor is a change landing in the
145instance repository, under that repository's own policy and its own integrator, and it is visible in
146that repository's history — which is what [self-transparency.md](../../design/self-transparency.md)
147asks of the system's own configuration. The schema cannot enforce this, because a schema cannot see
148which file a field came from. The tool that composes a policy is what makes it true, and the schema
149says so in its comments.
150
151## The two halves resolve at different times
152
153The mandatory floor resolves at head. A floor a project could pin is not a floor: pinning it would
154make every past floor permanently available as an alternative to the current one, and weakening
155would take one landing again — the project's.
156
157Templates may be pinned. They are defaults, a project can already override them, and a stale default
158costs nothing the project could not have written by hand.
159
160## Who enumerates a layer's documents
161
162The constraint on a policy directory is not how many documents it holds but who enumerates the set.
163A floor a project can decline to load is not a floor, so floor documents are enumerated by the
164instance, while template documents are selected by the project. That is the
165mandatory-versus-overridable distinction above, expressed at document granularity instead of at
166field granularity.
167
168A standard directory is the natural expression of it, because a CUE package already works that way:
169the directory is the enumeration, so no manifest is needed and nothing has to list which files
170count. One directory holds both the floor and the templates, because CUE's definition-versus-field
171distinction does the selection. A concrete field is floor and loads unconditionally; a project-type
172template written as a definition is inert until a project embeds it. Whether a policy document is
173mandatory or optional is therefore visible in the syntax of the file itself. This repository already
174uses the same move: [.the-valley/README.md](../README.md) describes the knowledge graph as "a
175directory convention, not a system", where listing is `ls` and search is `grep` and no indexer
176exists. A policy directory is that convention applied again rather than a new mechanism.
177
178The obvious comparison is a workflow directory in a hosted forge, and it breaks in two places.
179Workflow files are independent of one another; policy files unify. A new file in the floor directory
180changes the effective policy of every project in the valley, and that silent addition has no
181equivalent in the workflow-directory model. The second difference matters more: a workflow directory
182has no floor. Anyone who can write it controls the checks completely, which is precisely what this
183design denies a project. So the same convention is applied twice with different authority — the
184floor directory in the instance repository, resolved at head, and the project's own directory in its
185own tree. A project adding a document to its own directory can only narrow; a project able to write
186the floor directory would be the entire gate gone.
187
188Factoring a layer across several documents is safe rather than risky. Two floor documents may
189contribute mandatory checks to the same class and compose without complaint, and two documents that
190disagree on the same check fail at vet time with an error naming both files and both line numbers,
191so a silent last-write-wins is not possible. In the worked directory at
192[examples/policy/](../../../examples/policy/), a third floor document contradicting the second fails
193vet:
194
195```
196floor.classes.prose.requires."link-check": conflicting values true and false:
197 ./examples/policy/instance/floor-references.cue:19:27
198 ./floor-disagree.cue:3:48
199```
200
201## What the schema commits to
202
203Class matching is a set operation, never first-match. A change's required checks are the union of
204`requires` over every class that at least one changed path matches. Classes may overlap deliberately
205— a knowledge node is both knowledge and prose — and the union is the entirety of [[ida-1ec03b1]]'s
206"mixed takes the max" rule. There is no separate mixed case, and no ordering to get wrong.
207
208A path matching no class is answered explicitly, by a required `unclassified` field. The failure a
209policy must never have is a path that quietly requires nothing, so the policy has to state what an
210uncovered path costs rather than defaulting to silence.
211
212The signature is deliberately absent. [[ida-1ec03b1]] lists it alongside the knowledge lint because
213it is enumerating what a knowledge-only diff must satisfy, but the signature is required of every
214change by the structural invariant and the integrator, whatever paths the diff touches. It is not
215path-scoped, so it is not policy.
216
217Every check name a class requires must exist in the composed catalogue. A name that does not lands
218in `checks` as an incomplete check and fails vet. Without this, a typo is not a vet error — it is a
219check that silently stops being required.
220
221## Evidence: the worked example
222
223The claims above are pinned by running `cue vet`, not by inspection. The example is the policy
224directory at [examples/policy/](../../../examples/policy/). The instance layer makes `prose-format`
225mandatory over `**/*.md` and for uncovered paths, requires `link-check` over the same class from a
226second document, and offers a `docs` project type whose knowledge lint is a default. The project
227layer embeds that type, adds a `shellcheck` class of its own, and declines the defaulted knowledge
228lint.
229
230Both directions were run.
231
232```
233$ cue vet -c schema/verification.cue \
234 examples/policy/instance/*.cue examples/policy/project/*.cue
235$ echo $?
2360
237```
238
239The composed `policy` exports with `knowledge-lint` at `false` — the project's legitimate override —
240alongside the floor's `prose-format` and `link-check` at `true` and the project's own `shellcheck`
241class. A project that instead tries to unset a mandatory check fails, and the error names the field
242and the floor document it came from:
243
244```
245$ cue vet -c schema/verification.cue examples/policy/instance/*.cue unset.cue
246policy.classes.prose.requires."prose-format": conflicting values false and true:
247 ./examples/policy/instance/floor-format.cue:26:29
248 ./schema/verification.cue:184:16
249 ./schema/verification.cue:184:42
250 ./schema/verification.cue:185:9
251 ./unset.cue:3:52
252```
253
254Narrowing a floor class's coverage fails the same way, at `policy.classes.prose.paths."**/*.md"`.
255Selecting a project type the instance does not define is an evaluation error rather than a silent
256fallback. An unknown check name, a stray top-level field, an absolute or `..` path pattern, an
257unimplemented runner, an unknown field inside a class, and a malformed name all fail vet with an
258error naming the field. A project document that declares nothing at all vets, and composes to the
259floor exactly.
260
261The example is evidence for the schema and nothing more. It is not the live exercise on qinling,
262which is a separate step described below. The rejections above are demonstrated rather than run
263continuously: the flake's `cue-vet` check does not cover them. The schema is read by one tool, the
264deriver of step 3 below, and by nothing else — not by
265[schema/valley.cue](../../../schema/valley.cue) and not by
266[nix/valley-host.nix](../../../nix/valley-host.nix).
267
268## What this costs
269
270A project is now self-describing only above the floor, which trims [[ida-3e87f5c]]
271([ida-3e87f5c-self-describing-projects.md](../ideas/ida-3e87f5c-self-describing-projects.md)). A
272clone of the project alone can no longer state its required set; it can state what the project adds,
273and must consult the instance repository for the rest. That is a deliberate trade for the valley
274being able to force compliance, which is the whole reason the floor exists. The timing split
275preserves most of the offline story: templates may be pinned, so the only thing a clone genuinely
276cannot answer alone is the current floor, and the floor is small by design.
277
278Enforcement belongs to the integrator, which already holds both trees and reads the policy at the
279target ref's tip — the policy that is already integrated — so a change never supplies the policy
280that gates it. That is consistent with the one structural invariant in
281[contribute.md](../../design/contribute.md), and it means declared policy is inert data until Phase
2823 ([roadmap.md](../../design/roadmap.md)); Phase 2 is where a contributor can first produce the
283evidence a policy asks for. The checks a policy names are ordinary flake checks in the reference
284implementation, so a project that already has checks has most of a policy — the policy says which
285ones apply where, not what a check is.
286
287## The staged path: qinling first, cosmo second
288
289Every feature built for cosmo readiness is exercised live on the gunk-dev instance, on a project
290already hosted there, before cosmo depends on it. The projects on the instance today are the-valley
291and qinling, and both are markdown-only. So the first exercisable class is knowledge and prose — the
292formatter-idempotence check this repo already ships as a flake check, plus the frontmatter and
293reference-integrity linting [[ida-1ec03b1]] describes — and not the `nix build` class cosmo
294eventually needs.
295
296qinling is also the instance repository, so the first exercise carries both layers at once: qinling
297holds the floor and the templates, and the-valley holds a project policy that composes with them.
298
299### The smallest thing that could be turned on
300
301Four pieces, none of which is an enforcement point:
302
3031. qinling gains the instance policy directory — a floor requiring the prose format check over
304 `**/*.md` and for uncovered paths, and a `docs` project type offering the knowledge lint — and
305 the-valley gains a project policy that selects that type. The example at `examples/policy/` is
306 written as very nearly that arrangement.
3072. `knowledge-lint` is built as a flake check; what it checks is enumerated once, in
308 [.the-valley/README.md](../README.md). `prose-format` already exists in this repo and is copied
309 or shared.
3103. A read-only deriver: given the instance tip, a project tree, and two commits, compose the policy,
311 list the changed paths, match them against the composed classes, and print the required check
312 names. It reports; it blocks nothing. This is `valley checks` in
313 [bin/valley](../../../bin/valley). It is told where the two layers are and defaults to the worked
314 example, because nothing yet resolves a project to its instance — and that resolution is the
315 whole of the floor's forcing, so the deriver has no floor until something supplies it.
3164. The two checks are run against the trees the deriver named.
317
318### What observing it succeed looks like
319
320The standard is verified by looking, not by reviewing configuration. Reading the policy files and
321agreeing that they say the right thing is not the exercise.
322
323- A commit that actually landed in the-valley touching a knowledge node is fed to the deriver, and
324 it prints exactly `knowledge-lint` and `prose-format` — the union of two overlapping classes, one
325 contributed by each layer, observed rather than asserted.
326- A commit touching only `README.md` prints exactly `prose-format`. The knowledge lint's absence is
327 the observation; a policy that over-requires is as wrong as one that under-requires, and only the
328 second failure is loud.
329- The project document is edited to decline `prose-format`, and the deriver refuses to compose the
330 policy at all, naming the field. The floor is observed to hold against the project rather than
331 argued to.
332- A node's frontmatter is deliberately broken on a scratch branch. `knowledge-lint` fails against
333 that tree, and the failure names the file and the field.
334- A file no class covers — a shell script in a markdown-only repository — makes the deriver print
335 the `unclassified` set. The hole announces itself instead of being found later.
336
337### What cosmo additionally requires
338
339Naming these keeps the qinling exercise from being mistaken for cosmo readiness.
340
341- A `format` class over `**/*.nix` requiring `nixfmt --check`, and a build class requiring the
342 five-machine build matrix. The schema expresses both today; nothing else about them is ready.
343- An answer to check latency. Five machines' worth of `nix build` is not something a contributor's
344 machine finishes quickly, and neither layer's owning the policy changes that. It is a real open
345 question this node does not close.
346- The floor actually read from the instance repository's tip by something, rather than from whatever
347 tree happens to be at hand. Provenance is the whole of the forcing, so an implementation that gets
348 it wrong has no floor at all.
349- An enforcement point — Phase 3's integrator, or a deliberate interim. Until then this machinery
350 observes and reports, and **cosmo must not migrate onto an observation**. That is the difference
351 between qinling exercising the feature and cosmo depending on it.
352
353## Related
354
355- The design this implements: [[ida-1ec03b1]]
356 ([ida-1ec03b1-path-scoped-verification-policy.md](../ideas/ida-1ec03b1-path-scoped-verification-policy.md))
357- The unit whose policy the instance layer is: [[dcr-8f069dd]]
358 ([dcr-8f069dd-valley-is-the-unit.md](./dcr-8f069dd-valley-is-the-unit.md))
359- The direction the project layer continues, and that the floor trims: [[ida-3e87f5c]]
360 ([ida-3e87f5c-self-describing-projects.md](../ideas/ida-3e87f5c-self-describing-projects.md))
361- The store the policy travels in: [[dcr-5da1f36]]
362 ([dcr-5da1f36-project-is-repo.md](./dcr-5da1f36-project-is-repo.md))
363- Why the host schema stays free of options a host cannot act on: [[dcr-0f5d9b1]]
364 ([dcr-0f5d9b1-cue-config-host-module.md](./dcr-0f5d9b1-cue-config-host-module.md))