Skip to content

route_a.sh --sample: build the release on a household sample of a base H5 - #1862

Draft
anth-volk wants to merge 9 commits into
mainfrom
claude/route-a-sample-mode
Draft

anth-volk wants to merge 9 commits into
mainfrom
claude/route-a-sample-mode

Conversation

@anth-volk

Copy link
Copy Markdown
Contributor

Fixes #1861
Do not merge: check the sample mode against 1.9 · 2's --sample-receipt and any build-ID rule for sample builds once its PR exists (this PR's own step)

What this changes

tools/route_a/route_a.sh --sample builds the US national release on a household sample of an existing base H5 and stops at the build record. It is tracker task 1.9 · 3 of "15. US build memory, CPU and run time". 1.9 · 4's before-and-after tool runs it on two commits.

  • Settings (in route_a.env, checked before the run root is made):
    • SAMPLE_BASE_H5 and SAMPLE_BASE_SHA are both required: the base H5 to sample and its SHA-256.
    • SAMPLE_FRACTION (default 0.05) and SAMPLE_SEED (default 0) set the draw.
    • SAMPLE_RAM_GIB (default 8, from 1 to 28) is the free memory to wait for. It is a separate setting from RELEASE_RAM_GIB, because the example settings file sets that to 50 for full builds.
    • ROUTE_A_CERTIFY=1 is refused, and --sample with any other mode is refused.
  • Inputs: the run hashes only the base H5 it samples and the release's own inputs: the Ledger feed, the SSI prior basis, the SCF extract, and the QRF tail register and export-mass reference when set. It doesn't hash the base stage's raw ASEC, PUF and ACS inputs, and it skips the block-ladder check.
  • Commit check, in sample mode only: the build commit needs tools/sample_us_base_households.py declaring --base, --fraction, --seed and --out, and a release parser that declares --sample-receipt.
  • Stages:
    1. the prefetch;
    2. a sample stage in place of the base stage and the base's release-check preflight. It runs the base household sampler without the Hugging Face credential variables, into <run>/sample/;
    3. the release-check dry run on the sample (ROUTE_A_DRY_RUN, default 1);
    4. the release, with --base-h5 naming the sample and --sample-receipt naming its receipt.
  • Memory and staging:
    • The supervisor stops the sampler, the dry run or the release if its processes' resident memory passes 28 GiB.
    • Those three wait for SAMPLE_RAM_GIB of free memory before starting; the prefetch waits for the smaller of 12 GiB and that.
    • ROUTE_A_STAGING is set to 0 whatever the settings file says.
  • Where it stops:
    • A sample run keeps its stages in sample-<commit> beside a full build's run-<commit>, so the two never share an accepted stage.
    • It removes an earlier ROUTE_A_SAMPLED.json when it starts, and stops after the release with a new one. The record names the sampled base and its SHA-256, the fraction and seed, the sample and its receipt with their SHA-256 values, the build directory and record, whether the build failed its release validation checks, the dry run that checked the build, and the memory settings.
    • It exits 0, or 3 when the build failed its release validation checks, and never reaches the probe or certification.
  • Restarts:
    • A sample already drawn is kept only for the sampler command and SAMPLE_BASE_SHA it was drawn with. This covers a sample a driver accepted and one the supervisor of an earlier, stopped driver finished.
    • A fresh draw moves an earlier attempt's sample directory aside.
    • An accepted sample build is kept only for its release command and inputs. With other settings the run stops and says to move the sample run directory aside, since --rebuild is a mode of its own.

Two changes also apply to full builds:

  • Dry-run settings key. The release-check dry run now records its settings key when it starts, and compares it before run_stage can accept an earlier result. Before this, a dry run that the supervisor of an earlier, stopped driver finished was accepted after the release settings had changed, and was then recorded with the new key.
  • Dry-run record. The driver writes <run>/release-dry-run.result as the release starts, saying which dry run checked it.

release_ran now calls a general stage_ran. --sample-receipt is refused in RELEASE_EXTRA_ARGS.

Docs: a "Sample mode" section, stage rows and limit rows in the Route A runbook; the sample settings in route_a.env.example; one paragraph in docs/agent-guide.md; changelog.d/1861-route-a-sample-mode.added.md.

No build's output changes: this changes the driver that starts builds. No recorded hash or pin moves. No code shared with the UK build changes.

Built on

main (879cef1), not on an earlier task's branch. The driver's tests read route_a.sh only and need none of 1.9 · 1's or 1.9 · 2's code. The interfaces it assumes were checked as follows:

  • 1.9 · 1's sampler (Sample a base H5 by whole source households for the 5% national run #1860, head fe8dd20) matches: --base, --out, --fraction and --seed; the sample is written as <out>/<name of the --base file>; the receipt is <out>/sample_receipt.json; and --out may already exist.
  • 1.9 · 2's --sample-receipt <path> has no PR yet. If it requires a -sample- segment in a sample build's ID, this PR will add it to the release ID the driver passes. That check is the "Do not merge" step above.

Tests

All added or changed tests are engine-free and in packages/microcosm-build/tests/engine_free/us/. Each was run selected individually, once on the commit that adds it and once after the change.

  • New: test_route_a_sample_mode.py covers:
    • the mode and the refusal of each bad setting;
    • staging and memory settings in sample and full-build mode;
    • which inputs are hashed;
    • the sampler's command and launcher;
    • the release's --sample-receipt;
    • the commit check;
    • the sample stage replacing the base stage;
    • an accepted or supervisor-finished sample kept only for its settings;
    • a failed attempt moved aside;
    • the stop at the build record;
    • the dry run recorded as the release starts;
    • the stage order.
  • Changed in test_route_a_driver.py:
    • mode parsing now includes --sample;
    • the release and dry-run configuration lines now use the memory-limit setting;
    • the dry-run order now records the key before the dry run;
    • release_ran through stage_ran;
    • the rerun-guard tests;
    • new: test_a_sample_rerun_with_other_settings_is_refused and test_a_dry_run_an_earlier_supervisor_finished_counts_only_for_its_settings.
  • Changed helper: test_support/microcosm_build/route_a_driver.py's run_driver_settings passes the driver's arguments.

Results on each pair of commits (tests that fail before the change, then the change):

Tests commit Result before Change commit Result after
22c92aa 39 failed on assertions, 1 passed (the full-build case) 2927b81 40 passed
10cbc51 2 failed 6bc88ed 2 passed, and the 2 tests sharing their harness
1cee625 3 failed a87e40d 3 passed, and 1 related test
7b72097 5 failed, 2 control cases passed 1ea6ad6 9 cases passed

Round 3's reviewer ran all 44 cases at a87e40d under macOS bash 3.2.57: all passed. shellcheck reports nothing on route_a.sh and route_a.env.example, and ruff check and ruff format report nothing on the changed Python files. No CI has run yet; this PR starts it.

Review rounds

Three adversarial review rounds ran, each in a fresh subagent. The review files are in the project's notes folder.

  • Round 1: 1 medium bug.
    • A sample stage that the supervisor of an earlier, stopped driver finished was accepted by run_stage without comparing its command or base digest, and the digest record was overwritten.
    • Fixed: the sample is compared before run_stage, the digest is recorded only when the sampler starts, and a failed attempt's sample directory is moved aside.
  • Round 2: 2 low bugs.
    1. A dry run that the supervisor of an earlier, stopped driver finished was accepted for changed release settings. This affected full builds before this branch too.
    2. With ROUTE_A_DRY_RUN=0, the record's release_dry_run repeated an earlier dry run's result.
    • Both fixed (key recorded as the dry run starts; record corrected).
  • Round 3: 1 low bug.
    • On a rerun of an accepted sample build, release_dry_run described the rerun's settings.
    • Fixed: the record is written as the release starts and read by the hand-over.

Bugs left: none. Code-quality points left, none of which changes a build:

  • A sample run still runs full-build commit checks it doesn't use: the certification parser's flags, the base tool's flags and pins, and the preflight tool's flags.
  • A sample run in a full build's RUN_ROOT overwrites inputs.resolved.json, and ROUTE_A_SAMPLED.json is one file per RUN_ROOT. 1.9 · 4 runs each commit under its own RUN_ROOT.
  • The full build's ROUTE_A_BUILT.json still reports the dry run from the acceptance marker, as before this branch.
  • Some things are written twice: the release-input role list, the accepted exit statuses outside run_stage, and three test helpers copied from the driver tests.
  • Disk admission is sized for full builds, and --resolve doesn't check the sample settings.
  • A dry run that a driver from before this branch accepted from a supervisor's result, and recorded with that driver's settings key, is kept for that key.
  • The supervisor sums resident memory. On macOS under memory pressure that can read below the processes' physical footprint, so the 28 GiB limit can stop a stage later than a footprint reading would.

What the merge waits for

  • 1.9 · 1 (base household sampler, Sample a base H5 by whole source households for the 5% national run #1860): merged is enough. The sample mode runs its tool at the build commit, and a microcosm merge deploys and publishes nothing.
  • 1.9 · 2 (the release's --sample-receipt, no PR yet): merged is enough, for the same reason. Its certification refusal of sample builds is what the runbook and record rely on, and it must merge before this PR.
  • The "Do not merge" step above, then this PR's checks.

Environment variables and secrets

The changed driver reads settings from the operator's local, untracked settings file (route_a.env, or the file ROUTE_A_ENV names), sourced by the driver. None comes from a secret store or CI.

Variable Provider Wiring
SAMPLE_BASE_H5, SAMPLE_BASE_SHA, SAMPLE_FRACTION, SAMPLE_SEED, SAMPLE_RAM_GIB (new) the operator's settings file sourced by route_a.sh; passed to the sampler as arguments and to the supervisor configuration as limits
ROUTE_A_STAGING, ROUTE_A_CERTIFY, ROUTE_A_DRY_RUN, RELEASE_RAM_GIB (existing) the operator's settings file sample mode sets ROUTE_A_STAGING=0, refuses ROUTE_A_CERTIFY=1, honours ROUTE_A_DRY_RUN, and replaces RELEASE_RAM_GIB with SAMPLE_RAM_GIB
HF_TOKEN, HUGGING_FACE_HUB_TOKEN, HUGGINGFACE_HUB_TOKEN, HUGGING_FACE_TOKEN_MAX, SLACK_WEBHOOK_POPULACE_US, SLACK_WEBHOOK_POPULACE_UK the operator's shell removed by /usr/bin/env -u before the sampler starts, as for the probe; the release in sample mode runs without the four Hugging Face variables, as with ROUTE_A_STAGING=0

🤖 Generated with Claude Code

anth-volk and others added 9 commits December 3, 2026 01:27
A sample mode for the Route A driver: it draws a household sample of a
named base H5 with tools/sample_us_base_households.py, dry-runs the
release's checks on it, builds the release on it with --sample-receipt,
without staging and under a 28 GiB memory limit, and stops at the build
record with ROUTE_A_SAMPLED.json. These tests fail before the change.

The existing driver tests now read the release stage's memory limit from
a setting, the rerun guard in build and sample mode, and release_ran
through a stage_ran that any stage's command can be compared with.
run_driver_settings passes the driver's own arguments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
--sample builds no base. It hashes the base H5 SAMPLE_BASE_H5 names
against SAMPLE_BASE_SHA and the release's own inputs, not the base
stage's raw inputs; draws whole source households (SAMPLE_FRACTION,
default 0.05, with SAMPLE_SEED) with tools/sample_us_base_households.py
into <run>/sample/; dry-runs the release's gates on the sample; and builds
the release on it with --sample-receipt. It sets ROUTE_A_STAGING=0,
refuses ROUTE_A_CERTIFY=1, runs no base preflight, stops any stage above
28 GiB of resident memory and waits for SAMPLE_RAM_GIB (default 8, at
most 28) of free memory in place of RELEASE_RAM_GIB. Its stages live in
sample-<commit> beside run-<commit>, and it stops at the build record with
ROUTE_A_SAMPLED.json, exit 0, or 3 when the build failed its release
gates.

The commit check needs the sampler with the flags the driver passes and
a release parser declaring --sample-receipt; RELEASE_EXTRA_ARGS may not
carry --sample-receipt. A rerun keeps an accepted sample only for its
sampler command and base sha256 (stage_ran, which release_ran now uses),
and an accepted sample build only for its release command and inputs,
saying to move the sample run aside rather than --rebuild.

The test of the sample stage now reads only its own printed lines, not
the driver's log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When a driver is stopped during the sample stage, its supervisor can
finish and record an accepted result that no driver marked accepted. The
driver's run_stage accepts such a result, so the sample must be compared
with the current sampler command and base sha256 before that, and the
record of the base it was drawn from must keep the earlier digest. A
fresh draw after a failed attempt moves that attempt's sample directory
aside. Both tests fail before the change (review round 1, bug 1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A driver stopped during the sample stage can leave a supervisor that
finishes and records an accepted result, which run_stage accepts. The
sample stage now compares such a sample with the current sampler command
and SAMPLE_BASE_SHA before run_stage, as it does an accepted one, and
writes the record of the base digest only when the sampler is launched,
so a changed fraction, seed or base is refused instead of building the
release on the old sample (review round 1, bug 1). A fresh draw moves an
earlier attempt's sample directory aside first.

The driver's start-of-run log, the example settings, the runbook and the
changelog now say that the sampler, the dry run and the release wait for
SAMPLE_RAM_GIB, and the prefetch for at most that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A release-gate dry run that the supervisor of an earlier, stopped driver
finished must be kept only for the release settings it checked, so its
settings key is recorded as it starts and compared before run_stage can
accept its result (review round 2, bug 1). With ROUTE_A_DRY_RUN=0 the
sample hand-over record must say no dry run checked the build, not repeat
an earlier dry run's result (review round 2, bug 2). These tests fail
before the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The release-gate dry run's settings key is now recorded as the dry run
starts, and compared before run_stage can accept a result, whether a
driver accepted the dry run or the supervisor of an earlier, stopped
driver finished it. A release started after a change of settings is
therefore always dry-run on those settings (review round 2, bug 1). This
applies to full builds too, which had the same gap before this branch.

With ROUTE_A_DRY_RUN=0, ROUTE_A_SAMPLED.json's release_dry_run says no
dry run checked the build instead of repeating an earlier dry run's
result (review round 2, bug 2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The record's release_dry_run must describe the build, not the rerun
that writes the record: the driver records, as the release starts,
whether a dry run checked its settings and what it found, and the
sample hand-over reports that record, or "not recorded" for a build
released before the driver recorded it (review round 3). These tests
fail before the change, apart from the cases that check a release an
earlier driver's supervisor finished keeps its record.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The driver now writes <run>/release-dry-run.result as the release
starts: the dry run's acceptance marker, or that none ran with
ROUTE_A_DRY_RUN=0. A release that the supervisor of an earlier, stopped
driver finished keeps that driver's record. ROUTE_A_SAMPLED.json reports
this record ("not recorded" for a build released before it existed), so
a rerun with other dry-run settings no longer changes what the hand-over
says checked the build (review round 3). The changelog now says the
dry-run key change applies to full builds too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

route_a.sh sample mode: build the US national release on a household sample of a base H5

1 participant