# Agent reviews, recorded like approvals
Agent reviews judge a change’s intent and quality against written criteria.
They are approvals of that judgment, separate from checks and from permission to land.
Human and agent reviewers use the same durable record in project storage.
Clients run reviewers; the valley authenticates, stores, and evaluates their records.
Required reviews are checked before human approval and again before landing.
The operator’s integration request remains necessary for landing.
Review carry follows change-identity design §4; check evidence keeps its separate carry rules.
This is a proposed design: new mechanisms below are **not built**. **Implemented** claims cite HEAD `25cb784084726e904cbee32745d62eec7bf57fa0`. Citations beginning `outcomes/`, `comments/`, or `bugs/` name files in `refs/the-valley/knots` at `438a5d9737afb1573c4ac40bcd4941c85f852db2`. That local snapshot was readable; its freshness against origin is **unconfirmed**.
## 1. The review record
**Decision — not built.** Store reviews in an append-only history at:
```text
refs/the-valley/reviews/<target>/<change-id>
```
Each appended commit contains one `review.note`. Its signed payload is a strict, versioned JSON record, introduced by the domain header `the-valley/review/v1`. A shared Go package handles encoding, signatures, parsing, and validation. It rejects duplicate keys, unknown fields, malformed anchors, and oversized records.
The existing signed-note envelope is an implementation starting point. It currently identifies its statements as attestations, so supporting reviews requires an explicit new domain; a review must never parse as check evidence. **Implemented:** `note/note.go:8`, `note/note.go:55`.
The record contains:
| Fields | Meaning |
| --- | --- |
| `review_id`, instance, repository, target, change ID | Identify this judgment and prevent replay into another context. |
| Change-record commit, version number, version head | Identify the version the reviewer actually read. |
| Prepared tip and result, delta digest, landing-message digest, author fields | Bind the reviewed content and the information §4 requires for carry. |
| Policy digest, registry generation, carry mode, expiry | Bind the authority under which the review counts. |
| Review name and criteria identity | Identify the requirement being judged and the exact criteria used. |
| Reviewer principal and signing-key identity | Identify the accountable actor. The model name is not a principal. |
| `verdict`, summary, notes | Record `approve` or `request-changes`, with actionable feedback. |
| Run provenance | For agents: harness version, model identifier, settings digest, input manifest, and reported usage. |
Criteria identity includes the repository, source commit, path, section selector, and content digest. The source commit records provenance. Carry compares the relevant criteria content and authority history, rather than requiring the entire source commit to remain unchanged.
Each note identifies the reviewed side—before or after—the path, blob identity, and an optional one-based line range. File-level and general notes omit line ranges. Deleted lines anchor to the before side. Clients show old notes against their original version; they never silently attach them to current line numbers.
The history’s first-parent chain preserves every judgment. Other validated links retain the reviewed change record and prepared content. Appending uses compare-and-swap against the previous history head. A concurrent append requires fetching and appending again, without rerunning the model. A stable `review_id` makes publication retries idempotent.
Add a `review` grant, enforced by the push hook and scoped to a hosted project and named review. The authenticated pusher, signing key, and recorded reviewer must agree. Neither ordinary push access nor `request` implicitly grants review authority. Ordinary review operations cannot replace or delete earlier judgments.
Human feedback uses this record too. A human review may name criteria explicitly. General operator feedback uses an `operator` review name with no named rubric and cannot satisfy `docs-style`. An `approve` review alone does not make a version approved for landing; an integration request does that.
**Why.** Notes need to reach the author without depending on a particular control panel. **Implemented:** notes currently accumulate in a local branch-named file, under the reviewed commit heading (`bin/valley:833`, `bin/valley:946`). Durable, version-bound feedback is the requested outcome in `outcomes/oc-5e509b1-review-notes-reach-the-change-s-author.md:15`.
**Alternatives rejected.** Source commits would mix operational records into the source. Knot comments would not provide the required review contract. Mutable “latest verdict” records would erase blocking judgments. Git notes are also currently closed to pushes (`valleyhook/policy.go:127`).
## 2. Policy
**Decision — not built.** Add a review catalogue and review requirements alongside the check catalogue. Proposed syntax:
```cue
floor: {
reviews: "docs-style": {
criteria: {
path: "AGENTS.md"
section: "Documentation style and verification"
}
}
classes: prose: {
paths: {
"README.md": true
"AGENTS.md": true
"docs/**": true
}
requiresReviews: "docs-style": true
}
}
```
The catalogue describes what judgment is required. It does not select a provider, model, executable, or price. Reviewer authority comes from the instance’s review grants, outside the project’s control.
Compose `requiresReviews` as a set keyed by review name:
- Concrete `true` in the floor is mandatory.
- `bool | *true` in a template is an overridable default.
- Projects may add requirements.
- Overlapping classes require the union.
- Every referenced review must have a complete catalogue definition.
Add an `unclassifiedReviews` set for paths outside all classes. Pinning a floor requirement must also pin its coverage and criteria definition. A project cannot evade the requirement by disabling a glob, changing the named criteria path, or substituting its own reviewer.
This follows the **implemented** composition of check requirements and coverage in `schema/verification.cue:80`, `schema/verification.cue:150`, and `schema/verification.cue:307`. Carry remains the strictest mode required by the matched classes (`schema/verification.cue:107`).
Read policy and authoritative criteria from integrated source. For `docs-style`, use `AGENTS.md` at the project’s target tip, selecting the named section deterministically. The initial rules are at `AGENTS.md:65`. Include the resolved criteria identity in the review authority digest.
A change editing `AGENTS.md` is judged under the existing criteria. Its proposed replacement is review data. After that change lands, the replacement governs subsequent reviews. Put criteria paths in an `exact` authority class. The floor pins where criteria come from; editing their content remains a governed source change.
**Why.** A change must not choose the rules that admit it. **Implemented:** both approval and integration obtain project policy from the target tip, with the floor supplied independently (`bin/valley:1398`, `integrator/policy.go:9`). CUE unification only protects a floor whose provenance is trusted (`schema/verification.cue:270`).
**Alternatives rejected.** A check whose command calls a model would confuse judgment with check evidence. Candidate-tree criteria would let a change weaken its own review. A flat list with project-side replacement would let projects drop floor requirements.
## 3. Enforcement
**Decision — not built.** Evaluate required reviews at both approval and landing, through one Go evaluator.
Before filing an integration request, `valley approve` reports each required review and refuses when the requirement is unmet. This gives the operator useful feedback before the approval work proceeds.
The integrator repeats the evaluation against the actual prepared result. This is the authoritative gate. A direct integration request must pass it too. Where policy requires reviews, a request without a usable change identity is refused. Every included change in a stack must satisfy its own requirements against its actual predecessor result.
| Review condition | Result |
| --- | --- |
| No eligible review | Requirement is missing; no landing. |
| `approve`, valid for the candidate descriptor | Requirement is satisfied. |
| `approve` on an older version | Satisfies the requirement only if carry succeeds. |
| Eligible `request-changes` | Blocks, even if another reviewer approved. |
| Expired, unauthorized, or otherwise stale review | Remains visible but cannot satisfy the requirement. |
| Unreadable history or unverifiable authority | Refuse to decide; never interpret it as an empty requirement. |
A moved change is not automatically stale: a clean restack can qualify for carry. Changed content needs a fresh positive review. Show the specific reason a review no longer counts.
The landing decision records the review IDs it used, the reviewed and landed versions, and any intervening landings. Extend the integrator’s decision cache to include review history, change history, policy, criteria, and registry generations. **Implemented:** its current memo tracks request head, target tip, and check evidence (`integrator/refs.go:136`).
Make the final decision race-safe. Verify the request, change record, and fixed review-history ref in the same ref transaction that advances the target. Verify absence when no review-history ref exists. A changed value causes reevaluation. Pin authority publication through the final decision; coordination across the registry and instance-policy repository needs a short host-side critical section.
This is new work. **Implemented:** the current final record read and target update are separate, with a documented race (`integrator/refs.go:476`). Repeating that pattern would allow a newly published blocking review to be missed.
**Why.** Approval-time validation improves the interface. Landing-time validation prevents stale clients or direct ref writes from bypassing policy. Current request authorization is a hook grant check, not a review evaluator (`valleyhook/policy.go:151`).
**Alternatives rejected.** Client-only enforcement is bypassable. Landing-only enforcement discovers avoidable failures late. A final reread without atomic validation cannot guarantee that a published block stops landing.
## 4. Independence and carry
**Decision — not built.** Use the same acceptance predicate for agent reviews and human approvals. Do not invent a weaker agent-only definition of a clean restack.
An agent reviewer must differ from every authenticated uploader in the change’s history. Check this when accepting the review and again when deciding whether it counts. Another model run or another signing key under the uploader’s principal does not create independence.
**Implemented:** versions record uploader principals (`change/record.go:108`). The hook preserves earlier versions and binds each new uploader to the authenticated pusher (`valleyhook/record.go:328`). However, a `request` holder can currently delete the change record (`valleyhook/record.go:194`). Mandatory review therefore requires retaining upload history and preventing deletion followed by reuse of the same identity. Unknown history cannot establish independence.
Carry follows §4:
1. Instance, repository, target, change ID, delta, landing message, and author fields remain equal.
2. Recompute the whole-file delta of the actual prepared result. It must equal the reviewed delta, with no additional changes.
3. The reviewed tip is on the candidate tip’s linear landing history.
4. Apply the composed carry mode: `exact`, `same-class`, or `same-paths`.
5. Preserve the authority inputs. Policy or registry changes invalidate carry, including changes later reverted.
6. Recheck authorization, expiry, revocation, and independence against the candidate’s complete upload history.
7. Carry eligible blocking verdicts as well as positive ones.
8. Require checks separately on the resulting tree.
These rules are recorded in `outcomes/oc-d28b43a-approvals-carry-across-a-rebase-that-leaves-the.md:56`. Criteria identity is an additional review-specific authority input. A criteria change must invalidate reviews even if the policy still names the same path.
A fresh `approve` verdict does not overwrite an applicable `request-changes`. Retrying the reviewer or restacking identical content does not clear it. A different delta moves beyond the old content judgment and requires fresh review. Expiry and loss of eligibility still follow §4; the distinction between those events and an indefinite block needs clarification below.
**Implemented:** whole-file delta encoding exists (`delta/delta.go:4`). The CLI’s clean-restack comparison is informational (`status/compare.go:1`). The integrator reads carry modes but does not enforce approval carry (`integrator/policy.go:133`). This design does not treat those components as completed carry enforcement.
**Why.** Whole-file identity preserves what the reviewer read without inventing hunk identity. Rechecking uploader history prevents a reviewer from retaining independence after uploading a later version.
**Alternatives rejected.** Head equality alone prevents useful carry. Patch-text equality misses content and mode details. The latest verdict winning would permit repeated model calls to erase an unfavorable judgment.
## 5. Running reviewers
**Decision — not built.** Clients discover review work through a versioned machine-readable interface. The valley supplies prepared inputs and evaluates stored judgments. Klaus, or another client, owns scheduling and model execution.
Extend the pending listing with required-review status. **Implemented:** `valley pending --json` already describes pending changes (`status/pending.go:59`); version listings include uploader and head information (`status/list.go:529`).
A client performs this sequence:
1. Select a ready change with a missing or stale required review.
2. Obtain an immutable review context: descriptor, criteria, diff, relevant source, and any version-bound claim-to-code checklist.
3. Run the configured reviewer with bounded input, output, duration, and cost.
4. Validate the returned verdict and note anchors.
5. Attach identity and run provenance outside the model, sign, and publish.
6. Refresh status. If the change moved, preserve the original binding and let the valley determine whether the review carries.
The model returns only judgment content: verdict, summary, and notes. It does not choose its principal, criteria digest, change version, or permissions.
**Deployment choice.** Start with a dedicated klaus review worker using its existing provider adapter. Configure the harness version, model identifier, generation settings, timeout, concurrency, and spending limits. Keep these outside the change being reviewed. A required review name identifies a rubric; it does not identify a particular model.
Klaus’s available harnesses, configured models, and provider prices are **unconfirmed** from this repository. Selecting a concrete model without inspecting that deployment would invent a fact. Before making `docs-style` mandatory, compare the configured candidate models on a small set of accepted and rejected documentation changes.
Record token usage and reported cost. Estimate cost from bounded input and output against the client’s configured price table; mark estimates separately from billed amounts. Budget exhaustion leaves the review missing. It never creates an approval or weakens policy.
Retry transport failures and malformed responses within a small configured attempt limit. Do not automatically retry a valid negative judgment. Publication retries reuse the signed result. A client job key includes the change descriptor, criteria identity, and reviewer profile to avoid duplicate spending.
In `valley review`, the operator sees:
- Each requirement, its status, and the reason it counts or does not count.
- Reviewer, criteria revision, reviewed version, and whether the judgment carried.
- Notes at their original file and line locations.
- Agent provenance and available usage information.
- A `[c]hanges requested` action that publishes feedback without deleting the branch.
- The separate human approval action that files the integration request.
Failed publication keeps a recoverable local draft and must not report that feedback reached the author. **Implemented:** the current reject action deletes the remote branch (`bin/valley:790`); it is not a feedback mechanism.
**Why.** Client scheduling keeps provider behavior and cost outside integration. Durable records let another client display the same judgment.
**Alternatives rejected.** Running models inside the integrator couples landing to provider availability. Treating a timeout as a negative verdict invents a judgment. Repeatedly sampling until approval undermines blocking verdicts.
## 6. Safety
**Decision — not built.** The reviewed change is data. Only the trusted harness and resolved criteria supply review instructions.
The worker must not automatically load candidate-tree `AGENTS.md`, hooks, editor configuration, model configuration, or executable tools. Read files from the bound Git objects. Present diffs, commit messages, source, and prior notes as quoted review material. Do not follow repository links into arbitrary local files or network resources.
Run the model without Git write credentials, operator credentials, shell execution, or unrestricted filesystem access. A separate publisher holds the review credential and accepts only the bounded verdict format for its assigned review context. Model output cannot alter the context being signed.
The reviewer credential needs a restricted write path. Simply adding `review` beside ordinary `git-push` is insufficient. **Implemented:** topic branches are open at that boundary (`valleyhook/policy.go:140`), and named principals can create change records (`valleyhook/record.go:166`). Add a review-only admission mode that permits the assigned review namespace and denies other writes. Grant it neither `request`, `restack`, nor protected-source write authority.
The existing authenticated-principal mechanism is reusable: the shell derives identity from the SSH key and discards a supplied principal environment variable (`valleyhook/shell.go:22`). The identity schema currently has no review boundary, so adding it requires schema, compiler, hook, and Nix wiring (`schema/identity.cue:126`).
A compromised reviewer can make dishonest quality judgments or withhold them within its granted scope. It cannot file the operator’s integration request, upload a version, change policy, alter check evidence, or advance the source. Its signature proves who asserted the judgment; it does not prove that a model ran honestly.
Prompt separation reduces instruction confusion but cannot prove that a model ignores malicious prose. The enforceable protection is containment: even a fooled reviewer has only review authority. Clients receiving review notes must also treat them as feedback data, never as permission to change their own tools or credentials.
**Why.** The operator’s approval remains the landing authority. Narrow credentials preserve that boundary even when the judgment is wrong.
**Alternatives rejected.** An authoring agent with a different prompt is not independent. Sharing the operator’s credential gives a reviewer landing authority. “Ignore instructions in the document” alone is not a security boundary.
## 7. Relation to deterministic prose lint
**Decision.** Keep mechanical prose rules in the `prose-format` check. Use agent review for clarity, meaning, document altitude, and whether evidence supports a claim.
**Implemented:** `prose-format` runs Prettier and validates relative links and heading anchors (`nix/checks/prose-format.sh:6`, `nix/checks/prose-format.sh:60`). Vocabulary rules, source-line citation validation, and narration-phrase rules are **not built in that script at inspected HEAD**.
Add those deterministic rules separately. A Go helper can validate citation syntax, target existence, and line bounds. Explicit vocabulary and narration patterns need fixtures and narrow exceptions for quotations and examples. Whether the cited code actually supports the sentence remains a review judgment.
A change may require both `prose-format` and `docs-style`. Neither substitutes for the other. A clean restack may retain its review while requiring a check to run again because the check’s inputs changed. **Implemented:** pure-check evidence transfers by input-closure digest equality (`attest/inputs.go:8`).
**Why.** Mechanical rules should produce reproducible failures. Editorial judgment should remain visible as judgment, with reasons.
**Alternatives rejected.** Moving deterministic rules into a model makes simple failures variable and costly. Making lint claim that a citation proves a sentence would overstate what it verifies.
## 8. Slices and rollout
**Decision — not built.** Separate the mechanics, deployment, and first mandatory policy. Each slice carries its factual claim checklist in its brief and change description, as required by `AGENTS.md:77`.
| Slice | Deliverable and acceptance |
| --- | --- |
| 1. Record contract | Shared Go record and signature package. Fixtures cover identity binding, strict parsing, anchors, retention links, and limits. |
| 2. Review authority | Review grants, compiler output, restricted admission, and append-only history. Adversarial pushes cannot write other namespaces or spoof a reviewer. |
| 3. Human feedback | Publish and read human reviews; add changes-requested feedback. Verify original-version anchors and recovery after failed publication. |
| 4. Policy support | Catalogue, requirements, composition, and machine-readable derivation. Test mandatory floor coverage, defaults, overlapping classes, missing definitions, and criteria provenance. No policy uses the new fields yet. |
| 5. Eligibility | Shared evaluator for exact-version reviews, uploader independence, authority, and conflicting verdicts. Preserve authenticated upload history. |
| 6. Carry | Implement §4 for both verdicts. Test whole-file equality, modes, intervening landings, authority changes and reversions, and later reviewer uploads. |
| 7. Landing gate | Approval preflight, integrator enforcement, decision records, cache invalidation, and atomic final validation. Test direct requests, stacks, and concurrent blocking reviews. |
| 8. Client worker | Klaus adapter, budgets, bounded retries, credential separation, and operator display. Provider failures never produce verdicts. |
| 9. Activation | Deploy compatible tools, run an advisory pilot, then land the separate policy change requiring `docs-style`. |
Extend deterministic prose lint in an independent slice. It does not need the review worker.
Before activation, verify the deployed CLI, hook, identity compiler, integrator, and other policy consumers understand the new schema. The source tree containing the schema is insufficient. **Implemented:** the CLI and integrator package their own copies (`nix/packages.nix:73`, `nix/packages.nix:493`). The previous failure is recorded in `bugs/bd-5859932-a-policy-that-uses-a-new-schema-field-blocks.md:12`.
Use a short, coordinated cutover. Avoid a compatibility migration framework for this first deployment. If activation must be reversed, change the governing policy through the normal approval path; do not add a client bypass. Keep review history intact. Do not downgrade tools below the schema required by active policy.
**Why.** Each slice has one reviewable contract. Deployment before activation prevents the new policy from blocking every landing.
**Alternatives rejected.** Introducing and using a schema field in one change repeats the recorded failure. Making reviews mandatory before the worker and operator interface are exercised creates an avoidable availability risk.
## Open questions for the operator
1. **Exactly when may a blocking verdict stop blocking without a different delta?** §4 rule 7 says that only changed content moves past it, but conditions blocking on rules 1–6, which include expiry and revocation. Recommendation: clarify this before enforcement ships. Ordinary retries and later approvals must never erase a block; exceptional invalidation should be explicit and durable, not hidden in a newer verdict.
2. **Which deployed model and budget should the first reviewer use?** Recommendation: reuse klaus’s existing provider adapter, choose a pinned model through the documentation pilot, and begin with one concurrent review per project plus explicit per-run and daily limits. No concrete model or price is confirmed here.
3. **Should documentation use stricter carry than the current default?** Recommendation: retain `same-paths` initially, with criteria paths governed as authority. Use `same-class` where cross-document changes repeatedly invalidate judgments. Existing project policy leaves unnamed paths at `same-paths` (`policy/project/policy.cue:367`).
## Risks
- **Incorrect judgment.** A false approval lowers review quality; a false block delays work. Human landing approval remains necessary, and notes must make the judgment assessable.
- **Instruction attacks.** A document can still fool the model. Restricted execution and credentials must hold even when that happens.
- **Changed context.** Identical changed files can acquire different meaning when other files move. This is an accepted carry limit, not proof of semantic equivalence (`outcomes/oc-d28b43a-approvals-carry-across-a-rebase-that-leaves-the.md:86`).
- **Incomplete authority handling.** Lost upload history, stale registry data, or a missed concurrent verdict can invalidate independence or enforcement. Mandatory activation depends on resolving these mechanics.
- **Availability and cost.** Provider outages, budget limits, and repeated stale reviews can delay landing. Status must distinguish unavailable review work from an actual negative judgment.
- **Persistent sensitive data.** Review notes and submitted context may contain private information. Store concise findings and provenance; keep secrets and unnecessary provider transcripts out of durable review records.