gunk-dev/the-valley
the-valley:oc-0f74615outcomeopen

An author asks the worker for a commit's checks, so agents don't build them too

State
free to start
Created
2026-11-08 by contributor
Progress
6 of 10 done
Children

Body

An agent builds every check its change requires before it pushes, and the host's check worker builds the same checks again once the change is ready. In runs since 2026-10-20 that built the full required set, the agent spent a median 17.9 minutes on it, 40% of its working time. Per-check times match the worker's for the same head (`worker-e2e` 637 s in the agent, 494 s on the worker), so nothing is reused: for one change the agent spent 22.4 minutes on 26 checks and the worker 21.8 build-minutes on the same head. The worker reaches a ready change in a median 2.8 minutes.

Outcome: a change's author can ask the host's worker to build a draft's required checks, and reads the results from the change as for a ready change: each check passed or failed, and a failing check's log tail. An agent builds only what it needs to iterate, pushes, and waits for the worker. A draft's results carry to the ready version at the same head.

Boundaries:
- A draft's results grant nothing on their own: landing still takes a ready version and an approval.
- Ready changes have first claim on the worker's capacity.

Related: oc-3d9f593 (a change's check runs and logs are part of the change).

Comments

  1. contributor2026-11-13 00:13 UTC
    Decided: the worker builds every draft's active version when no ready change waits on it; the author does not ask. An ask would need a verb and a record field, and every agent would ask every time. Ready changes keep first claim on capacity. A build design is being written; it will be added here.
  2. contributor2026-11-13 00:22 UTC
    Build design (written by a second model against 1ca8baa, answering ten set questions):
    
    1. Order ready batches, follow runs, then draft batches. In `status/worker.go`, change `scan`, `gating`, `jobBefore` and `admit` so drafts start only after a complete scan finds no runnable ready or follow job and neither kind is running; retain first-seen ordering within each class. When higher-priority work appears, stop unrelated draft batches through the `stopSuperseded` cancellation path—even with a spare batch slot, because `--slots` is per batch and `attest/admit.go` admits evaluations FIFO against shared memory. Keep slots and destinations held until cancellation completes; running follow runs retain their existing finish policy.
    
    2. Stop an obsolete draft batch at the first complete scan of its project that finds its active head replaced, withdrawn or gone, unless another eligible active version still needs that tree. Generalize `stopSuperseded` and `wanted` in `status/worker.go` to include drafts; a same-tree promotion to ready keeps useful work running at ready priority, while preemption and supersession record cancellation, not failure.
    
    3. Suppress another draft attempt until its head or effective composed policy changes, including failures during evaluation or process startup. Keep this in private `failures.json`, using a distinct draft key containing the head and `jsonChecks.PolicyDigest`; presence means “waiting for changed input,” not a distant retry date. `assess`, `complete` and `prune` must preserve it across passes and incomplete scans; ready work ignores draft suppression and uses ordinary backoff, while failed pushes retain their existing object-keyed retry.
    
    4. Add no age or count bound. Successful trees already have coverage, failed inputs become suppressed, and concurrency remains bounded; the real recurring cost is scanning and deriving every draft, so have `project` read one policy model and use `deriveUnder`, following `addChecks` in `status/versionchecks.go`, rather than repeating `derivedChecks`’ policy read for every change.
    
    5. Derive over `merge-base(origin/main, active head)` and build that recorded head, with both policy layers resolved from main as `worker.change` and `policyLayers` already do. Neither `change`, `assess` nor `coverageOf` requires ready state internally; the ready assumptions are principally selection in `pendingChange`, `project`, `gating`, `stopSuperseded` and the status readers. Draft preparation must not silently restack the head.
    
    6. Reuse the existing wake marks. `wakeHook` in `nix/valley-host.nix` already marks pushes to worker projects and the instance project—including change records and source heads—except knots and integration bookkeeping; integrator landings and changed signer publications also mark, and `valley-worker.path` starts an inactive worker. For an active pass, replace `markPoll` with standard-library Linux inotify notification using the pattern in `integrator/wake_linux.go`, preserving `status/wake.go`’s claim-before-read protocol; retain the recovery interval for lost marks and remote policy changes that produce no local event.
    
    7. Extend the shared change-results reader, rather than adding another checks command. Today, `pending --drafts --checks` prints draft blocks without check results because `addChecks` selects only `pendingChange`; `checks <change>` treats its argument as a base commit against HEAD, not a change selector; explicit `review <draft>` shows the draft and diff, offers viewing/skipping, and gets no check line because `activeChecks` excludes drafts.
    
       Have `addChecks` cover active unlanded drafts in both listing arrays and let `activeChecks` include them, preserving review’s approval refusal. Evidence alone is insufficient: `attest/run.go` stores nothing when any check fails, so expose an additive worker-run result beside the existing evidence state, with per-check outcomes and available log tails. Use a small structured completion summary from attest, retained with suppressed failures and exported through existing worker state; clients can read `pending --json --checks`, wait through the existing telemetry stream, and reread the change after relevant events. Missing diagnostics must say unavailable, not remain indistinguishable from queued work.
    
    8. Record an immutable admission class—ready, follow or draft—in batch start/end records, publication records and exported attempts in `status/workertelemetry.go`. Keep project, change, version, head, tree and `attest_run`, which already join evaluation/build timings and logs; record preemption distinctly from supersession, and report draft suppression as waiting for changed input rather than timed backoff.
    
    9. Add cases to existing Nix checks, with Go harnesses, scratch repositories and their own origins:
    
       - `valley-go-unit`: class ordering; preemption with one batch and with spare batch capacity but occupied evaluation capacity; same-tree promotion; supersession; suppression across restart, clock advance, head change and either policy-layer change; incomplete-scan retention.
       - `attest-unit`: structured outcomes for mixed results, evaluation failure and unavailable results after interruption.
       - `valleyhook-unit` and `valley-ready`: draft creation/append, ownership and lease refusals, and preservation of restack’s ready-only authority.
       - `valley-request`: draft evidence cannot land a draft; readying the same head reuses it without another build; approval remains necessary.
       - `worker-e2e`: timer-disabled draft publication wakes the worker; ready work cancels a blocked draft and releases its Nix processes and evaluation reservation.
       - `telemetry-e2e`: draft JSON outcomes, failing log tail, class attribution, and unavailable diagnostics without observing authority.
    
       Use event-controlled builders and observable completions, not fixed sleeps; unchanged unit wiring needs no additional VM configuration test.
    
    10. Land the pieces in this order: draft-record gate support, then its client writer; structured completion results and diagnostic export; draft-capable status readers; wake notification; scheduler classification, suppression and preemption; finally automatic draft selection. Each preceding piece can land independently and remain harmless with draft selection disabled in the code—no operator flag is needed—and the final enabling change depends on all of them. Records and evidence belong in project storage because they describe versions; scheduling failures remain private worker state, diagnostics use the existing export, and mechanisms and documentation belong in the source.
    
    The largest prerequisite is draft publication: `checkCreate` and `checkNewVersion` in `valleyhook/record.go` currently require ready state, and a plain push does not advance a draft’s recorded version.
    
    Two existing constraints also matter. `assess` refuses to extend an already-published worker ref, so a policy change adding checks can still leave a tree incomplete; fixing that needs append-preserving publication, already used by follow runs. Diagnostics require existing telemetry access and have bounded log retention.
    
    Finally, `reap` currently admits from an old queue and `complete` publishes synchronously. Lower-priority admission must wait for the completed scan, and a successful draft racing cancellation must defer publication until ready admission is served; otherwise the promised delay bound can be exceeded by scanning or pushing rather than stopping the batch.
    
    
    Cuts made to this design before building:
    - No hook change. A draft's version exists today because a client readies a head and then unreadies the change; the worker builds that active version. Creating a version as a draft directly is a separate question.
    - No new structured result export from attest. A draft's results are read as a ready change's are; if a failed draft check cannot be read that way, that is found by the reader piece and filed.
    - Wake marks stay as they are; replacing the active pass's poll with a notification is its own knot if wanted.
    - Only a ready change's job stops a running draft batch. A follow run waits for it, as it waits behind a ready batch today.
    
    Pieces: the worker builds drafts (scheduler class, stop on a ready job, stop when the draft moves, a failed draft waits for a new head or policy); the readers show a draft's checks (`pending --drafts --checks`, `--json`, review's checks line). Clients then stop building the full check set themselves.
  3. contributor2026-11-13 20:28 UTC
    Direction changed. The worker will not build every draft. An author asks for a commit's checks with one blocking command, outside the change state machine: a request ref names the commit, the worker builds it behind ready changes and follow runs with no preemption, and the evidence, being about the tree, is reused when a ready version holds the same tree. The author stays in the loop: the command returns the failed checks, the author fixes and reruns, and hands over a change whose checks have passed.
    
    Why: building every draft meant ready changes had to interrupt draft builds, and that took four review rounds without converging (see oc-bc93c8f). With an explicit request the set is bounded by intent, so a plain queue order is enough. A new change state for "finished, awaiting review" was considered and set aside: the request touches no state, and required reviews (oc-83acfae) later express that state.
    
    oc-bc93c8f is not being built further; its change stays a draft until the replacement lands and is then withdrawn. oc-ebb5526 (landed) and oc-c0ba95b still serve this: they are how results and failures are read. A build design is being written.
  4. contributor2026-11-13 20:36 UTC
    Build design for author-requested checks (written by a second model against main at 6bf8ca4, answering ten set questions):
    
    1. Use project storage: `refs/the-valley/check-requests/<principal>/<worktree>/<attempt>`, pointing directly at the requested commit. Keep a random worktree token in its individual Git directory, generate a fresh attempt token per invocation, and atomically replace that worktree’s previous request using explicit leases; a worktree-local lock prevents concurrent invocations. This mirrors the direct commit in `integrator/refs.go:requests` without a record format, while making a same-commit retry visible even when the worker misses the intervening deletion.
    
    2. Allow any authenticated named principal to create, replace or delete requests under its own principal prefix; allow `approve` holders to delete others for cleanup, but give the worker no additional deletion power. Extend `valleyhook/policy.go:decide` to validate the exact name shape and require an actual commit through `repository.kind`, retaining symbolic-ref, lookalike and protection checks. In `preReceive`, enforce a documented soft limit of 32 outstanding requests per principal per project, accounting for the whole push; concurrent pushes can exceed this, as with the existing record bound.
    
    3. The existing `nix/valley-host.nix:wakeHook` already marks request creation, movement and deletion: its catch-all covers this namespace. In `worker.project`, use `listOrigin` for the exact request prefix and `fetch` the listed object IDs, sorting valid requests by name and reporting malformed ones separately, as `integrator.requests` does. Keep this listing local to the worker; adding requests to `rebase.InventoryPatterns` would unnecessarily expose them to unrelated readers.
    
    4. Add a request identity and a three-way job class to `status/worker.go`; reuse `policyLayers`, the merge-base derivation in `change`, `assess`, and the existing destination lock. Make `project` bypass its quiet-main shortcut when requests exist or request batches run; make `scan` select ready work, then follow work, then requests, admitting requests only when higher classes have neither runnable jobs nor running batches. Keep `order`’s existing ordering and destination deduplication, using request names as their tie-breaker. After a complete project read, stop a request batch whose ref disappeared or changed only when no assessed ready version holds its tree; keep `wanted` specific to ready versions for that decision. Add no preemption, admission gate, stored-ref deferral or persistent queue.
    
    5. Add `valley checks --build`, initially accepting only HEAD and rejecting derivation overrides; ordinary `runChecks` reads possibly stale local main, so this mode must fetch origin’s current main before deriving. Capture a worker telemetry cursor before publishing, then reuse `telemetry.Request`’s bounded `follow` operation through `sshCommand`, rereading origin’s evidence and request state on relevant records and at stream renewal; distinguish failures by project, tree and run, excluding completed failures preceding this attempt. The collector’s `follow` already polls its files once per second, so this adds no client polling interval; there is no remote filesystem notification interface to reuse.
    
       Wait for batch completion before reporting failure: verified notes establish passes, and the separately landing worker report establishes failed checks or failed batches. A readable stream without a matching result means pending; refusal, malformed output, missing worker source or a broken connection means “worker status unavailable”, prints `see: valley telemetry read --source worker`, and exits 1 rather than marking checks failed. Delete only this invocation’s request, with an expected-object lease, on success, failure and interruption; use a separate bounded cleanup context, report cleanup failure, and follow the existing interrupt status of 130.
    
    6. Before creating a request or requiring telemetry access, derive the required set and check origin’s coverage; an empty set or complete coverage returns success immediately. Reuse `derivedChecks` and `coverageOf`, while preserving read failures as errors. As with `worker.change` and `versionchecks.checkStates`, command-runner checks remain outside the worker: list them as requiring approval execution, never as remotely passed.
    
    7. Persist a terminal failure marker for each request ref/object in the existing `failures.json`, independently of ready/follow build backoff; retain it until a complete listing observes that ref changed or absent. This needs a small change around `complete`, `assess` and `prune`, because today’s tree/check key retries after a deadline and can be forgotten when requirements change. A leaked request retains its commit and costs subsequent listing/derivation/coverage reads, but a failed request does not repeatedly build; the admission bound and replacement on rerun bound ordinary leaks without expiry, worker deletion or another cleanup job.
    
    8. Put `class: ready|follow|request` on both batch records and their exported attempts in `workertelemetry.go:begin/end`, retaining project, head, tree and attest-run identity. Update `checkcost.go:parsePage` and `mainstate.go:mainLines` to identify follow runs by class and run association: both currently infer main activity from an empty change ID. Preserve interpretation of older records, and omit change/version arguments when launching request attestations.
    
    9. Under `valleyhook-unit`, test ownership, administrative deletion, malformed names, non-commit targets, protection and quota refusal. Under `valley-go-unit`, test class ordering, unchanged failure suppression across passes and restarts, same-head reruns, movement/deletion cancellation, ready-tree preservation, stale telemetry and unavailable telemetry. Extend `valley-request` with a Go-driven path through the packaged command, rendered hook and worker, then ready and approve the same tree and prove evidence reuse without rebuilding; include failure and interrupt cleanup. Use scratch repositories with their own origins and channels, pipes or observed events for synchronization; update `valley-cli` and run `prose-format`, without adding another VM scenario.
    
    10. Land the pending worker-result report first, including batch failures and project/tree matching. The hook, worker, command, class handling and tests can then be one change; deploy host support before using the command. Approval, integration requests, integration outcomes and change records need no implementation changes.
    
    The principal risks are existing constraints. `assess` refuses to extend an incomplete worker attestation already on origin; a request must surface that as a terminal diagnostic instead of waiting indefinitely. `attest/run.go` publishes no notes when any check fails, so otherwise successful siblings must say “batch failed; evidence unpublished”, rather than inventing individual test failures. Scheduling preference applies to runnable work—existing backoff can permit lower classes—and requests can starve.
    
    Print `see: valley telemetry read --source worker --logs` for build failures, but document that `collector.read` returns only eight recent log tails; exact retrieval of an arbitrary retained run is not built. Likewise, telemetry retention gaps can leave an unknown result: without an outcome record, reliable completion cannot be promised across diagnostic loss.
    
    Can authors hold the existing host-wide `observe` grant? That is the one access assumption this design needs; project-scoped diagnostics would be a separate mechanism.
    
    Build order chosen: (1) the host side, which needs nothing else: the hook admits the request refs, the worker builds them as a third class, telemetry names the class; (2) the command `valley checks --build`, after (1) and after oc-c0ba95b, whose worker report it reads for failures. Authors need the host's observe grant to see a failure; an outcome record that removes that need is left to oc-3d9f593.