Exploring the idea of generated web rendering engine.
genera handoff.md

Handoff: scripted-e2e #

Resume Here #

Goal. Exercise the whole job system end to end with no real model: submission (jobs/scripts/submit.sh), Dagu (bench/dagu/job.yaml), job-run and its stages, the review and rework loop, resends, and landing (jobs/scripts/poll-and-land.sh), each driven into one known outcome so every branch of that code runs. The point is the system, not feature code: fixture specs are tiny, and the agent and model are stand-ins that behave as each scenario says.

Scenarios, each checked against the job's recorded outcome afterwards:

  • clean pass through every stage and a landing
  • writer crash (the session errors)
  • writer leaves nothing (no commit)
  • writer's work fails the tests or checks
  • review fails, the job goes back to the writer, the rework passes
  • transient failures that make a stage or a run resend, then succeed
  • a batch with no admissible candidate
  • a landing that fails

Constraints:

  • One code path. The stand-ins are chosen by configuration (for example PATH or a setting naming the agent program, and NEV_LANE_MODEL_URL pointing at a stub server); unset, folknet runs unchanged, and nothing asks "is this a test".
  • Runs on the development box's lane (lane 2; docs/local-lane.md) against the local forge, and lands into a scratch clone named by JOBS_REPO, never the real main. Tags go to a scratch bare repository (JOBS_TAG_REMOTE; see "Runner settings" under Findings), announcements off (NEV_ANNOUNCE_URL=).
  • A real aspect-ratio job on Kimi may be running on the same Dagu (jobs-work/aspect-ratio); scenario jobs use their own names and never touch it.

State. The survey of how a job resolves its agent, model, preflight and outcome is recorded under "Findings". The stand-in agent is done (see "Stand-in agent" under Findings): --pi <program> in pi-session.sh, pi-writer.sh and pi-review.sh, preflight resolving that program in pi's place, jobs/scripts/stand-in-pi, and jobs/tests/stand_in_pi.rs; cargo test -p jobs passes on lane 2.

Next steps (one each; a writer does one and stops)

  1. The scenario fixtures: a generator (a script under jobs/scripts/, or a function of the scenario runner bench/e2e-jobs.sh of the next step) that writes, for each scenario below, specs/<name>.md, specs/<name>.job.json and specs/<name>.stand-in.json into a given checkout, and a test that each generated manifest passes job-check manifest --spec (reuse jobs/tests/manifest.rs's pattern). Names are e2e-<scenario>; each spec touches only its own file e2e/<name>.txt, so the landings cannot conflict with one another. Set limits.failed_rounds explicitly per scenario (see "Stand-in agent" under Findings for what a failing review does with it).
  2. The scenario runner bench/e2e-jobs.sh (it coordinates only; the jobs run in Dagu on lane 2). Preconditions it checks and refuses on: Dagu up on the box's lane; a fresh ~/folknet/inventory.json (under 15 minutes; see "What a stand-in job must still satisfy" under Findings); and no open record in the real ~/.local/state/nev-jobs (see "Shared lane" under Findings). Then, in a scratch directory: clone the submitting checkout, branch e2e-main, commit the fixtures plus a scratch tracks.json (base e2e-main, a cheap verify, landChecks []), push e2e-main to the local forge, add a scratch bare repository as the tag remote, install the forge's pre-receive hook for the publish-once scenario; submit every scenario with submit.sh --restart; run poll-and-land.sh every minute until records.py <dir> open is empty or a time limit passes; read each record and each kept result; print a table (scenario, expected, got, match); clean up (forge refs e2e-main, job/e2e-*, result/e2e-*; dagu-lane.sh clean-jobs e2e-*; prune-mirror; the hook); exit 1 on any mismatch. Settings in "Runner settings" under Findings.
  3. Run it on lane 2 until every scenario matches; document it in docs/local-lane.md.

Findings #

Stand-in agent. A manifest agent command ["{tools}/pi-writer.sh", "--pi", "{tools}/stand-in-pi"] (or pi-review.sh) runs jobs/scripts/stand-in-pi where pi would run, through the same pi-session.sh (models.json, --mode json, the filter). Its script is specs/<name>.stand-in.json, keyed by JOB_STAGE; a review's restate session is the stage <stage>-restate, and a stage missing from the script fails with exit 2 and the reason in the stage log. The actions and output are in the script's header. Behaviours the scenarios depend on, each covered in jobs/tests/stand_in_pi.rs:

  • The call count lives in $JOB_STATE_DIR/stand-in/<stage> and each call's prompt in <stage>.prompt.<N>, so a list plays out across relaunches and rework rounds.
  • A commit whose files already hold that content commits nothing, so a writer whose last action repeats in a later round changes nothing and pi-writer.sh fails that round's stage. A rework scenario's writer list needs one distinct commit per round.
  • A failing review with failed_rounds 1 ends the job waiting for a person (job-run exit 11, failed_stage review), not failed (exit 1). With failed_rounds 2, a failing review sends the job back to the writer, whose brief carries the review's findings.
  • Preflight (preflight.rs check(), pi_option()): a pi stage with --pi <p> needs <p> to resolve instead of pi; any pi stage without --pi still needs pi; the gateway check applies either way. An unresolvable --pi exits 9 before any stage.

How a job gets its agent. pi-writer.sh and pi-review.sh both run pi-session.sh, which finds pi with command -v pi (else ~/.local/bin/pi), writes a models.json naming NEV_MODEL_URL, and always runs pi with --mode json, keeping the last assistant message's text as the answer and exiting 1 when that message's stopReason is error or aborted. The Dagu run step (bench/dagu/job.yaml) takes PATH from the shell Dagu started in plus ~/.cargo/bin, and NEV_MODEL_URL from ~/.lane-model-env; both are lane-wide. So neither PATH nor NEV_LANE_MODEL_URL can pick a stand-in per job without changing it for the real aspect-ratio job on the same Dagu. What is per job is the manifest: an agent of kind command is any argv, {tools} is filled in the agent's own elements (runner.rs expand_stage()), and the manifest's leak check (manifest.rs leak_in()) allows {tools}/... and repo-relative paths but no address and no absolute path. Hence the stand-in agent: the manifest's agent command names it, ["{tools}/pi-writer.sh", "--pi", "{tools}/stand-in-pi"], and the stand-in reads its script from the job's own base commit. Nothing asks whether it is a test; a manifest without --pi runs exactly as today. Wrapping the command in env or sh -c instead would change argv[0], and preflight's pi check keys on argv[0]'s basename (preflight.rs check(), pi_stages), so the stand-in path would skip the gateway and pi checks a real job gets.

Existing stand-ins, for reference: jobs/fixtures/pi-writer/fake-pi/pi (FAKE_PI_MODE: commit, more, uncommitted, switch, nothing, fail, error; space-separated per call; picked by PATH in jobs/tests/pi_writer.rs run_fake_with()), jobs/fixtures/pi-review/stub-pi/pi (answers from STUB_PI_REPLY, per call .N), jobs/fixtures/run-batch/batch.sh (prints the log lines bench/ledger.py reads), jobs/fixtures/dagu-stub/dagu-lane.sh (no Dagu at all; not usable here, since the scenarios are meant to go through the real Dagu). jobs/tests/common/mod.rs stub_gateway_url() answers 200 to anything and is how the tests meet preflight's gateway check.

What a stand-in job must still satisfy (preflight.rs check() and the inventory):

  • git, python3, node, kill on PATH; NEV_LANE_SHARED with archive/job-logs writable (the box has ~/lane-shared); 20 GiB free on the workdir's filesystem.
  • A writer stage adds: oracle/node_modules in the workdir with the Playwright browsers in ~/.cache/ms-playwright (the prepare step installs node_modules; the browsers are the box's own), and cargo and rustc on PATH.
  • A pi stage (argv[0] pi-writer.sh, pi-review.sh, pi-session.sh) adds: pi resolving (or the --pi program, when the stage names one) and GET <NEV_MODEL_URL>/v1/models answering 200 with NEV_MODEL_API_KEY within 10 s: the real Kimi endpoint on the box. Cheap, no generation, but a Kimi outage fails every scenario with exit 9.
  • A run-batch.sh stage or ledger check adds <share>/ledger and NEV_ON_LANE (the run step exports it).
  • Inventory (inventory.rs check(), always, since job.yaml passes --inventory): the snapshot under 15 minutes old; every model the manifest names (gateway agents' models, command agents' model) declared in bench/folknet.json and ready in the snapshot; every provider used declared and allowed. kimi-for-coding (provider kimi) is the one model the box's probe marks ready, so fixture manifests name it everywhere a model goes; the stand-in never calls it. The snapshot is kept fresh by a crontab line on the box ($HOME/folknet/probe-kimi.sh, every 10 minutes) whose comment says to remove it when the aspect-ratio job ends; the runner needs it, or runs the probe itself first.

Fewest stages. manifest.rs validate() needs format 1, name equal to the file name, a candidates role (top-level provider, or agents.candidates), stop_rule, limits (wall_clock_seconds, writer_relaunches above 0), and exactly one review stage, last. --spec adds only: feature_rules need docs/feature-map.json in touches (checks.rs manifest_with_spec), so fixtures have no feature rules. submit.sh needs the spec's front matter enabled: true and depends-on: []. The shape for most scenarios (write, checks, review):

{ "format": 1, "name": "e2e-clean",
  "stop_rule": { "flat_batches": 1, "max_batches": 1 },
  "limits": { "wall_clock_seconds": 1800, "writer_relaunches": 1, "failed_rounds": 2 },
  "agents": {
    "candidates": { "kind": "gateway", "models": "kimi-for-coding:1:1" },
    "writer": { "kind": "command", "model": "kimi-for-coding",
                "command": ["{tools}/pi-writer.sh", "--pi", "{tools}/stand-in-pi"] },
    "review": { "kind": "command", "model": "kimi-for-coding",
                "command": ["{tools}/pi-review.sh", "--pi", "{tools}/stand-in-pi"] } },
  "stages": [
    { "name": "write", "kind": "writer", "agent": "writer", "command": ["{agent}"] },
    { "name": "checks", "kind": "script",
      "command": ["sh", "-c", "test \"$(cat e2e/e2e-clean.txt)\" = hello"] },
    { "name": "review", "kind": "review", "agent": "review", "command": ["{agent}"] } ] }

with the spec's front matter touches: [e2e/e2e-clean.txt]. The batch scenario adds batch (script, agent candidates, ["{tools}/run-batch.sh", "--job", "<name>", "--measure-dir", "target/e2e", "--", "sh", "jobs/fixtures/run-batch/batch.sh", "target/e2e/marker", "0", "0"], check ledger ["{ledger_dir}", "<name>"]) and admit (writer, check provenance on a file nobody writes). The runner refuses only argv[0] under jobs/ in the workdir (runner.rs unpinned()), so a fixture after -- is fine.

Scenarios, stand-in script and expected outcome (record outcome, and from result.json: status, failed_stage, stage attempts, rounds):

scenario stand-in script expected
clean write: commit the file right; review: pass landed
writer crash write: "error" (every call) failed, stage write, attempts 2
writer nothing write: "nothing" failed, stage write ("changed nothing")
checks fail write: commit wrong content failed, stage checks
rework write: [wrong-but-passing, fix]; review: [fail with a finding, pass] landed, 2 rounds
stage resend write: [{"exit": 3}, commit right] landed, write attempts 2
run resend clean script; the forge refuses the first publish landed, record resends 1
no admissible candidate batch runs; admit: "nothing" failed, stage admit (provenance)
landing fails write: commit the file and one outside touches refused ("outside the spec's touches")

Optional extra: checks with "on_fail": "rework" failing every round ends needs-person (exit 11), a branch of poll-and-land.sh no other scenario reaches.

The run resend: a run-level resend happens on run step exit 7 (publish failed, counted) or 3 (inventory refused, uncounted). Exit 3 cannot be made per job without a model that stays not ready, which never clears. Exit 7 per job: a pre-receive hook on the local forge ($HOME/forge/nev.git/hooks/, which has none today) that refuses a push including refs/heads/result/e2e-run-resend once, keyed by a marker file in the runner's scratch directory, and accepts every other ref untouched. The resend resumes the kept job directory, finds every stage passed, and publishes again. The hook is the one change to shared state the scenarios make; the runner installs it and removes it.

Runner settings (every one already a setting of submit.sh/poll-and-land.sh): JOBS_REPO the scratch clone; JOBS_STATE_DIR a scratch directory, never the default ~/.local/state/nev-jobs (the real poller reads that, and poll-and-land.sh would land the aspect-ratio job from it); JOBS_BASE_BRANCH=e2e-main; JOBS_FORGE_REMOTE the scratch clone's remote for $HOME/forge/nev.git; JOBS_TAG_REMOTE a scratch bare repository, so no spec/e2e-* or result/e2e-* tag reaches the forge or origin; JOBS_CHECK a job-check built through lane 2 (jobs/scripts/install-job-check.sh); NEV_ANNOUNCE_URL=; NEV_DAGU_LANE, NEV_DAGU_LOCAL_PORT, NEV_LANE_SSH, NEV_LANE_SSH_OPTS, NEV_LANE_ROOT, NEV_LANE_GIT_URL as docs/local-lane.md gives them; the scratch clone needs bench/lane.local.json linked to the primary checkout's. No JOBS_MODEL.

The base must be on the forge under the name submit.sh fetches (`git fetch

`), and `bench/land.sh` reads `base` from the clone's `tracks.json`: a scratch branch `e2e-main` in both places keeps the forge's `main` untouched. The lane mirror fetches all of the forge, so `prepare` finds the base. `bench/land.sh` checks the diff against `touches` (and the gate's own files) before it runs `verify`, so the landing-fails scenario is refused in seconds. `verify` in the real `tracks.json` is the full `bench/verify.sh` gate plus `bench/fragment-floor.sh`; four landings of it on the box would take hours and test nothing about the job system, so the scratch `tracks.json` declares a cheap `verify` and no `landChecks`. Reversible: point it back at the real gate for one run to exercise that too.

Outcome. records.py <dir> get <name> outcome|message|run_id|resends; open lists what is not finished. result.json (result.rs build(): status, failed_stage, reason, stages[].attempts, round, rounds) is kept by poll-and-land.sh as the tag result/<name>/<run id> on JOBS_TAG_REMOTE for exits 0 (after landing), 1, 9 and 11; the runner reads it from there. Exit 10 and a refused landing record only the message.

Shared lane. Two things the scenarios share with the real aspect-ratio job:

  • bench/dagu-lane.sh run without --no-sync replaces ~/dagu/src and ~/dagu/jobs/scripts with the submitting checkout's copy, and submit.sh adds --no-sync only for open runs in its own JOBS_STATE_DIR. A scenario submit would so replace the source a later aspect-ratio resend builds from with the scratch clone's. Hence the runner's refusal while the real record directory has an open run.
  • Dagu's jobs queue runs two at a time across both; the lane's job-events store gets the scenarios' events (the run step posts whenever ~/job-events/token exists, not a per-job setting). Caveat to live with; the names all start e2e-.

Not covered, by choice. The batch model client (crates/generation/src/model.rs HttpModelClient) is feature code reached only through a real *_real_model_run binary; a stub model server would have to be the lane-wide NEV_LANE_MODEL_URL, which the real job uses. The batch scenario exercises run-batch.sh, the ledger check and the admit failure with the fixture batch instead. The exit-3 resend path (inventory not ready) is covered only by jobs/tests/poll_and_land.rs.

Unverified. That the box's ~/.cache/ms-playwright holds the browsers the clone's oracle/node_modules/playwright-core/browsers.json names (the aspect-ratio job passing preflight suggests so). What bench/after-land.sh, which bench/land.sh runs after every merge, does in the scratch clone (dashboard and web-features updates; a failure there does not change a completed landing's exit, per bench/land.sh's header). That the scenarios' prepare step's npm install from the shared cache stays under a minute or two.

Key files

  • jobs/scripts/stand-in-pi, jobs/tests/stand_in_pi.rs (its manifest shape is the one the scenario fixtures reuse), jobs/tests/common/mod.rs stub_gateway_url()
  • jobs/scripts/submit.sh, jobs/scripts/poll-and-land.sh, jobs/scripts/pi-session.sh
  • bench/dagu/job.yaml, bench/land.sh, jobs/scripts/pi-writer.sh, jobs/scripts/pi-review.sh, jobs/scripts/records.py
  • jobs/src/preflight.rs check()
  • docs/local-lane.md (the box as lane 2, its settings, the job commands)

Verify. cargo test -p jobs through lane 2 (NEV_LANE_* overrides in docs/local-lane.md); then the scenario runner exits 0 with every scenario matching.