Slice 3 of touch-signed approvals. With an approval key selected (environment or flag), `valley approve` and the approve step of `valley review` sign the approval statement and publish the note beside the request, with leases; with none selected they behave as today and say no signed approval was written. One change per signing. Nothing is enforced. The brief is the next comment.
Comments
contributor2026-11-15 14:18 UTC
# approve and review publish a signed approval note when an approval key is selected
Slice 3 of touch-signed approvals. Base on current origin/main. Read `guidance/house-rules.md` and `AGENTS.md` first.
This brief has two parts. **Part 1 holds decisions and corrections that override Part 2 wherever they disagree.** Part 2 is the design text and the verified file map.
## Part 1: decisions, scope and corrections
**The rule that matters most.** With neither the environment nor a flag selecting an approval key, both entry points preserve every existing path and exit status, add only one plain line saying no signed approval was written, and perform no approval-specific validation, device access, publication read or ref handling. Today's unsigned path accepts names with no recorded version and missing Nix evidence (`status/approve.go` near 715 and 849); it keeps doing so. Add unsigned regression tests for both entry points, including an unrecorded name and a publication with absent or malformed approval fields.
**Everything approval-specific is conditional on a key being selected:** building the statement, key and membership and hardware validation, reading approval authority, refusing on a changed, missing, malformed or unreadable publication, signing and self-verification, the recorded-version prerequisite, and approval-ref leases and lookalike checks. Extend the publication reader (`status/signers.go` `readSigners`) without making approval fields required for its existing consumers.
**Once a key is selected and signing cannot complete,** nothing is published for that change, and the client never falls back to an unsigned approve or a weaker key. Causes: key not in the published list; hardware required and the key is not in the hardware list; device absent; PIN cancelled; no touch; publication missing or malformed; self-verification failed; the change has no recorded version (say to mark it ready first).
**Key selection.** `VALLEY_APPROVAL_KEY` names a software key file. `VALLEY_APPROVAL_PIV` names the hardware slot; the default slot alone does not select PIV, the variable or flag must be given. `--approval-key FILE` and `--approval-piv` override the environment for one command; a flag beats the environment; the two kinds are mutually exclusive at each level. The evidence key variable (`VALLEY_ATTEST_KEY`, `status/approve.go` near 1179) is not reused and gains no meaning. Default: the environment's selection, otherwise none.
**Scope cut: one change per signing.** This change signs in `valley approve` for its one name and in the approve step of `valley review` for each change it approves, opening and closing the device for each. Not in this change: `valley approve` taking several names, sharing one device session across approvals, partial-list handling and their tests. Ignore Part 2 where it describes those.
**Corrections to Part 2.**
- The statement's `project` is the canonical origin repository basename minus `.git`. The publication holds no project registry, and `signer-projects` restricts evidence, not approvals. No alias handling.
- For the record commit: return the existing recorded wrapper from `versionsOf` (`status/changes.go`), freeze its commit together with the selected version and head, and keep later validation separate. It is where the observation came from; add no field to the change record and no readiness flag.
- Whether hardware is required comes from the existing composed-model read; `derive.Result` does not carry it today, so obtain it from that read without inventing a second source.
- There are no open forks: unrecorded changes get no signed approval, and names are canonical.
**The operator's manual test.** Do not use the three-change test in Part 2. In your report, give the exact commands for one real-device approval of one disposable ready change with `--approval-piv`, the expected prompts (PIN, then touch), the command that lists the published approval ref by its exact name, and the command that verifies the note's signature against the published hardware list; then the same change approved again without touching, expecting a refusal and no change to the ref. Real-device behaviour is not verified by the checks; say so.
**Verification.** Use `valley checks --build` to build the checks this change requires on the host's worker and wait; do not also build them all locally. When a check fails, run the `nix log` command it prints (or the worker output it points to), fix, and run it again. Build a single check locally only to iterate on that failure. If `valley checks --build` cannot establish a result for a reason that is not your change, say so in the report and fall back to building the listed checks one at a time. Report how this went: it is a trial of that workflow.
**Constraints.** Go standard library only; no Bash logic; the platform is impersonal (no hosts, people or deployments; neutral examples); docs one voice, present tense, no history, no knot IDs, never describing unbuilt behaviour as existing; untrusted text escaped; one commit or a final summary commit describing the whole change; Change-Id trailer kept; no attribution lines; never a full `nix flake check`; never touch a shared tmux server. If carrying this shape costs much more than expected, or needs a concept this brief did not name, stop and report.
## Part 2: design text and file map (verified against 69d7bae)
The missing capability is client approval signing: the operator’s key must authorize the recorded head the operator reviewed, independently of check evidence. Hardware-only approval remains a deployment choice; approvals have no expiry.
All implemented claims below are verified against source at `69d7baef1f04a5306064bd92704f7d837475e57a`. Proposed work is **not built**. Tests were not run.
The source holds enrollment, policy and project declarations. Project storage holds the public authority snapshot and version-specific approval blobs. The operator selects and holds the approval key locally; agent runners receive none. Reject reusing `VALLEY_ATTEST_KEY`: evidence signing and human approval are separate powers. Request refs still name heads; readiness, `seq`, check requests and `retainChangeRecords` acquire no approval meaning.
Sign an ordinary Ed25519 note containing exactly the canonical statement: `the-valley/approval/v1`, then `instance`, `project`, `target`, `change`, `version`, `head`, `record`, `principal`, `issued`. Obtain instance from the pinned publication’s `instance-id`; project from the published project name matching origin’s repository basename minus `.git`; target from `recordTarget` (`main`); change from the resolved bare ID; version/head from the selected recorded version; record from the same observed record commit used to read that version; principal from the published entry matching the complete public key; issued from the client clock, UTC whole seconds. Prefix head/record with `git-sha1:`. Freeze these inputs; never substitute an active/restacked head. Include no expiry, policy digest, `seq`, result, delta or carry field.
Add mutually exclusive `--approval-key FILE` and `--approval-piv` to both entry points; default to no selection. PIV slot defaults to `9c`, with an optional reader selector. Parse software keys or open the packaged PIV session; require unambiguous principal membership in `approval-signers`. When composed `approval.hardware` requires hardware, require matching membership in `approval-signers-hardware` too. Missing selection, unknown/ambiguous key, missing authority, absent device, cancelled PIN, untouched device or failed self-verification refuses publication. Never downgrade or retry a rejected PIN.
Read both authority files and `instance-id` from one fetched publication OID. Empty lists revoke authority. Refresh before approval; recheck before pushing and refuse observed publication changes. Missing, malformed or unreadable publication refuses. An unchanged remote publication can still be stale: the accepted missed-wake window supplies no freshness proof. Describe membership as published eligibility; slice 4 independently reads host authority.
Use one signing path for approve lists and review traversal, sharing a device session. Keep `--head` single-change-only. Show the reviewed diff and approved head’s clean-merge contract; put principal, fingerprint and hardware membership behind `--verbose`. Preserve immediate filing with missing Nix evidence, `--build-here` and command checks. After checks, sign/self-verify, revalidate readiness and frozen-head membership, then atomically publish the note blob, request and new evidence. Lease `approval.Ref(target,id)` against absence or its observed OID; lease every changed request. Include approval refs in lookalike checks. Git omits unchanged requests: reread after pushing, report consumption/unknown, never recreate them. Atomicity covers updated refs; the record race remains for slice 4. Failure/cancellation preserves completed approvals, reports the remainder and closes the session.
Reuse implemented code: `approval/statement.go:100` `Statement.Encode` and `:150` `Parse`; `approval/sign.go:27` `Sign`, `:89` `Verify`, `:115` `ParseKey`; `approval/piv.go:76` `OpenPIV`; `approval/cmd/approval/main.go:126` `sign` implements `approval sign --piv`. Bounds are 1024/2048 bytes (`approval/statement.go:54`). `status/approve.go:692` `approval.attempt` owns checks/publication; `:905`/`:978` handle atomic pushes/unchanged requests. `status/review.go:912` `review.approve` delegates there. `status/signers.go:254` `readSigners` pins publication objects but omits approval fields. `status/changes.go:288` `versionsOf` discards the observed commit: retain it. `integrator/signers.go:341` `signersTree` publishes the additions; `:126` `publishSignersWith` contains the reread limit. Reuse `approval/ref.go:18` `Ref`, `valleyhook/approval.go:39` `checkApproval`, `valleyhook/record.go:185` `checkRecord`, and `rebase/outcome.go:22` `ParseOutcome`.
Not built here: integrator enforcement/consumption and ready-history verification (slice 4, shipping off), activation (slice 5), landing enforcement of carry modes, preparation, batching several changes under one signature, or signing over SSH/web/apps.
Extend existing `valley-go-unit`, `valley-request` and `valley-walk` checks with software keys and a Go fake device: verify published fields/signatures, both entry points, missing checks, command failures, key/publication refusals, record movement, stale leases, hook rejection, unchanged-request consumption, cancellation and partial lists. Use event synchronization and Go drivers behind shell glue. Keep signer tests in `approval-unit`. Update module dependencies, package wiring with a pinned PIV helper path, CLI help and guide.
One manual test: with an enrolled PIN-ONCE/touch-ALWAYS key and three disposable ready changes awaiting evidence, set `C1`, `C2`, `C3` to their full IDs. Run `valley approve --approval-piv "$C1" "$C2" "$C3"`. Confirm displayed heads; touch twice, withhold the third. Expect one PIN prompt, two approved verdicts, then `⊘` and nonzero exit. Run `git ls-remote origin "*/main/c-$C1" "*/main/c-$C2" "*/main/c-$C3"`: expect request/approval pairs for the first two and neither for the third. Real-device behavior is **not verified here**.
Use Go standard library only, existing packaged PIV support, no Bash logic, neutral examples, scratch builds, and documentation in one voice and present tense, without history. Run `prose-format`; list checks with `valley checks --names origin/main HEAD`; run Nix checks one at a time.
Open forks: should unrecorded changes retain unsigned approval? Recommend refusal with `valley ready` guidance. Should project aliases require an override? Recommend canonical origin names initially; `project()` is only a display-name reader (`status/changes.go:356`), not authoritative alias resolution.
contributor2026-11-15 14:56 UTC
Independent review of 810cfb2 (run 20261115-1418-1ef66d63, 33 min, $9.08; 18 files +1262/-57; valley checks --build refused twice for lack of an observe slot, so the agent built 21 checks locally). NOT READY: two blockers (CLI depends on the Linux-only PIV signer on every platform; a note can replace another approver's note beside a request it does not match) and three should-fixes (helper not stopped on SIGTERM; publication errors unescaped; docs claim PIN and touch unconditionally). Fix round launched; for the second blocker the brief prefers the hook refusing a note that does not match the request beside it.
Opt-in signing preserves the established approval flow while reusing the existing statement format and signature verification. Freezing the selected version and rereading authority after signing protects against changes during the touch.
NOT READY. Static review of 810cfb2 against 273a801 only; no builds, tests, or device operations performed. Citations use new-side line numbers.
Blocker — nix/packages.nix:180: The unconditional linker reference makes every CLI package depend on piv-signer, including the advertised aarch64-darwin package. That helper includes sys/prctl.h and uses prctl, ppoll and SIGPWR without platform guards. Installing the CLI on macOS therefore requires building Linux-specific C code and fails, even for users selecting no approval key. The client closure also gains the helper, patched libykpiv and pcsc-lite dependencies.
Blocker — status/approve.go:952 and status/approve.go:1000: The request and approval are read separately, and an already-matching request is omitted from the push. Concrete race: this invocation signs head A and reads request A; another approver atomically publishes request B and note B; this invocation then reads note B, leases against it, and successfully replaces it with note A. The final request reread reports refusal, but origin already contains request B paired with note A, and B’s signed approval has been overwritten. Atomic push cannot protect a ref omitted from its transaction; merely including an unchanged refspec is insufficient because Git can omit it too.
Should-fix — status/approvalsign.go:148: The PIV helper is started outside approval’s tracked child lifecycle. Send SIGTERM specifically to the approve process while the helper waits for its PIN: approval.interrupt finds no tracked helper and exits without running deferred Close. The helper remains blocked on /dev/tty, retaining its exclusive card connection and potentially terminal echo state. Cancellation needs to stop and await the signer before exiting.
Should-fix — status/approvalsign.go:258: Publication errors reach stderr unescaped. A malformed approval-signers entry containing terminal escape bytes in its hash field reaches note.ParseVerifierKey’s hash-mismatch error, which interpolates that field verbatim; this new output path then prints it directly. Reading the malformed publication can therefore execute terminal control sequences instead of displaying inert diagnostic text. Apply the existing oneLine sanitization to these diagnostics, including software-key errors at line 267.
Should-fix — docs/reference.md:610 and docs/security.md:157: The unconditional PIN/touch claims exceed the implementation. With approval.hardware false, a listed PIV key whose PIN and touch policies are “never” passes membership validation; approval/piv.go sends PIN mode “none” and suppresses the touch prompt, and signing succeeds without either interaction. Document prompts as dependent on the slot’s policies, and distinguish selecting PIV from requiring a touch-always key.
No nits.
The single most valuable change is to make publication of the signed note conditional on its matching request within one enforced ref transaction, including when that request is unchanged.
contributor2026-11-15 15:29 UTC
Recheck of 03c8abe (run 20261115-1456-da6465e7, 27 min, $15.95 cumulative; 29 files +1714/-106 against main). NOT READY. Closed: Darwin dependency, escaping, docs. Not closed: helper untracked while the device initialises and echo left off when the helper is killed during PIN entry; new: the hook's request lookup buffers every ref under a prefix. Pairing: the hook blocks the reported race; concurrent non-atomic paired pushes and a later request-only push can still mismatch, which is left to the gate and will be stated as a limit (coordinator's call: the client always pushes atomically, a mismatch is not an approval, and slice 2 already assigned the comparison to the gate). Second fix round launched.
The fix puts structural comparison on the host while leaving signature authority and landing decisions to the gate. It also removes the Darwin signer dependency and adds interruption cleanup and diagnostic sanitization.
NOT READY. Static review only; no builds or tests run. Changed-code citations use the supplied diff’s resulting line numbers.
Finding 1: CLOSED. nix/packages.nix:182 conditionally includes the helper on Linux; status/approvalsign.go:132 refuses PIV selection when no helper is packaged. A Darwin user selecting a software key avoids the Linux C dependency. nix/checks/cli.nix:529 evaluates the Darwin derivation and checks its system; it proves neither compilation nor execution.
Finding 2: NOT CLOSED as a transactional admission guarantee. valleyhook/approval.go:94 blocks the reported sequential race: note A is refused beside request B. Concurrent atomic paired pushes conflict through the note’s compare-and-swap. However, valleyhook/main.go:304 supplies proposed values without requiring atomic installation. Two concurrent non-atomic paired pushes can both pass: push P wins note B, push Q loses its note update but wins request C, and P then loses its request update. The resulting pair mismatches despite neither push being request-only. The added atomic-push test does not cover this.
Finding 3: NOT CLOSED. status/approvalsign.go:166 calls OpenPIV before registering the child at :173. approval/piv.go:94 starts the process and :98 waits for its initial reply. SIGTERM during blocked device initialization therefore exits without signalling or reaping that helper. Separately, killing the helper during PIN entry leaves echo disabled: ordinary cleanup at status/approvalsign.go:186 only releases the saved terminal descriptor, without restoring it. The fake-device test begins after registration and never changes terminal settings, so it misses both paths.
Finding 4: CLOSED. status/approvalsign.go:294, :303 and :356 sanitize the affected diagnostics through oneLine. An OpenSSH key type containing ESC/BEL reaches stderr as escaped text rather than terminal instructions.
Finding 5: CLOSED. docs/reference.md:610 and docs/security.md:158 make prompting depend on slot policies and distinguish PIV selection from requiring hardware. A slot with both policies set to never is described correctly; VALLEY_APPROVAL_PIV_READER remains documented beside PIV selection.
For the legitimate-push cases, valleyhook/approval.go:62 and :94 preserve the intended behavior: an authorized note without a request passes; a matching request and note pass in either input order because main.go:304 populates the complete map first; replacement matching the newer request’s recorded version passes; stale replacement is intentionally refused; deletion bypasses parsing. A restack-only principal updating the record never enters approval comparison (valleyhook/policy.go:231).
A later request-only update can still produce a mismatch. That is explicitly expected and left to the landing gate; concurrent request-only and note-only pushes also lack a shared compare-and-swap.
The new lookup is unbounded: valleyhook/repo.go:66 buffers every matching descendant. An approve holder can accumulate refs beneath an absent request name across many pushes, making a legitimate no-request approval consume arbitrarily large output. The per-push map is bounded, and note/record object reads retain their size limits; I found no unsafe note parsing.
The single most useful change is to make request/note pairing an operation enforced within one host ref transaction.
contributor2026-11-15 15:55 UTC
Final recheck of dc3c3e3 (run 20261115-1529-de92e453, 22 min, $20.51 cumulative): hook lookup closed, pairing limit stated, terminal restoration closed, no new defect. One window left: the helper is started before it is registered, so a signal in between leaves it running. Small fix round launched.
contributor2026-11-15 16:12 UTC
Last round (run 20261115-1555-99f7e4f5, 17 min, $22.96 cumulative; 4 files +111/-18): the interrupted check, the helper's start and its registration are one critical section, with a test that holds the window open. Coordinator read the code change against the recheck's recommendation and marked e19d7d5 ready. Whole change: 30 files +2032/-109; three independent passes; 25 required checks built by the agent.
contributor2026-11-15 20:45 UTC
Change valley:the-valley/orpwlyqowoxnypznpulsqkrzsqzwqzqm landed: v4 as 58e68be0d151a32d0f2bf58acf20ac4c19b204ae.
Every change the knot links has landed and it has no active children, so klaus set it done.