gunk-dev/the-valley

dcr-f41f718-declared-verification-policy.md

source221b93eb65bfmain's published tip history
24.4 KiB · Rendered
1---
2type: decision
3id: dcr-f41f718
4status: proposed
5title: Verification policy is a declared document, 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 — becomes a declared CUE
13document. It is composed from two documents, not one. The group's instance repository carries a
14mandatory floor and a set of project-type templates; the project's own repository carries everything
15above the floor. The effective policy is the unification of the two. A draft schema accompanies the
16proposal ([schema/verification.cue](../../schema/verification.cue)), with a worked two-document
17example at [examples/verification-instance.cue](../../examples/verification-instance.cue) and
18[examples/verification-project.cue](../../examples/verification-project.cue), so the shape can be
19read rather than imagined.
20
21The design this gives a home to is already written down. [[ida-1ec03b1]]
22([ida-1ec03b1-path-scoped-verification-policy.md](../ideas/ida-1ec03b1-path-scoped-verification-policy.md))
23establishes that required checks are derived from the actual tree diff and never from a
24contributor's claim, that `.the-valley/**` takes signature plus knowledge lint while code takes the
25full suite and a mixed diff takes the max, and — the sentence this node acts on — that the policy
26itself is data, so it is a CUE document versioned in-repo. What is missing is the schema and the
27answer to _in which repo_.
28
29## Why this is needed now
30
31cosmo gates every change through GitHub Actions. Its `.github/workflows/ci.yml` runs
32`nixfmt --check` and a `nix build` matrix over classic-laddie, makers-nix and johnny-walker, and
33branch protection makes that gate the condition of merging. S1 direct-push mode has no pull request
34object, so migrating cosmo to a valley instance does not weaken that gate — it deletes it. The
35repository that builds five machines would land changes with nothing checking them, and nothing on
36the instance runs a check today. Declared verification policy is the piece that has to exist before
37cosmo can be hosted here. The wider readiness picture is tracked separately as the cosmo-readiness
38outcome node, in flight on branch `oc/cosmo-readiness`.
39
40## The two layers
41
42The **instance layer** is the group's policy. A group has exactly one instance — that binding is
43settled in [[ida-8482624]]
44([ida-8482624-federation-groups.md](../ideas/ida-8482624-federation-groups.md)) and in
45[architecture.md § federation](../../design/architecture.md#federation-the-group-is-the-unit) — so
46the instance repository is the group's repository, and for the gunk-dev instance that is qinling. It
47holds two things: a mandatory floor every project in the group clears, and project-type templates a
48project selects and then narrows.
49
50The **project layer** is the project's own policy, a versioned document in its own tree. It states
51everything above the floor: the classes the project cares about, the checks it adds, and the
52template defaults it declines.
53
54Policy has no business at a lower layer than the instance. Group to instance is 1-to-1, but instance
55to host deliberately is not: an instance is instantiable on a single machine and equally runnable as
56a distributed system, with git hosting sharding across hosts and nothing in the architecture
57assuming co-location. classic-laddie being the whole of the gunk-dev instance today is a fact about
58deployment, not about the design. A policy field on a host would therefore be a policy field on _one
59of several_ possible carriers of the same instance, free to diverge from its siblings with neither
60one wrong — the same defect that rules out putting a project's policy in a place the project does
61not control at all.
62
63## The fork: which layer owns what
64
65### Option A — the instance layer owns all of it
66
67Every project's classes and required checks are declared in the instance repository, and a project's
68own tree says nothing.
69
70Changing a project's policy is a change to a different repository. No contributor to a project can
71change that project's checks; only whoever can land in the instance repository can. A fresh clone
72knows nothing on its own — clone the project and there is no way to say what its changes must pass
73without asking the instance.
74
75The cost is the one that matters: policy is not versioned with the code it gates. A change that adds
76a check and the code needing that check cannot land together — they land in two repositories, in an
77order nothing enforces.
78
79### Option B — the project layer owns all of it
80
81A versioned CUE document in the project's tree, and nothing anywhere else. This is the plainer
82reading of [[ida-1ec03b1]]'s "versioned in-repo", and it is the direction [[ida-3e87f5c]]
83([ida-3e87f5c-self-describing-projects.md](../ideas/ida-3e87f5c-self-describing-projects.md))
84already adopted: a project's declaration travels in its store, and instance config shrinks toward a
85serving list.
86
87Anyone who can land a change in the project can change its policy, and that change goes through the
88policy in force before it. A fresh clone knows everything: the policy document plus the repository's
89own checks say exactly what a change must pass, offline, with nothing else contacted. Checks travel
90with the code that needs them, so adding a check and the code it covers is one commit.
91
92The enforcement question is sharper here and is worth stating plainly. At push time an in-repo
93policy lives in the tree being pushed, which is to say it is supplied by the change being gated; a
94`pre-receive` hook reading it would let a change weaken its own gate. The integrator does not have
95that problem, because it already holds both trees and can read the policy at the target ref's tip —
96the policy that is already integrated. Weakening then takes two landings: one that changes the
97policy under the old policy, and then the change that wanted the weakening. That is the right shape,
98and it is another reason integration-time enforcement beats push-time enforcement, consistent with
99the one structural invariant in [contribute.md](../../design/contribute.md).
100
101What Option B alone cannot do is let the group insist. A project whose policy document goes empty —
102or never had one — is served exactly as before, and nothing notices. For cosmo that is the whole
103problem restated: a gate a project can remove by editing its own repository is weaker than the
104branch protection it replaces.
105
106### Option C — split, by force rather than by subject
107
108Both layers are the same schema and the same kind of document. The instance layer states the
109minimum: the checks no project in the group may decline, and the templates that give a project of a
110known type a sensible starting set. The project layer states everything else. They compose by
111unification, which can only narrow, so the floor is a floor by construction: the project layer can
112add to it and cannot subtract from it.
113
114The split is not "the instance says whether, the project says what". Both layers say what; they
115differ in whether a project can answer back. That is what keeps the two halves from being two
116vocabularies to learn, and what makes the composition a single `cue vet`.
117
118The risk is the floor growing. A floor that keeps absorbing checks until it describes every class of
119every project is Option A wearing Option C's clothes, and the discipline is to keep the floor the
120minimum a group is willing to enforce on projects it has not read.
121
122## Recommendation
123
124Option C, with the weight in the project and a deliberately small floor.
125
126Four things follow from it and should be read as part of the recommendation.
127
128### Mandatory versus overridable is one bit per check, in CUE's own semantics
129
130This is why CUE suits the model rather than merely carrying it. Unification can only narrow, so the
131_form_ of a value decides whether a project can answer back, and the schema needs no flag it would
132have to interpret.
133
134- A **concrete** constraint from the floor — a check required with the value `true` — cannot be
135 unset. A project supplying `false` conflicts, and `cue vet` fails naming the field.
136- A **template default** — written as the disjunction `bool | *true` — is overridable. It reads as
137 `true` when nobody says otherwise, and a project supplying `false` unifies cleanly to `false`.
138- **Open structs** mean a project may always add classes and checks, and can never remove the
139 floor's.
140- **Project-type templates** are policy fragments a project selects by name and then narrows, so a
141 project that is an ordinary instance of its type works with very little configuration and can
142 still override the non-mandatory parts or define its own.
143
144### The schema shape follows from that, and it is not the shape the first draft had
145
146CUE unifies lists positionally and requires equal length, so two lists that were written
147independently simply conflict. Every part of the policy that has to compose across the two layers
148therefore cannot be a list.
149
150The path classes are keyed by class name rather than held in a list of class values. A class's
151required checks, the `unclassified` set, and a class's path patterns are all sets written as structs
152from name to `bool` rather than lists of names. When both layers name the same class, it is one
153class: its coverage and its requirements are the union of what each layer contributed, and nothing
154either layer made concrete can be taken back.
155
156Keying a class's `paths` the same way is load-bearing and easy to miss. If coverage were a list, a
157project could rewrite a floor class's patterns wholesale; keyed and concrete, a floor class's
158coverage cannot be narrowed to a path the project never touches, which would otherwise escape the
159floor everywhere else.
160
161### Forcing comes from the floor's provenance, not from CUE
162
163Unification on its own forces nothing. A project that vendored a copy of the floor into its own tree
164and edited the copy would unify perfectly well; the copy is simply not the floor. What makes a floor
165a floor is where it is read from: the instance repository's integrated tip, never the project's
166tree.
167
168That is Option B's "weakening takes two landings" argument one level up. Changing the floor is a
169change landing in the instance repository, under that repository's own policy and its own
170integrator, and it is visible in that repository's history — which is what
171[self-transparency.md](../../design/self-transparency.md) asks of the system's own configuration.
172The schema cannot enforce this, because a schema cannot see which file a field came from. The tool
173that composes a policy is what makes it true, and the schema says so in its comments.
174
175### The two halves resolve at different times
176
177The mandatory floor resolves at head. A floor a project could pin is not a floor: pinning it would
178make every past floor permanently available as an alternative to the current one, and weakening
179would take one landing again — the project's.
180
181Templates may be pinned. They are defaults, a project can already override them, and a stale default
182costs nothing the project could not have written by hand.
183
184## The document count is free; the enumeration is not
185
186Each layer is described above as one document. That is how the example is written, not something CUE
187imposes. A CUE package unifies any number of files, and unification is commutative and associative,
188so file boundaries carry no meaning and factoring a layer across several documents is semantically
189free. Two floor documents may contribute mandatory checks to the same class and compose without
190complaint. Two documents that disagree on the same check fail at vet time, and the error names both
191files and both line numbers, so a silent last-write-wins is not possible. That is what makes
192fragmenting policy safe rather than risky.
193
194The constraint that does exist is not the number of documents but who enumerates the set. A floor a
195project can decline to load is not a floor, so floor documents are enumerated by the instance, while
196template documents are selected by the project. That is the mandatory-versus-overridable distinction
197above, expressed at document granularity instead of at field granularity.
198
199Collecting policy into a standard directory is the natural expression of it, because a CUE package
200already works that way: the directory is the enumeration, so no manifest is needed and nothing has
201to list which files count. One directory holds both layers, because CUE's definition-versus-field
202distinction does the selection. A concrete field is floor and loads unconditionally; a project-type
203template written as a definition is inert until a project embeds it. Whether a policy document is
204mandatory or optional is therefore visible in the syntax of the file itself. This repository already
205uses the same move: [.the-valley/README.md](../README.md) describes the knowledge graph as "a
206directory convention, not a system", where listing is `ls` and search is `grep` and no indexer
207exists. A policy directory is that convention applied again rather than a new mechanism.
208
209The obvious comparison is a workflow directory in a hosted forge, and it breaks in two places.
210Workflow files are independent of one another; policy files unify. A new file in the floor directory
211changes the effective policy of every project in the group. Contradictions fail loudly as above, but
212silent addition is real and has no equivalent in the workflow-directory model. The second difference
213matters more: a workflow directory has no floor. Anyone who can write it controls the checks
214completely, which is precisely what this design denies a project. So the same convention is applied
215twice with different authority — the floor directory in the instance repository, resolved at head,
216and the project's own directory in its own tree. The drop-in property is safe only because of where
217each directory lives. A project adding a document to its own directory can only narrow; a project
218able to write the floor directory would be the entire gate gone.
219
220A worked directory is at [examples/policy/](../../examples/policy/). Two floor documents contribute
221to the same `prose` class — one requiring `prose-format`, one added later requiring `link-check`,
222both pinning the same coverage pattern — and the composed class requires both. A `docs` template is
223written as the definition `#docs`, and composing the instance directory alone exports a policy with
224no `knowledge` class at all: the definition contributes nothing until the project document embeds
225it. That project document embeds it, declines the template's defaulted knowledge lint, and adds a
226`shellcheck` class of its own. A third floor document contradicting the second fails vet naming both
227files:
228
229```
230floor.classes.prose.requires."link-check": conflicting values true and false:
231 ./examples/policy/instance/floor-references.cue:19:27
232 ./floor-disagree.cue:3:48
233```
234
235## What the host-side half was for, and why it is gone
236
237The first draft sketched a field on the host declaration — `enable`, plus the source policy is read
238from — whose entire job was to stop a project deleting its own gate. That field is deleted, not
239moved. It is not needed: a project belongs to a group whether or not it declares a policy, so an
240absent or empty project policy still composes to the floor exactly. The hole the field was covering
241is closed by the floor, and closed better, because the floor also says what the project must pass
242rather than only that it must pass something. [schema/valley.cue](../../schema/valley.cue) is
243untouched by this proposal.
244
245## What the draft schema commits to
246
247Class matching is a set operation, never first-match. A change's required checks are the union of
248`requires` over every class that at least one changed path matches. Classes may overlap deliberately
249— a knowledge node is both knowledge and prose — and the union is the entirety of [[ida-1ec03b1]]'s
250"mixed takes the max" rule. There is no separate mixed case, and no ordering to get wrong.
251
252A path matching no class is answered explicitly, by a required `unclassified` field. The failure
253this document must never have is a path that quietly requires nothing, so the policy has to state
254what an uncovered path costs rather than defaulting to silence.
255
256The signature is deliberately absent. [[ida-1ec03b1]] lists it alongside the knowledge lint because
257it is enumerating what a knowledge-only diff must satisfy, but the signature is required of every
258change by the structural invariant and the integrator, whatever paths the diff touches. It is not
259path-scoped, so it is not policy.
260
261Every check name a class requires must exist in the composed catalogue. A name that does not lands
262in `checks` as an incomplete check and fails vet. Without this, a typo is not a vet error — it is a
263check that silently stops being required.
264
265## Evidence: the worked example
266
267The claims above are pinned by running `cue vet`, not by inspection. The example in `examples/` is
268two documents. The instance layer makes `prose-format` mandatory over `**/*.md` and for uncovered
269paths, and offers a `docs` project type whose knowledge lint is a default. The project layer selects
270that type, adds a `shellcheck` class of its own, and declines the defaulted knowledge lint.
271
272Both directions were run.
273
274```
275$ cue vet -c schema/verification.cue \
276 examples/verification-instance.cue examples/verification-project.cue
277$ echo $?
2780
279```
280
281The composed `policy` exports with `knowledge-lint` at `false` — the project's legitimate override —
282alongside the floor's `prose-format` at `true` and the project's own `shellcheck` class. A project
283that instead tries to unset the mandatory check fails, and the error names the field:
284
285```
286$ cue vet -c schema/verification.cue examples/verification-instance.cue unset.cue
287policy.classes.prose.requires."prose-format": conflicting values false and true:
288 ./examples/verification-instance.cue:29:29
289 ...
290 ./unset.cue:3:52
291```
292
293Narrowing a floor class's coverage fails the same way, at `policy.classes.prose.paths."**/*.md"`.
294Selecting a project type the instance does not define is an evaluation error rather than a silent
295fallback. An unknown check name, a stray top-level field, an absolute or `..` path pattern, an
296unimplemented runner, an unknown field inside a class, and a malformed name all fail vet with an
297error naming the field. A project document that declares nothing at all vets, and composes to the
298floor exactly.
299
300This example is the proposal's own evidence and nothing more. It is not the live exercise on
301qinling, which is a separate step described below. Those rejections are also not yet wired into a
302flake check, because the draft is deliberately unwired.
303
304## What this costs
305
306A project is now self-describing only above the floor, which trims [[ida-3e87f5c]]. A clone of the
307project alone can no longer state its required set; it can state what the project adds, and must
308consult the instance repository for the rest. That is a deliberate trade for the group being able to
309force compliance, which is the whole reason the floor exists. The timing split preserves most of the
310offline story: templates may be pinned, so the only thing a clone genuinely cannot answer alone is
311the current floor, and the floor is small by design.
312
313Enforcement belongs to the integrator, not to a `pre-receive` hook, so declared policy is inert data
314until Phase 3 ([roadmap.md](../../design/roadmap.md)); Phase 2 is where a contributor can first
315produce the evidence a policy asks for. And the checks a policy names are ordinary flake checks in
316the reference implementation, so a project that already has checks has most of a policy — the
317document says which ones apply where, not what a check is.
318
319## The staged path: qinling first, cosmo second
320
321Every feature built for cosmo readiness is exercised live on the gunk-dev instance, on a project
322already hosted there, before cosmo depends on it. The projects on the instance today are the-valley
323and qinling, and both are markdown-only. So the first exercisable class is knowledge and prose — the
324formatter-idempotence check this repo already ships as a flake check, plus the frontmatter and
325reference-integrity linting [[ida-1ec03b1]] describes — and not the `nix build` class cosmo
326eventually needs.
327
328qinling is also the instance repository, so the first exercise carries both layers at once: qinling
329holds the floor and the templates, and the-valley holds a project policy that composes with them.
330
331### The smallest thing that could be turned on
332
333Four pieces, none of which is an enforcement point:
334
3351. qinling gains the instance document — a floor requiring the prose format check over `**/*.md` and
336 for uncovered paths, and a `docs` project type offering the knowledge lint — and the-valley gains
337 a project document that selects that type. The example in `examples/` is written as very nearly
338 those two files.
3392. `knowledge-lint` is built as a flake check: frontmatter vetted against a CUE `#Node` schema, and
340 reference integrity — `[[wiki-links]]`, `blocked_by` ids, and relative links all resolve.
341 `prose-format` already exists in this repo and is copied or shared.
3423. A read-only deriver: given the instance tip, a project tree, and two commits, compose the policy,
343 list the changed paths, match them against the composed classes, and print the required check
344 names. It reports; it blocks nothing.
3454. The two checks are run against the trees the deriver named.
346
347### What observing it succeed looks like
348
349The standard is verified by looking, not by reviewing configuration. Reading the policy files and
350agreeing that they say the right thing is not the exercise.
351
352- A commit that actually landed in the-valley touching a knowledge node is fed to the deriver, and
353 it prints exactly `knowledge-lint` and `prose-format` — the union of two overlapping classes, one
354 contributed by each layer, observed rather than asserted.
355- A commit touching only `README.md` prints exactly `prose-format`. The knowledge lint's absence is
356 the observation; a policy that over-requires is as wrong as one that under-requires, and only the
357 second failure is loud.
358- The project document is edited to decline `prose-format`, and the deriver refuses to compose the
359 policy at all, naming the field. The floor is observed to hold against the project rather than
360 argued to.
361- A node's frontmatter is deliberately broken on a scratch branch. `knowledge-lint` fails against
362 that tree, and the failure names the file and the field.
363- A file no class covers — a shell script in a markdown-only repository — makes the deriver print
364 the `unclassified` set. The hole announces itself instead of being found later.
365
366### What cosmo additionally requires
367
368Naming these keeps the qinling exercise from being mistaken for cosmo readiness.
369
370- A `format` class over `**/*.nix` requiring `nixfmt --check`, and a build class requiring the
371 five-machine build matrix. The schema expresses both today; nothing else about them is ready.
372- An answer to check latency. Five machines' worth of `nix build` is not something a contributor's
373 machine finishes quickly, and neither layer's owning the policy changes that. It is a real open
374 question this node does not close.
375- The floor actually read from the instance repository's tip by something, rather than from whatever
376 tree happens to be at hand. Provenance is the whole of the forcing, so an implementation that gets
377 it wrong has no floor at all.
378- An enforcement point — Phase 3's integrator, or a deliberate interim. Until then this machinery
379 observes and reports, and **cosmo must not migrate onto an observation**. That is the difference
380 between qinling exercising the feature and cosmo depending on it.
381
382## Status
383
384Proposed. The direction is agreed; the decision is recorded by hand-review and integration, not by
385this branch. The draft schema is a draft: it is not referenced by
386[schema/valley.cue](../../schema/valley.cue), not covered by the flake's `cue-vet` check, and not
387read by [nix/valley-host.nix](../../nix/valley-host.nix).
388
389## Related
390
391- The design this implements: [[ida-1ec03b1]]
392 ([ida-1ec03b1-path-scoped-verification-policy.md](../ideas/ida-1ec03b1-path-scoped-verification-policy.md))
393- The group-to-instance binding the instance layer rests on: [[ida-8482624]]
394 ([ida-8482624-federation-groups.md](../ideas/ida-8482624-federation-groups.md))
395- The direction the project layer continues, and that the floor trims: [[ida-3e87f5c]]
396 ([ida-3e87f5c-self-describing-projects.md](../ideas/ida-3e87f5c-self-describing-projects.md))
397- The store the policy travels in: [[dcr-5da1f36]]
398 ([dcr-5da1f36-project-is-repo.md](./dcr-5da1f36-project-is-repo.md))
399- Why the host schema stays free of options a host cannot act on: [[dcr-0f5d9b1]]
400 ([dcr-0f5d9b1-cue-config-host-module.md](./dcr-0f5d9b1-cue-config-host-module.md))