The write foundations for the restacker, split out of the publishing slice by the 2026-10-19 brief critique: a restack append mode in rebase (exact branch equality, the active title, build-then-push for durable intent), the same split for reports, bounded subprocesses everywhere the restacker reaches, the controller git identity, a state-directory lock, and authenticated fixtures (verifier path, signing keys, the real integrator and a real reject, a distinct restacker principal, transport barriers). Enables no writes.
Comments
contributor2026-10-19 11:56 UTC
Brief for the foundations slice (oc-6cd79c6), prepared 2026-10-19:
# the-valley: the restacker's write foundations — the restack append, bounded subprocesses and authenticated fixtures
## Why
The restacker's read-only planner has landed (`valley-restacker once --report-only`, module `restack/`). The next step lets it write: publish families, append versions, write reports, recover. A critique of that step found it needs foundations first, so this slice builds them and **enables no writes**: nothing in `valley-restacker` pushes after this slice. The publishing slice that follows uses all of it.
Context: the design is the body of knot `oc-adc7b2b` and the publishing slice's notes are on knot `oc-d994dc4` (`valley knot show <id>` in this repository). What exists: `restack/` (the planner), `rebase/` (Capture, Prepare, Publish, AppendVersion, structured results), `composed/` (the composed-policy reader), `change/report.go` and `valleyhook/report.go` (reports), `valleyhook/record.go` (the `restack` transition).
## Build
1. **A restack append mode in `rebase/`.** Today `AppendVersion` (`rebase/record.go`, around lines 296–359) accepts a prepared head anywhere in the branch's ancestry, derives the title from the commit subject, and builds and pushes the record in one call. Under `restack` authority the hook (`valleyhook/record.go`, around line 264) requires the new version to keep the active version's branch and title. Add a restack mode that:
- checks inside the library that the branch on origin equals the prepared head exactly (and documents that a client-side check can't be atomic with the record push, since only the record is leased);
- carries the active version's title and branch;
- separates **building** the record commit from **pushing** it, so a caller can persist the record commit's identity and its lease before the push (durable intent for recovery).
Manual paths (`valley rebase`, review's `[b]ase`) keep their behaviour exactly.
2. **The same build-then-push split for reports** (`rebase/report.go` or wherever the report write will live): build the report commit, return its identity, push separately.
3. **Bounded subprocesses everywhere the restacker reaches:** `rebase/prepare.go`'s cleanup and `Release` (they use `context.WithoutCancel`, which drops deadlines), network commands (`ls-remote`, `fetch`, `push`), `composed/composed.go`'s context-free `exec.Command` calls (around lines 200 and 222), and `restack/main.go`'s git helpers (output waits, around line 193). Each takes a context with a deadline, and output waits are bounded. Tests: a hanging child process ends within the bound.
4. **The controller's git identity.** `restack/main.go` disables global git configuration (around line 161), and `commit-tree` (`rebase/record.go`, around line 44) and preparation need an author and committer. Add flags for the controller's commit identity, set them in its scratch repository, and test with every inherited identity variable (`GIT_AUTHOR_*`, `GIT_COMMITTER_*`, `EMAIL`) absent.
5. **A state-directory lock.** `scratchRepo` rewrites origin on each invocation (`restack/main.go`, around line 183). Lock the state directory for the whole operation (a second `once` fails clearly while one runs), and bind state to repository, target and principal, refusing a state directory that belongs to another.
6. **Authenticated test fixtures** for the publishing slice, in `nix/checks/restack.nix` and its scripts:
- a sandbox verifier path shared by the rendered hook and the controller (today `hosts.nix` points the hook at a verifier file that isn't available in the restack fixture), signing keys, and the policy and evaluator fixtures `integrator/e2e/run.sh` uses (around line 520) so the real integrator can land a change and produce a real `reject` from signed wrong-kind evidence;
- a distinct `restacker` principal holding `restack`, separate from the `requester` that files requests (a `request` holder bypasses the restack-specific rules, so tests must not publish as `requester`);
- deterministic transport barriers that delegate to the real `receive-pack` and the rendered hook, for race tests (the controller disables git hooks, so `valley-ready.sh`'s post-rewrite trigger can't be reused), and a dropped-acknowledgement helper adapted from `rebase/rebase_test.go`.
Prove each fixture works with a small test: the integrator lands a change and the planner sees it submitted through integrator evidence; a real reject is classified from a real outcome; a barrier holds a push and releases it.
## Tests
- The restack append: refused when the branch moved past the prepared head; carries the active title when the commit subject differs (use a change whose title differs from its commit subject); build-then-push leaves an identifiable commit before the push; the hook accepts the result as the `restacker` principal and refuses a forged title.
- Bounded subprocesses, identity, and the lock, as above.
- The fixtures, as above. The planner's existing `restack-e2e` scenarios keep passing.
Checks, each one at a time with `nix build --no-link .#checks.x86_64-linux.<name> -L`: `restack-unit`, `restack-e2e`, `rebase-unit`, `valleyhook-unit`, `protect-e2e`, `integrator-unit`, `integrator-e2e`, `valley-ready`, `valley-go-unit`, `own-policy`, `prose-format`, and any check the policy requires for the paths you change. Never `nix flake check`.
## Constraints
- **No writes from `valley-restacker` yet**, and no schema, policy-format or report-format change (bug `bd-5859932`); if you think one is needed, stop and report.
- Platform logic in Go; Bash only as thin glue in tests. No new third-party Go dependencies.
- Never run a tmux command against the shared server; if a test needs tmux, use `env -u TMUX tmux -S <a socket under your scratch dir>`. Don't leave `go build` output in module directories.
- Docs: only where behaviour visible to users changes (the controller's new flags), in "The restacker" section of `docs/architecture.md`, present tense.
- Vocabulary: a change is ready, approved, submitted; it requires checks. No attribution lines in commits.
## Delivery
Push your topic branch to origin; never push main. Report: the restack append API, the build-then-push split, each bounded call site, the identity flags, the lock, each fixture and the test that proves it, and each check's result.