gunk-dev/the-valley
the-valley:oc-362886coutcomeopen

A valley runner runs jobs in systemd and microVM profiles

State
blocked
Created
2026-10-17 by contributor
Source
2026-10-13, plan.md R slice 3
Blocked by
Blocks

Body

A runner: a level-triggered reconciler on systemd, with `systemd` and `microvm` (Cloud Hypervisor) profiles; gVisor later for light reconcilers. Jobs rev 2 (`valley-jobs-design.md`) is its design input, with its executor and identity sections replaced by this milestone: jobs are declared in the scope they write to, enabled by the operator, pin their target commit and publish with a lease.

Done when a declared job runs in a microVM under its own identity and publishes a change.

Source: `plan.md` R slice 3 and Status 2026-10-12 ("Valley jobs").

Comments

  1. contributor2026-10-18 14:45 UTCedited2026-10-29 01:09 UTC by contributor
    From the coordinator's working file `valley-jobs-design.md` (moved here 2026-10-18), part 1 of 1:
    
    # Valley jobs: event and clock triggers (draft rev 2, 2026-10-12)
    
    Rev 2 takes in the Codex critique (`valley-jobs-review-codex.md`). The coordinator checked its claims against the-valley's source:
    - push grants cover the whole host (`schema/identity.cue`, dcr-0f5d9b1);
    - the hook has no ancestry check on unprotected refs (`valleyhook/policy.go`);
    - `bd-d853d9c` forbids automated bus consumers until the bus is authenticated.
    
    ## The need
    
    A valley host has no place for a program that reacts to a project's events, and none for a program that runs on a schedule (`ida-62a7a3b`). The bus publishes `ref-updated`, `integration-succeeded` and `request-stale`, and nothing subscribes.
    
    The deployment project has been canonical on the valley since 2026-10-11 (plan Status, M5 steps 1–5). Its GitHub bump bots went with switch step 1, so its bumps are by hand. The plan (2026-10-05) already settled who owns them: "Dependency-bump automation belongs to the-valley… with one request per input."
    
    Today a bump is a klaus agent. On 2026-10-11 run `20261011-1917-6b89e122` spent 49 minutes on it, nearly all in VM tests. That's deterministic work done by an agent, the case plan principle 2 says should graduate to code.
    
    **First customer:** the deployment project bumps its `klaus` and `the-valley` inputs, one topic branch per input.
    
    ## The model
    
    1. **A job is a level-triggered reconciler.**
       - It reads desired state from sources the operator designated, compares it with the observed state, and publishes a proposal that closes the gap.
       - Every run is idempotent under the concurrency rules below.
       - It reconciles at startup and on a period, so a missed wake-up costs only latency. This follows `ida-b48bded`.
    2. **Triggers only mark an enabled job as due.** A trigger never chooses a repository, revision, executable or credential. Due marks coalesce, and runs have a timeout, backoff and resource limits.
    3. **The output is a proposal behind the gate.** A job pushes one topic branch per proposal. Filing the request stays with the operator (`[a]sk`). Automatic landing waits for M1-C and its own gate.
    
    ## Scope and authority
    
    **Declaration and enforcement are separate things.**
    
    - **Declared in the scope it writes to (the operator, 2026-10-12):**
      - the deployment project's bump jobs live in its own tree;
      - instance-wide jobs (a stale-branch sweep) live in the instance repository;
      - triggers may name things outside the scope, because reading is not writing.
    - **Enabled by the operator.** The executor runs only jobs named in its own enable list, which lives in the executor's host config (for v0, the deployment's agent-guest module). A project can declare a job, but declaring it doesn't make it run.
    - **What the host enforces:**
      - the job's principal holds push only, and that push covers every unprotected ref in every project on the host (per-project push isn't enforceable over a shared git user, dcr-0f5d9b1);
      - protected targets move only through the integrator;
      - `request` belongs to the operator.
    - **What the executor follows by convention:**
      - a job writes only its own project's `<job>/…` branches;
      - its only effect is that push;
      - its code comes from the pinned commit.
    
      The guest accepts root for its agents (`docs/security.md`), so this is not a boundary against them. v0 accepts that explicitly: the request gate stays enforced, and the convention is what keeps automation tidy, not secure.
    - **The approval class covers declaration and implementation.**
      - The instance floor makes `valley/jobs.cue` and every path an enabled job executes approval-required: its flake app, scripts, and the inputs that define them.
      - Approving the declaration alone would leave the program editable. This is planned work under M1-C. Until then, every change to the deployment project already needs `[a]sk`.
    
    ## The run contract (v0)
    
    1. **Pin.**
       - Resolve the project's protected target to one commit, and refuse an unprotected target.
       - Read the declaration from that commit's tree.
       - Run the app as `nix run git+ssh://…?rev=<commit>#<app>`, never from a mutable checkout.
       - Run in a fresh temporary workspace, with a fixed environment and `PATH`.
    2. **Treat everything else as data.** Upstream commit subjects, existing branch contents and event payloads are never evaluated or passed to a shell. A job that updates a lock adds new dependencies, and anything that builds them runs in the same untrusted zone.
    3. **Check quickly.** Run the change's quick checks (`valley checks --names --cost quick`, from run `20261012-1240-bc7201b6`) before publishing, so a bump that doesn't evaluate never reaches the operator. Slow checks run at `[a]sk` on the valley host, as they do for agents.
    4. **Publish with a lease.**
       - Push with `--force-with-lease=<branch>:<expected>`, where `<expected>` is either absent or the job's own last output.
       - **If someone else moved the branch,** stop and report, never overwrite it.
       - **If a request is pending** for the branch's current commit, leave the branch alone until that request's outcome is recorded, then reconcile.
    5. **Serialize.** Only one run per job at a time, with wake-ups coalesced.
    6. **Record.** Write structured journald entries and a status file: the job, code commit, upstream revisions, output commit, timing and outcome. "Nothing to do" and "couldn't observe upstream" are different outcomes. A failure must reach the operator; how is open question 3.
    
    ## Delivery of triggers
    
    - **v0: watched refs plus the clock.**
      - The executor watches named refs with `git ls-remote` (pinned host key, bounded timeout) and reconciles on a period.
      - It doesn't claim the bus vocabulary: polling can't tell an integration from a direct write, nor see `request-stale`. Bumps don't need either.
    - **v1: bus delivery.** This needs `bd-d853d9c` closed first: publisher credentials, subscribe-only consumers, and locked-down JetStream admin, before any automated consumer acts. The wake-only argument limits what a forged event can do, but a flood still costs work, and the bug's gate stands as written.
    
    ## Where jobs run
    
    v0 runs jobs in the agent guest as the agent principal.
    - **Alternatives:**
      - A dedicated automation guest separates jobs from interactive agents, and is the better long-term home.
      - The host's `git` user is ruled out, because it is a much more consequential boundary.
    - **A separate principal** buys attribution and independent revocation, but not project scope. It's a later step.
    - **The runner:** a systemd timer and service per enabled job, driving one small Go reconciler from the-valley (`valley-job`) that does the pin, lease, record and serialize steps. A resident scheduler waits until more jobs justify it.
    
    ## v0 slice
    
    - **the-valley:**
      - `schema/jobs.cue`, with name, watched refs, interval, app, branch and timeout;
      - the `valley-job` Go reconciler implementing the run contract;
      - a NixOS module that turns an enable list into timers;
      - tests for restart, overlapping runs, the target moving mid-run, a branch changed by someone else, a failed push and a failed observation.
    - **the deployment project:**
      - `valley/jobs.cue` declaring `bump-the-valley` (watching the-valley `main`, every 10 minutes) and `bump-klaus` (watching GitHub klaus `main`, hourly);
      - a `bump-input` app that runs `nix flake update <input>` and writes the commit message from the upstream range, as data;
      - an enable list in the agent-guest module.
    - **the instance repository:** nothing in v0 (the agent principal's push grant covers it). The approval-class rule comes with M1-C.
    
    **Acceptance:**
    - a landing on the-valley `main` produces `bump/the-valley` within 10 minutes;
    - that branch passes the quick checks;
    - it shows in `valley review`;
    - your `[a]sk` lands it;
    - a rerun with nothing new to do changes nothing.
    
    ## Decisions on the open questions
    
    1. **Declarations:** `valley/jobs.cue` with its own loader. `policy/project/` composes against `schema/verification.cue`, which rejects unknown fields.
    2. **Replacing a branch:** allowed, since the hook has no ancestry rule for unprotected refs, but always with an explicit lease.
    3. **Run records:** journald and a status file in v0, plus an operator-visible failure signal, still to be chosen. Options: klaus's event stream, the guest's check command, or a pending-list marker. A job ref under `refs/the-valley/*` is closed to guest pushes, and opening a namespace needs its own enforcement design.
    4. **Schedules:** positive intervals with jitter for now. Starting, restarting and missed runs all mean reconcile now. Calendar times wait until timezones matter.
    5. **Agent-launching jobs:** not in v0. A future one needs budgets, deduplication, cancellation and credential rules.
    6. **Sequence:** v0 replaces the soak's "bump automation v0", before M1-C, with requests still the operator's. v1 (bus delivery) waits for `bd-d853d9c`.
    
    ## Doc drift found on the way
    
    the-valley's `docs/roadmap.md` still lists M5 as "next, in review", and `docs/security.md` still records the deployment project's GitHub merge path as open. Both lag the 2026-10-11 switch.