From 6caed891a733021008dece6ca1bc0f3d1b3c61af Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Fri, 9 Oct 2026 21:51:16 -0400 Subject: [PATCH 01/28] Register the US head-to-head scorer as a Modal stage for the d844 run A us-release-head-to-head ToolSpec (one score stage, digest-pinned incumbent, candidate and ledger-feed inputs, owned path flags, --workers and --maximum-microsim-batch-size as plan options), a head-to-head resource class (20 CPUs with limit 20, 224 GiB, 4 h 45 min, non-preemptible; $38.95 list-price ceiling per attempt), the d844 plan and a runbook section. Co-Authored-By: Claude Opus 5.5 --- docs/us-modal-stage-route-a-h2h-plan.json | 38 +++ docs/us-modal-stage-runbook.md | 171 ++++++++++- ...est_us_modal_stage_release_head_to_head.py | 270 ++++++++++++++++++ tools/modal_us_stage.py | 29 ++ tools/modal_us_stage_plan.py | 78 ++++- 5 files changed, 577 insertions(+), 9 deletions(-) create mode 100644 docs/us-modal-stage-route-a-h2h-plan.json create mode 100644 packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py diff --git a/docs/us-modal-stage-route-a-h2h-plan.json b/docs/us-modal-stage-route-a-h2h-plan.json new file mode 100644 index 0000000000..d1cdd1d9e0 --- /dev/null +++ b/docs/us-modal-stage-route-a-h2h-plan.json @@ -0,0 +1,38 @@ +{ + "schema": "microcosm-modal-us-stage-plan/1", + "tool": "us-release-head-to-head", + "stage": "score", + "run_id": "route-a-h2h-d844-20261009", + "source": { + "commit": "5d1f71a2cb28b130f4ecbd5a17a29e8f639c7698", + "branch": "h2h-scorer-workers" + }, + "inputs": { + "incumbent_h5": { + "uri": "volume://cas/sha256/6496cc4393d4d3c6574f76eca231de5898c803b9067645591fd5c4d3e65aee84/populace_us_2024.h5", + "sha256": "6496cc4393d4d3c6574f76eca231de5898c803b9067645591fd5c4d3e65aee84" + }, + "candidate_h5": { + "uri": "volume://cas/sha256/417d23aed4d044de2e657a7b5d856136975d25739dbdb4ddd72866f841de1559/populace_us_2024.h5", + "sha256": "417d23aed4d044de2e657a7b5d856136975d25739dbdb4ddd72866f841de1559" + }, + "ledger_facts": { + "uri": "volume://cas/sha256/b85437390021777e746f507c5890305496baf5fc7f2c78ba08ddb090f4839801/consumer_facts_us_c5e5bf8.jsonl", + "sha256": "b85437390021777e746f507c5890305496baf5fc7f2c78ba08ddb090f4839801" + } + }, + "options": { + "workers": 20, + "maximum_microsim_batch_size": 2000 + }, + "env": { + "PYTHONUNBUFFERED": "1", + "OMP_NUM_THREADS": "1", + "MKL_NUM_THREADS": "1", + "OPENBLAS_NUM_THREADS": "1", + "NUMEXPR_NUM_THREADS": "1", + "BLIS_NUM_THREADS": "1" + }, + "max_wall_seconds": 15900, + "nonpreemptible": true +} diff --git a/docs/us-modal-stage-runbook.md b/docs/us-modal-stage-runbook.md index 92b8b9a146..29b3140e28 100644 --- a/docs/us-modal-stage-runbook.md +++ b/docs/us-modal-stage-runbook.md @@ -3,12 +3,14 @@ Epic #956 acceleration item E: heavy US stages should not have to queue on the one 128 GiB build machine. This runbook covers the smallest working path: a registered tool run on Modal from a pinned commit, with inputs fetched by -digest and outputs listed with sha256 receipts. Three tools are registered +digest and outputs listed with sha256 receipts. Four tools are registered (`TOOLS` in the plan module): `tools/build_us_acs_local_release.py` (tool `us-acs-local-release`, stages `materialize`, `calibrate`, `qa`, `finalize`, `package`, or `all`), Route A's PUF-support base, `tools/build_us_puf_support_base.py` (tool `us-puf-support-base`, stage -`all`; see "Route A's base stage"), and `runner-smoke` (stage `smoke`), an +`all`; see "Route A's base stage"), the US head-to-head scorer, +`tools/score_us_release_head_to_head.py` (tool `us-release-head-to-head`, +stage `score`; see "Route A head-to-head (d844)"), and `runner-smoke` (stage `smoke`), an inline script that proves the run path on any pushed commit (see "Commands"). @@ -21,7 +23,9 @@ Two files do the work: files, and writes and verifies receipts. Unit tests (engine-free): `packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_plan_tool.py` and, for the base, - `packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_puf_support_base.py`. + `packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_puf_support_base.py`, + and, for the scorer, + `packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py`. Nothing here uploads to the Hugging Face Hub, touches `latest.json` or notifies anyone. The furthest a stage goes is `package`, which writes a @@ -159,21 +163,22 @@ local wall times in this table understate Modal's wall and cost. | package | 21.8 GB, 79 s | light | 2 cores, 48 GiB | about $0.01 | | check | n/a | check | 2 cores, 8 GiB, 30 min timeout | cents | | PUF-support base (`all`) | 72.5 GB, 2,788 s wall, 6,238 CPU-s | base | 4 cores (limit 4), 112 GiB, 4 h 35 min timeout | about $0.84 ($2.52 non-preemptible) | +| Route A head-to-head (`score`) | unmeasured aggregate peak; about 80 core-hours estimated locally | head-to-head | 20 cores (limit 20), 224 GiB, 4 h 45 min timeout | $38.95 non-preemptible at the timeout and request | The prices are Modal's list prices for standard compute, read from -modal.com/pricing on 22 September 2026 and unchanged on 29 September: +modal.com/pricing on 22 September 2026 and unchanged on 9 October: $0.0000131 per core-second and $0.00000222 per GiB-second. Modal bills the higher of the request and actual use (modal.com/docs/guide/resources). The heavy class costs about $1.21 an hour at its request, so an 8-hour timeout costs about $9.70 at the request; CPU or memory used above the request bills above that. With `"nonpreemptible": true` every figure is three times -higher: about $3.63 an hour for the heavy class. Only the base class sets -a CPU limit (equal to its request); the others are request-only for CPU, +higher: about $3.63 an hour for the heavy class. The base and head-to-head +classes set a CPU limit equal to their request; the others are request-only for CPU, and every class is request-only for memory, so a stage that used more cores or more memory than its request would be billed for them. The engine pass in materialize is single-threaded (CPU seconds roughly equal wall seconds), so extra cores would not speed it up. The table leaves out volume storage and -image builds. The base class is sized in "Route A's base stage" below. +image builds. The base and head-to-head classes are sized in their sections below. ## Commands @@ -1020,6 +1025,158 @@ can also hold older checkpoints. The run's state already differs from its receipt by the checkpoints that were never copied, so a later stage of the same `run_id` would refuse either way; none is planned. +## Route A head-to-head (d844) + +`docs/us-modal-stage-route-a-h2h-plan.json` compares Route A +(`populace-us-2024-0fb05b6-4b57d15a287c-20260930T150401Z`) with the US +default (`populace-us-2024-spm-20260915`) on the frozen +`consumer_facts_us_c5e5bf8.jsonl` ledger. The plan pins scorer commit +`5d1f71a2cb28b130f4ecbd5a17a29e8f639c7698` on `h2h-scorer-workers` (#1171). +The runner registration comes from this checkout. Before the paid run, +incorporate #1171's separate scorer fix round and update `source.commit` +and `source.branch` to its reviewed, pushed revision; repeat the local +validation and Modal check after repinning. This plan's current immutable +pin will not acquire those fixes when the branch moves. + +The stage runs the local comparison's argv with staged paths and +`--workers 20` added: + +```text +--incumbent X --candidate Y --ledger-facts Z --out-prefix P --maximum-microsim-batch-size 2000 --workers 20 +``` + +Only `workers` and `maximum_microsim_batch_size` are plan options. Every +path flag, `--out-prefix`, the candidate-manifest pin, both spellings of +each boolean, and the alternative batch-size spelling are runner-owned. +The builder omits `--age-targets` and `--allow-unaged-dollar-targets`, so +the scorer uses the same defaults as the sequential run: `False` and +`True`, respectively. The crosswalk and candidate pool/attestation flags +are also omitted; the scorer chooses its normal bundled crosswalk. +Changing this scoring yardstick requires a reviewed registration change. +The plan sets the five native numerical thread counts to `1`, so twenty +spawned workers do not each start a twenty-thread BLAS/OpenMP pool. +That is an execution choice; the engine-free argv test does not prove +numerical parity across platforms or thread counts. + +Both H5 inputs retain the filename `populace_us_2024.h5` in separate CAS +directories and stage to `/work/inputs/incumbent_h5/populace_us_2024.h5` +and `/work/inputs/candidate_h5/populace_us_2024.h5`. Keep the `.h5` suffix +and this filename: `_resolved_artifact_path` preserves them for the loader +and artifact identity. Do not upload either H5 under an extensionless hash. +The incumbent is 826,917,837 bytes; the ledger is 164,603,204 bytes. The +candidate's size was not supplied; its digest is the byte identity. + +**Resources and ceiling.** Class `head-to-head` requests 20 physical +cores with CPU limit 20 and 224 GiB. The d844 plan uses non-preemptible +placement; both class runners have `retries=0`. At twenty workers, +1,030 slices × 4.7 minutes / 20 is 14,523 seconds (about 4 hours 2 minutes). +The tool budget is 15,900 seconds (4 hours 25 minutes), with 1,377 seconds +for initialization and compute margin. The 17,100-second timeout +(4 hours 45 minutes) adds the normal 900-second runner reserve and +300 seconds for staging. Slow staging reduces the tool's available time; +the runner preserves the reserve for logs, hashes, mirroring and receipt. +The budget estimate including the reserve is $38.27. + +Using the existing runbook formula and [Modal's list prices](https://modal.com/pricing) +(checked 9 October 2026), the request held through the timeout costs +`(20 × $0.0000131 + 224 × $0.00000222) × 17,100 × 3 = $38.95`. +**The per-attempt ceiling at the request is below $40.** Memory has no hard +limit; use above 224 GiB bills above this estimate. Startup/image work, +the check, storage, timeout overshoot and another attempt are outside this +execution ceiling, as for the base stage. A 256 GiB class at this timeout +would cost **$42.60, above $40**; use the registered 224 GiB class for this +plan. A possible smaller fallback is 16 workers, 16 CPUs and 192 GiB with +a 20,700-second timeout (5 hours 45 minutes), listing at $39.49; that +requires a reviewed class and matching plan change before use. + +The independent review's 9–10 GiB per worker is unmeasured. Each worker +holds a full copy of the repaired frame, and the parent retains the +original and repaired frames. The 224 GiB request allows 200 GiB for +workers plus 24 GiB for the parent, runner and spawn serialization, with +limited spare capacity. This is an estimate, not a measured aggregate +peak. The receipt's `peak_rss_bytes` is a child-process peak from +`RUSAGE_CHILDREN`, not the sum of twenty workers; use Modal's container +memory measurements to assess this sizing after the run. The stage writes +scorecards and logs, mirrors `h2h.json` and `h2h.md` first, and has no +checkpoint/resume state or additional disk/write-probe requirement. + +Stage the inputs in the `policyengine` workspace. Set these variables to +the existing local files; the ledger path is the one used by Route A's +base. `upload-commands` only hashes files and prints commands: it performs +no upload. Run it first to refuse a digest mismatch before uploading. +If a CAS file already exists (the base may have staged the ledger), skip +that `put` and let check mode verify its digest; do not overwrite it. + +```bash +INCUMBENT_H5=/path/to/populace-us-2024-spm-20260915/populace_us_2024.h5 +CANDIDATE_H5=/path/to/populace-us-2024-0fb05b6-4b57d15a287c-20260930T150401Z/populace_us_2024.h5 +LEDGER_FACTS=$HOME/PolicyEngine/_buildh-runtime/inputs/consumer_facts_us_c5e5bf8.jsonl +python3 tools/modal_us_stage_plan.py upload-commands \ + docs/us-modal-stage-route-a-h2h-plan.json \ + incumbent_h5="$INCUMBENT_H5" candidate_h5="$CANDIDATE_H5" ledger_facts="$LEDGER_FACTS" + +modal volume put microcosm-us-stage-inputs "$INCUMBENT_H5" \ + cas/sha256/6496cc4393d4d3c6574f76eca231de5898c803b9067645591fd5c4d3e65aee84/populace_us_2024.h5 +modal volume put microcosm-us-stage-inputs "$CANDIDATE_H5" \ + cas/sha256/417d23aed4d044de2e657a7b5d856136975d25739dbdb4ddd72866f841de1559/populace_us_2024.h5 +modal volume put microcosm-us-stage-inputs "$LEDGER_FACTS" \ + cas/sha256/b85437390021777e746f507c5890305496baf5fc7f2c78ba08ddb090f4839801/consumer_facts_us_c5e5bf8.jsonl + +# Validate locally, then check on Modal after the reviewed scorer repin. +python3 tools/modal_us_stage_plan.py validate docs/us-modal-stage-route-a-h2h-plan.json +MICROCOSM_MODAL_PLAN=docs/us-modal-stage-route-a-h2h-plan.json \ + modal run tools/modal_us_stage.py +``` + +Require `CHECK OK`, including the pinned parser and all three volume +digests, before the paid run. Launch the paid run through +`893/bin/lsubmit.sh` under launchd, never from a session shell. +Prepare this job script in the assigned checkout; the absolute CLI and +working directory make the payload independent of launchd's default +`PATH` and working directory: + +```bash +mkdir -p modal-runs/route-a-h2h-d844-20261009 +cat > modal-runs/route-a-h2h-d844-20261009/launch.sh <<'SH' +#!/bin/bash +set -euo pipefail +cd /Users/maxghenis/PolicyEngine/_worktrees/microcosm-h2h-modal +export PATH=/Users/maxghenis/.local/bin:/opt/homebrew/bin:/usr/bin:/bin +export MICROCOSM_MODAL_PLAN=docs/us-modal-stage-route-a-h2h-plan.json +exec /Users/maxghenis/.local/bin/modal run --detach tools/modal_us_stage.py --run +SH +``` + +Submit `/bin/bash` with the absolute path to that script through the main +session's `893/bin/lsubmit.sh`. **The exact submission command still needs +the main session's launcher path and argument interface:** that script is +absent from this checkout and the known build-machine locations. Do not +run `launch.sh` directly in a session shell. The main session should fill +in the submission command before launching; the payload above is complete. + +Once the launch reports a receipt path, fetch that `score-.json` and +the two scorecards. The receipt's `outputs` lists their relative paths, +byte counts and sha256s. Fetch the tiny complete state, including the logs, +so strict verification covers everything: + +```bash +R=route-a-h2h-d844-20261009 +mkdir -p "modal-runs/$R" +modal volume get microcosm-us-stage-runs "runs/$R/receipts" "./modal-runs/$R/" +modal volume get microcosm-us-stage-runs "runs/$R/state" "./modal-runs/$R/" +RECEIPT="./modal-runs/$R/receipts/score-.json" +python3 tools/modal_us_stage_plan.py verify-receipt "$RECEIPT" \ + --state-root "./modal-runs/$R/state" --strict +ls -l "./modal-runs/$R/state/h2h.json" "./modal-runs/$R/state/h2h.md" +``` + +Use the actual receipt name from the launch and confirm the downloaded +directory layout (Modal CLI versions can add a level; see "Commands"). +Verification requires `COMPLETED` and no budget stop, and rehashes both +scorecards and every other state file. Inspect `h2h.json` and `h2h.md` +only after it passes. A successful receipt proves those bytes; Max's d844 +decision remains separate from running this comparison. + ## Preemption and restarts Functions run on Modal's preemptible placement unless the plan sets diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py new file mode 100644 index 0000000000..210ed411e8 --- /dev/null +++ b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py @@ -0,0 +1,270 @@ +"""Engine-free registration and d844 plan checks for the Modal scorer stage.""" + +from __future__ import annotations + +import argparse +import ast +import json +from collections.abc import Sequence +from pathlib import Path +from types import SimpleNamespace + +import pytest + +from test_support.microcosm_build.us_modal_stage_plan_tool import ( + ROOT, + load_app, + plan_lib, +) + +PLAN_PATH = ROOT / "docs" / "us-modal-stage-route-a-h2h-plan.json" +SCORER = ROOT / "tools" / "score_us_release_head_to_head.py" +INPUTS = { + "incumbent_h5": ( + "populace_us_2024.h5", + "6496cc4393d4d3c6574f76eca231de5898c803b9067645591fd5c4d3e65aee84", + ), + "candidate_h5": ( + "populace_us_2024.h5", + "417d23aed4d044de2e657a7b5d856136975d25739dbdb4ddd72866f841de1559", + ), + "ledger_facts": ( + "consumer_facts_us_c5e5bf8.jsonl", + "b85437390021777e746f507c5890305496baf5fc7f2c78ba08ddb090f4839801", + ), +} +LOCAL_ARGV = [ + "--incumbent", + "/local/incumbent/populace_us_2024.h5", + "--candidate", + "/local/candidate/populace_us_2024.h5", + "--ledger-facts", + "/local/consumer_facts_us_c5e5bf8.jsonl", + "--out-prefix", + "/local/h2h", + "--maximum-microsim-batch-size", + "2000", +] +PATH_FLAGS = { + "--incumbent": "incumbent_h5", + "--candidate": "candidate_h5", + "--ledger-facts": "ledger_facts", +} + + +def _plan_data() -> dict: + return json.loads(PLAN_PATH.read_text()) + + +def _plan() -> plan_lib.Plan: + return plan_lib.parse_plan(_plan_data()) + + +@pytest.fixture(scope="module") +def scorer_parser(): + """Run only the scorer's argparse functions, without its engine imports. + + Its BooleanOptionalAction generates --no-* aliases, which a regex of + add_argument calls would miss. Capturing the real parser also catches + the maximum-microsimulation spelling alias. + """ + + parsers = [] + + class RecordingParser(argparse.ArgumentParser): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + parsers.append(self) + + namespace = { + "argparse": SimpleNamespace( + ArgumentParser=RecordingParser, + ArgumentTypeError=argparse.ArgumentTypeError, + BooleanOptionalAction=argparse.BooleanOptionalAction, + Namespace=argparse.Namespace, + ), + "Path": Path, + "Sequence": Sequence, + # The run passes its batch size explicitly. Loading the release + # module just to provide this unused default would import the engine. + "release": SimpleNamespace(DEFAULT_MAXIMUM_MICROSIM_BATCH_SIZE=2000), + } + functions = [ + node + for node in ast.parse(SCORER.read_text()).body + if isinstance(node, ast.FunctionDef) + and node.name in {"_parse_args", "_positive_workers"} + ] + assert {node.name for node in functions} == {"_parse_args", "_positive_workers"} + exec( + compile(ast.Module(body=functions, type_ignores=[]), str(SCORER), "exec"), + namespace, + ) + parse = namespace["_parse_args"] + parse(LOCAL_ARGV) + return SimpleNamespace(parse=parse, parser=parsers[0]) + + +def test_d844_plan_validates_with_digest_pinned_loader_filenames() -> None: + plan = _plan() + tool = plan_lib.US_RELEASE_HEAD_TO_HEAD + assert plan.tool is tool + assert (tool.name, tool.script, plan.stage) == ( + "us-release-head-to-head", + "tools/score_us_release_head_to_head.py", + "score", + ) + assert set(tool.stages) == {"score"} + assert set(tool.inputs) == set(tool.stages["score"].required_inputs) == set(INPUTS) + assert plan.options == {"maximum_microsim_batch_size": 2000, "workers": 20} + assert plan.nonpreemptible is True + assert plan.max_wall_seconds == 15_900 + for role, (filename, digest) in INPUTS.items(): + ref = plan.inputs[role] + assert (ref.kind, ref.filename, ref.sha256) == ("volume", filename, digest) + assert ref.volume_path == f"cas/sha256/{digest}/{filename}" + assert plan_lib.input_local_path("/work", ref) == ( + f"/work/inputs/{role}/{filename}" + ) + # The two loader filenames stay identical but are staged independently. + assert plan.inputs["incumbent_h5"].filename == "populace_us_2024.h5" + assert plan.inputs["candidate_h5"].filename == "populace_us_2024.h5" + assert plan.stage_spec.mirror_first == ("h2h.json", "h2h.md") + + +def test_modal_argv_equals_the_local_d844_command_apart_from_paths_and_workers( + scorer_parser, +) -> None: + plan = _plan() + argv = plan_lib.planned_argv(plan) + assert argv[:3] == [ + "/opt/venv/bin/python", + "-B", + "tools/score_us_release_head_to_head.py", + ] + expected = list(LOCAL_ARGV) + for index, item in enumerate(expected[:-1]): + if item in PATH_FLAGS: + ref = plan.inputs[PATH_FLAGS[item]] + expected[index + 1] = plan_lib.input_local_path("/work", ref) + elif item == "--out-prefix": + expected[index + 1] = "/work/state/h2h" + assert argv[3:] == [*expected, "--workers", "20"] + local_args = vars(scorer_parser.parse(LOCAL_ARGV)) + modal_args = vars(scorer_parser.parse(argv[3:])) + for flag in (*PATH_FLAGS, "--out-prefix"): + name = flag.removeprefix("--").replace("-", "_") + assert isinstance(local_args.pop(name), Path) + assert isinstance(modal_args.pop(name), Path) + assert local_args.pop("workers") == 1 + assert modal_args.pop("workers") == 20 + assert local_args == modal_args + assert modal_args["age_targets"] is False + assert modal_args["allow_unaged_dollar_targets"] is True + assert modal_args["maximum_microsim_batch_size"] == 2000 + # Each scorer worker gets one native numerical thread. + assert all(plan.env[name] == "1" for name in plan_lib.THREAD_ENV_KEYS) + + +def test_owned_flags_cover_the_scorer_surface_except_the_two_plan_options( + scorer_parser, +) -> None: + tool = plan_lib.US_RELEASE_HEAD_TO_HEAD + flags = { + flag + for flag in scorer_parser.parser._option_string_actions + if flag.startswith("--") + } - {"--help"} + option_flags = {"--workers", "--maximum-microsim-batch-size"} + assert {option.flag for option in tool.options.values()} == option_flags + assert set(tool.options) == {"workers", "maximum_microsim_batch_size"} + assert tool.owned_flags == flags - option_flags + assert { + "--age-targets", + "--no-age-targets", + "--allow-unaged-dollar-targets", + "--no-allow-unaged-dollar-targets", + "--maximum-microsimulation-batch-size", + } <= tool.owned_flags + + +@pytest.mark.parametrize( + "key", + [ + "incumbent", + "candidate", + "ledger_facts", + "out_prefix", + "candidate_manifest_sha256", + "candidate_worker_identity_attestation", + "congressional_district_vintage_crosswalk", + "age_targets", + "no_age_targets", + "allow_unaged_dollar_targets", + "no_allow_unaged_dollar_targets", + "maximum_microsimulation_batch_size", + ], +) +def test_paths_and_boolean_overrides_are_not_plan_options(key: str) -> None: + data = _plan_data() + data["options"][key] = True + with pytest.raises(plan_lib.PlanError, match="not allowlisted"): + plan_lib.parse_plan(data) + + +@pytest.mark.parametrize("value", ["20", True]) +def test_workers_must_be_an_integer_in_the_plan(value) -> None: + data = _plan_data() + data["options"]["workers"] = value + with pytest.raises(plan_lib.PlanError, match="must be int"): + plan_lib.parse_plan(data) + + +def test_head_to_head_timeout_covers_the_slice_estimate_and_cost_cap() -> None: + plan = _plan() + resources = plan_lib.HEAD_TO_HEAD + assert plan.resources is resources + assert (resources.cpu, resources.cpu_limit, resources.memory_gib) == (20, 20, 224) + assert resources.timeout_s == 17_100 + slice_wall_seconds = 1030 * 4.7 * 60 / plan.options["workers"] + # At least ten minutes remain for initialization before the tool budget; + # the container additionally reserves runner time and timeout margin. + assert plan.max_wall_seconds >= slice_wall_seconds + 10 * 60 + assert resources.timeout_s > ( + plan.max_wall_seconds + plan.stage_spec.runner_overhead_seconds + ) + per_second = ( + 20 * plan_lib.CPU_USD_PER_CORE_SECOND + 224 * plan_lib.MEMORY_USD_PER_GIB_SECOND + ) + ceiling = round(per_second * 17_100 * 3, 2) + assert ceiling == pytest.approx(38.95, abs=0.005) + assert ceiling <= plan_lib.HEAD_TO_HEAD_COST_CAP_USD == 40 + assert resources.estimated_usd(resources.timeout_s, 3) == ceiling + assert plan_lib.estimated_usd_at_timeout(plan) == ceiling + assert plan_lib.summarize(plan)["estimated_usd_at_timeout"] == ceiling + + +def test_head_to_head_registers_its_modal_functions_without_retries( + monkeypatch, +) -> None: + app = load_app(monkeypatch) + resources = plan_lib.HEAD_TO_HEAD + for nonpreemptible in (False, True): + options = app.RUNNERS[(resources.name, nonpreemptible)].modal_options + assert (options["cpu"], options["memory"], options["timeout"]) == ( + (20, 20), + 224 * 1024, + 17_100, + ) + assert options.get("nonpreemptible", False) is nonpreemptible + assert options["retries"] == 0 + plan = _plan() + runner = app.RUNNERS[(plan.resources.name, plan.nonpreemptible)] + assert runner is app.run_stage_head_to_head_nonpreemptible + calls = [] + monkeypatch.setattr( + app, "_run_stage", lambda data: calls.append(data) or {"ok": True} + ) + data = _plan_data() + assert runner(data) == {"ok": True} + assert calls == [data] diff --git a/tools/modal_us_stage.py b/tools/modal_us_stage.py index 93d637e929..ad4fac8a03 100644 --- a/tools/modal_us_stage.py +++ b/tools/modal_us_stage.py @@ -1095,6 +1095,33 @@ def run_stage_base_nonpreemptible(plan_data: dict) -> dict: return _run_stage(plan_data) +@app.function( + image=image, + volumes=VOLUMES, + secrets=_secrets(), + cpu=plan_lib.HEAD_TO_HEAD.modal_cpu, + memory=plan_lib.HEAD_TO_HEAD.memory_mib, + timeout=plan_lib.HEAD_TO_HEAD.timeout_s, + retries=0, +) +def run_stage_head_to_head(plan_data: dict) -> dict: + return _run_stage(plan_data) + + +@app.function( + image=image, + volumes=VOLUMES, + secrets=_secrets(), + cpu=plan_lib.HEAD_TO_HEAD.modal_cpu, + memory=plan_lib.HEAD_TO_HEAD.memory_mib, + timeout=plan_lib.HEAD_TO_HEAD.timeout_s, + retries=0, + nonpreemptible=True, +) +def run_stage_head_to_head_nonpreemptible(plan_data: dict) -> dict: + return _run_stage(plan_data) + + RUNNERS = { ("heavy", False): run_stage_heavy, ("heavy", True): run_stage_heavy_nonpreemptible, @@ -1103,6 +1130,8 @@ def run_stage_base_nonpreemptible(plan_data: dict) -> dict: ("check", False): run_stage_small, ("base", False): run_stage_base, ("base", True): run_stage_base_nonpreemptible, + ("head-to-head", False): run_stage_head_to_head, + ("head-to-head", True): run_stage_head_to_head_nonpreemptible, } diff --git a/tools/modal_us_stage_plan.py b/tools/modal_us_stage_plan.py index 9a5cefeb23..b039d4b6a2 100644 --- a/tools/modal_us_stage_plan.py +++ b/tools/modal_us_stage_plan.py @@ -259,7 +259,20 @@ def estimated_usd(self, wall_seconds: float, multiplier: float = 1.0) -> float: BASE = Resources( "base", cpu=4.0, memory_mib=112 * 1024, timeout_s=16_500, cpu_limit=4.0 ) -RESOURCE_CLASSES = {item.name: item for item in (CHECK, HEAVY, LIGHT, BASE)} +# Route A's head-to-head: each spawned worker retains a full repaired frame. +# The independent review's 9-10 GiB/worker is unmeasured: 20 * 10 GiB plus +# 24 GiB for the parent and headroom, not a measured aggregate peak. At +# 1,030 slices * 4.7 minutes / 20 workers the tool takes about 14,523 s. +# 17,100 s leaves staging, the normal 900 s runner reserve and compute margin. +# CPU is capped at the request; memory remains request-only like the other +# classes. The non-preemptible ceiling at the request is $38.95 at timeout. +HEAD_TO_HEAD = Resources( + "head-to-head", cpu=20.0, memory_mib=224 * 1024, timeout_s=17_100, cpu_limit=20.0 +) +HEAD_TO_HEAD_COST_CAP_USD = 40.0 +RESOURCE_CLASSES = { + item.name: item for item in (CHECK, HEAVY, LIGHT, BASE, HEAD_TO_HEAD) +} #: Max's cap for the base run (2026-09-29: non-preemptible, 4 hours, "about #: $15"). The base class's ceiling at its request (its timeout, #: non-preemptible, at list price) must not exceed it; a test holds this. @@ -835,9 +848,70 @@ def _puf_support_base_argv( stage_hash_seed_default=HASH_SEED, ) + +def _release_head_to_head_argv( + plan: Plan, input_paths: Mapping[str, str], state_dir: str +) -> list[str]: + return [ + "--incumbent", + input_paths["incumbent_h5"], + "--candidate", + input_paths["candidate_h5"], + "--ledger-facts", + input_paths["ledger_facts"], + "--out-prefix", + str(PurePosixPath(state_dir) / "h2h"), + ] + + +US_RELEASE_HEAD_TO_HEAD = ToolSpec( + name="us-release-head-to-head", + script="tools/score_us_release_head_to_head.py", + inputs=("incumbent_h5", "candidate_h5", "ledger_facts"), + stages={ + "score": StageSpec( + "score", + HEAD_TO_HEAD, + ("incumbent_h5", "candidate_h5", "ledger_facts"), + mirror_first=("h2h.json", "h2h.md"), + ) + }, + options={ + "workers": OptionFlag("--workers", int), + "maximum_microsim_batch_size": OptionFlag("--maximum-microsim-batch-size", int), + }, + owned_flags=frozenset( + { + "--incumbent", + "--candidate", + "--ledger-facts", + "--out-prefix", + "--candidate-manifest-sha256", + "--candidate-worker-identity-attestation", + "--congressional-district-vintage-crosswalk", + # Omit both BooleanOptionalActions to preserve the local run's + # defaults (age_targets=False, allow_unaged_dollar_targets=True). + # Reserve both spellings so plans cannot change that yardstick. + "--age-targets", + "--no-age-targets", + "--allow-unaged-dollar-targets", + "--no-allow-unaged-dollar-targets", + # Only the canonical batch-size spelling is a plan option. + "--maximum-microsimulation-batch-size", + } + ), + argv_builder=_release_head_to_head_argv, + parse_function="_parse_args", +) + TOOLS: dict[str, ToolSpec] = { tool.name: tool - for tool in (US_ACS_LOCAL_RELEASE, RUNNER_SMOKE, US_PUF_SUPPORT_BASE) + for tool in ( + US_ACS_LOCAL_RELEASE, + RUNNER_SMOKE, + US_PUF_SUPPORT_BASE, + US_RELEASE_HEAD_TO_HEAD, + ) } From 255d46419e75a14535b9b0d71588f3ff921db6a0 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sat, 10 Oct 2026 15:07:02 -0400 Subject: [PATCH 02/28] Pin the d844 plan to the merged scorer and expose --worker-max-slices as a plan option #1171 merged as 7639ef8b0, so the plan pins that commit on main. The scorer gained --worker-max-slices after this stage was written; it becomes the third plan option (unset in the d844 plan), and the ownership test and its parser fixture follow. The runbook's launch section no longer carries machine paths. Co-Authored-By: Claude Opus 5.5 --- ...-release-head-to-head-modal-stage.added.md | 1 + docs/us-modal-stage-route-a-h2h-plan.json | 6 +-- docs/us-modal-stage-runbook.md | 48 +++++++++---------- ...est_us_modal_stage_release_head_to_head.py | 26 +++++++--- tools/modal_us_stage_plan.py | 3 ++ 5 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 changelog.d/us-release-head-to-head-modal-stage.added.md diff --git a/changelog.d/us-release-head-to-head-modal-stage.added.md b/changelog.d/us-release-head-to-head-modal-stage.added.md new file mode 100644 index 0000000000..670b801dae --- /dev/null +++ b/changelog.d/us-release-head-to-head-modal-stage.added.md @@ -0,0 +1 @@ +The US head-to-head scorer is a Modal stage: `us-release-head-to-head` (one `score` stage; digest-pinned incumbent, candidate and ledger-feed inputs; `workers`, `maximum_microsim_batch_size` and `worker_max_slices` as the only plan options), with a `head-to-head` resource class (20 CPUs with the limit at the request, 224 GiB, 4 h 45 min, non-preemptible; list-price ceiling $38.95 per attempt). `docs/us-modal-stage-route-a-h2h-plan.json` is the d844 run (Route A against `populace-us-2024-spm-20260915`), pinned to the merge of #1171, and the runbook gains a "Route A head-to-head (d844)" section. diff --git a/docs/us-modal-stage-route-a-h2h-plan.json b/docs/us-modal-stage-route-a-h2h-plan.json index d1cdd1d9e0..610d40e46a 100644 --- a/docs/us-modal-stage-route-a-h2h-plan.json +++ b/docs/us-modal-stage-route-a-h2h-plan.json @@ -2,10 +2,10 @@ "schema": "microcosm-modal-us-stage-plan/1", "tool": "us-release-head-to-head", "stage": "score", - "run_id": "route-a-h2h-d844-20261009", + "run_id": "route-a-h2h-d844-20261010", "source": { - "commit": "5d1f71a2cb28b130f4ecbd5a17a29e8f639c7698", - "branch": "h2h-scorer-workers" + "commit": "7639ef8b02f65e295d8311cb51ec801f4030a3cd", + "branch": "main" }, "inputs": { "incumbent_h5": { diff --git a/docs/us-modal-stage-runbook.md b/docs/us-modal-stage-runbook.md index 29b3140e28..28e60d5fc2 100644 --- a/docs/us-modal-stage-runbook.md +++ b/docs/us-modal-stage-runbook.md @@ -1031,12 +1031,11 @@ same `run_id` would refuse either way; none is planned. (`populace-us-2024-0fb05b6-4b57d15a287c-20260930T150401Z`) with the US default (`populace-us-2024-spm-20260915`) on the frozen `consumer_facts_us_c5e5bf8.jsonl` ledger. The plan pins scorer commit -`5d1f71a2cb28b130f4ecbd5a17a29e8f639c7698` on `h2h-scorer-workers` (#1171). -The runner registration comes from this checkout. Before the paid run, -incorporate #1171's separate scorer fix round and update `source.commit` -and `source.branch` to its reviewed, pushed revision; repeat the local -validation and Modal check after repinning. This plan's current immutable -pin will not acquire those fixes when the branch moves. +`7639ef8b02f65e295d8311cb51ec801f4030a3cd` on `main`, the merge of #1171 +(`--workers`, the per-slice release of Core's variable modules, and the +recycling guard). The runner registration comes from this checkout. A plan's +pin is immutable: to pick up a later scorer change, update `source.commit`, +then repeat the local validation and the Modal check. The stage runs the local comparison's argv with staged paths and `--workers 20` added: @@ -1045,7 +1044,10 @@ The stage runs the local comparison's argv with staged paths and --incumbent X --candidate Y --ledger-facts Z --out-prefix P --maximum-microsim-batch-size 2000 --workers 20 ``` -Only `workers` and `maximum_microsim_batch_size` are plan options. Every +Only `workers`, `maximum_microsim_batch_size` and `worker_max_slices` are +plan options. `worker_max_slices` is unset in the d844 plan: the image's +Python 3.14 patch level decides whether the scorer accepts recycling (it +refuses below 3.14.7), and the per-slice module release is the memory fix. Every path flag, `--out-prefix`, the candidate-manifest pin, both spellings of each boolean, and the alternative batch-size spelling are runner-owned. The builder omits `--age-targets` and `--allow-unaged-dollar-targets`, so @@ -1129,30 +1131,28 @@ MICROCOSM_MODAL_PLAN=docs/us-modal-stage-route-a-h2h-plan.json \ ``` Require `CHECK OK`, including the pinned parser and all three volume -digests, before the paid run. Launch the paid run through -`893/bin/lsubmit.sh` under launchd, never from a session shell. -Prepare this job script in the assigned checkout; the absolute CLI and -working directory make the payload independent of launchd's default -`PATH` and working directory: +digests, before the paid run. Launch the paid run under launchd, never from a +session shell: a restart of the launching session kills a session-owned +client, and Modal then cancels the paid input (this happened to Route A's +base on 2026-09-29). From the checkout that holds this plan: ```bash -mkdir -p modal-runs/route-a-h2h-d844-20261009 -cat > modal-runs/route-a-h2h-d844-20261009/launch.sh <<'SH' +mkdir -p modal-runs/route-a-h2h-d844-20261010 +cat > modal-runs/route-a-h2h-d844-20261010/launch.sh < /bin/bash `; any +launchd submission whose parent is launchd works. Do not run `launch.sh` +directly in a session shell. Once the launch reports a receipt path, fetch that `score-.json` and the two scorecards. The receipt's `outputs` lists their relative paths, @@ -1160,7 +1160,7 @@ byte counts and sha256s. Fetch the tiny complete state, including the logs, so strict verification covers everything: ```bash -R=route-a-h2h-d844-20261009 +R=route-a-h2h-d844-20261010 mkdir -p "modal-runs/$R" modal volume get microcosm-us-stage-runs "runs/$R/receipts" "./modal-runs/$R/" modal volume get microcosm-us-stage-runs "runs/$R/state" "./modal-runs/$R/" diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py index 210ed411e8..e11cccaf85 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py +++ b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py @@ -60,6 +60,13 @@ def _plan() -> plan_lib.Plan: return plan_lib.parse_plan(_plan_data()) +_PARSER_FUNCTIONS = { + "_parse_args", + "_positive_workers", + "_positive_worker_max_slices", +} + + @pytest.fixture(scope="module") def scorer_parser(): """Run only the scorer's argparse functions, without its engine imports. @@ -92,10 +99,9 @@ def __init__(self, *args, **kwargs): functions = [ node for node in ast.parse(SCORER.read_text()).body - if isinstance(node, ast.FunctionDef) - and node.name in {"_parse_args", "_positive_workers"} + if isinstance(node, ast.FunctionDef) and node.name in _PARSER_FUNCTIONS ] - assert {node.name for node in functions} == {"_parse_args", "_positive_workers"} + assert {node.name for node in functions} == _PARSER_FUNCTIONS exec( compile(ast.Module(body=functions, type_ignores=[]), str(SCORER), "exec"), namespace, @@ -166,7 +172,7 @@ def test_modal_argv_equals_the_local_d844_command_apart_from_paths_and_workers( assert all(plan.env[name] == "1" for name in plan_lib.THREAD_ENV_KEYS) -def test_owned_flags_cover_the_scorer_surface_except_the_two_plan_options( +def test_owned_flags_cover_the_scorer_surface_except_the_plan_options( scorer_parser, ) -> None: tool = plan_lib.US_RELEASE_HEAD_TO_HEAD @@ -175,9 +181,17 @@ def test_owned_flags_cover_the_scorer_surface_except_the_two_plan_options( for flag in scorer_parser.parser._option_string_actions if flag.startswith("--") } - {"--help"} - option_flags = {"--workers", "--maximum-microsim-batch-size"} + option_flags = { + "--workers", + "--maximum-microsim-batch-size", + "--worker-max-slices", + } assert {option.flag for option in tool.options.values()} == option_flags - assert set(tool.options) == {"workers", "maximum_microsim_batch_size"} + assert set(tool.options) == { + "workers", + "maximum_microsim_batch_size", + "worker_max_slices", + } assert tool.owned_flags == flags - option_flags assert { "--age-targets", diff --git a/tools/modal_us_stage_plan.py b/tools/modal_us_stage_plan.py index b039d4b6a2..3fc74c0422 100644 --- a/tools/modal_us_stage_plan.py +++ b/tools/modal_us_stage_plan.py @@ -879,6 +879,9 @@ def _release_head_to_head_argv( options={ "workers": OptionFlag("--workers", int), "maximum_microsim_batch_size": OptionFlag("--maximum-microsim-batch-size", int), + # Off unless a plan sets it; the scorer refuses it on interpreters + # where replacing a recycled worker can deadlock. + "worker_max_slices": OptionFlag("--worker-max-slices", int), }, owned_flags=frozenset( { From badbdf1d74c4c4cbbeb7a5de1fc2ca01f08aa0fc Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Thu, 15 Oct 2026 05:21:20 -0400 Subject: [PATCH 03/28] Fix the Modal head-to-head check probe, hard-limit its memory, size it at 16 workers Address the #1190 review: the check-mode import probe now puts the scorer's directory on sys.path and registers the module in sys.modules, so tools that import a sibling (the scorer imports build_us_fiscal_refresh_release) pass the required check; a subprocess test runs the real probe (engine-contract-us). The head-to-head class's memory is a hard limit equal to its request, so an overrun OOM-kills the container instead of billing past the ceiling. The class is 16 CPUs / 192 GiB / 20,400 s (ceiling $38.91 at list); the runbook's ledger path is an operator placeholder. Co-Authored-By: Claude Opus 5.5 --- ...-release-head-to-head-modal-stage.added.md | 2 +- docs/us-modal-stage-route-a-h2h-plan.json | 4 +- docs/us-modal-stage-runbook.md | 88 +++++++++++-------- ...est_us_modal_stage_release_head_to_head.py | 65 ++++++++++++++ .../us/test_us_modal_stage_plan_tool.py | 11 ++- .../test_us_modal_stage_puf_support_base.py | 4 +- ...est_us_modal_stage_release_head_to_head.py | 50 ++++++++--- tools/modal_us_stage.py | 23 ++--- tools/modal_us_stage_plan.py | 66 +++++++++++--- 9 files changed, 234 insertions(+), 79 deletions(-) create mode 100644 packages/microcosm-build/tests/engine_contract/us/test_us_modal_stage_release_head_to_head.py diff --git a/changelog.d/us-release-head-to-head-modal-stage.added.md b/changelog.d/us-release-head-to-head-modal-stage.added.md index 670b801dae..4f6e7fb278 100644 --- a/changelog.d/us-release-head-to-head-modal-stage.added.md +++ b/changelog.d/us-release-head-to-head-modal-stage.added.md @@ -1 +1 @@ -The US head-to-head scorer is a Modal stage: `us-release-head-to-head` (one `score` stage; digest-pinned incumbent, candidate and ledger-feed inputs; `workers`, `maximum_microsim_batch_size` and `worker_max_slices` as the only plan options), with a `head-to-head` resource class (20 CPUs with the limit at the request, 224 GiB, 4 h 45 min, non-preemptible; list-price ceiling $38.95 per attempt). `docs/us-modal-stage-route-a-h2h-plan.json` is the d844 run (Route A against `populace-us-2024-spm-20260915`), pinned to the merge of #1171, and the runbook gains a "Route A head-to-head (d844)" section. +The US head-to-head scorer is a Modal stage: `us-release-head-to-head` (one `score` stage; digest-pinned incumbent, candidate and ledger-feed inputs; `workers`, `maximum_microsim_batch_size` and `worker_max_slices` as the only plan options), with a `head-to-head` resource class (16 CPUs and 192 GiB, both limited at the request; 20,400-second timeout; non-preemptible; CPU/memory list-price ceiling $38.91 through the timeout). `docs/us-modal-stage-route-a-h2h-plan.json` is the first 16-worker d844 run (Route A against `populace-us-2024-spm-20260915`), with a 19,200-second tool budget and pinned to the merge of #1171. The runbook documents the sizing estimate, costs outside the compute ceiling, the lack of a final receipt after a whole-container OOM, and operator-supplied input paths. Check mode imports sibling-dependent tools with their script directory on the module search path and registers the probed module before executing it. diff --git a/docs/us-modal-stage-route-a-h2h-plan.json b/docs/us-modal-stage-route-a-h2h-plan.json index 610d40e46a..92a0970c65 100644 --- a/docs/us-modal-stage-route-a-h2h-plan.json +++ b/docs/us-modal-stage-route-a-h2h-plan.json @@ -22,7 +22,7 @@ } }, "options": { - "workers": 20, + "workers": 16, "maximum_microsim_batch_size": 2000 }, "env": { @@ -33,6 +33,6 @@ "NUMEXPR_NUM_THREADS": "1", "BLIS_NUM_THREADS": "1" }, - "max_wall_seconds": 15900, + "max_wall_seconds": 19200, "nonpreemptible": true } diff --git a/docs/us-modal-stage-runbook.md b/docs/us-modal-stage-runbook.md index 28e60d5fc2..4651a116d7 100644 --- a/docs/us-modal-stage-runbook.md +++ b/docs/us-modal-stage-runbook.md @@ -27,6 +27,12 @@ Two files do the work: and, for the scorer, `packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py`. +The actual subprocess parser probe is covered by +`packages/microcosm-build/tests/engine_contract/us/test_us_modal_stage_release_head_to_head.py` +in `tools/ci_test_plan.py`'s `engine-contract-us` group. Importing the scorer +loads the US engine through a sibling tool, so this regression runs in US +engine CI. + Nothing here uploads to the Hugging Face Hub, touches `latest.json` or notifies anyone. The furthest a stage goes is `package`, which writes a release directory onto the runs volume. Publication stays the human step in @@ -163,19 +169,21 @@ local wall times in this table understate Modal's wall and cost. | package | 21.8 GB, 79 s | light | 2 cores, 48 GiB | about $0.01 | | check | n/a | check | 2 cores, 8 GiB, 30 min timeout | cents | | PUF-support base (`all`) | 72.5 GB, 2,788 s wall, 6,238 CPU-s | base | 4 cores (limit 4), 112 GiB, 4 h 35 min timeout | about $0.84 ($2.52 non-preemptible) | -| Route A head-to-head (`score`) | unmeasured aggregate peak; about 80 core-hours estimated locally | head-to-head | 20 cores (limit 20), 224 GiB, 4 h 45 min timeout | $38.95 non-preemptible at the timeout and request | +| Route A head-to-head (`score`) | unmeasured aggregate peak; about 80 core-hours estimated locally | head-to-head | 16 cores (limit 16), 192 GiB (limit 192), 5 h 40 min timeout | $38.91 non-preemptible compute through the timeout | The prices are Modal's list prices for standard compute, read from -modal.com/pricing on 22 September 2026 and unchanged on 9 October: +modal.com/pricing on 22 September 2026 and unchanged on 10 October: $0.0000131 per core-second and $0.00000222 per GiB-second. Modal bills the higher of the request and actual use (modal.com/docs/guide/resources). The heavy class costs about $1.21 an hour at its request, so an 8-hour timeout costs about $9.70 at the request; CPU or memory used above the request bills above that. With `"nonpreemptible": true` every figure is three times higher: about $3.63 an hour for the heavy class. The base and head-to-head -classes set a CPU limit equal to their request; the others are request-only for CPU, -and every class is request-only for memory, so a stage that used more cores -or more memory than its request would be billed for them. The engine pass in +classes set a CPU limit equal to their request; the others are request-only for CPU. +The head-to-head class also sets a memory limit equal to its request. Other +classes retain request-only memory because changing those workloads is outside +the head-to-head trial's sizing change; their memory use above the request is +billed. The engine pass in materialize is single-threaded (CPU seconds roughly equal wall seconds), so extra cores would not speed it up. The table leaves out volume storage and image builds. The base and head-to-head classes are sized in their sections below. @@ -1038,10 +1046,10 @@ pin is immutable: to pick up a later scorer change, update `source.commit`, then repeat the local validation and the Modal check. The stage runs the local comparison's argv with staged paths and -`--workers 20` added: +`--workers 16` added: ```text ---incumbent X --candidate Y --ledger-facts Z --out-prefix P --maximum-microsim-batch-size 2000 --workers 20 +--incumbent X --candidate Y --ledger-facts Z --out-prefix P --maximum-microsim-batch-size 2000 --workers 16 ``` Only `workers`, `maximum_microsim_batch_size` and `worker_max_slices` are @@ -1055,8 +1063,8 @@ the scorer uses the same defaults as the sequential run: `False` and `True`, respectively. The crosswalk and candidate pool/attestation flags are also omitted; the scorer chooses its normal bundled crosswalk. Changing this scoring yardstick requires a reviewed registration change. -The plan sets the five native numerical thread counts to `1`, so twenty -spawned workers do not each start a twenty-thread BLAS/OpenMP pool. +The plan sets the five native numerical thread counts to `1`, so sixteen +spawned workers do not each start a sixteen-thread BLAS/OpenMP pool. That is an execution choice; the engine-free argv test does not prove numerical parity across platforms or thread counts. @@ -1068,40 +1076,50 @@ and artifact identity. Do not upload either H5 under an extensionless hash. The incumbent is 826,917,837 bytes; the ledger is 164,603,204 bytes. The candidate's size was not supplied; its digest is the byte identity. -**Resources and ceiling.** Class `head-to-head` requests 20 physical -cores with CPU limit 20 and 224 GiB. The d844 plan uses non-preemptible -placement; both class runners have `retries=0`. At twenty workers, -1,030 slices × 4.7 minutes / 20 is 14,523 seconds (about 4 hours 2 minutes). -The tool budget is 15,900 seconds (4 hours 25 minutes), with 1,377 seconds -for initialization and compute margin. The 17,100-second timeout -(4 hours 45 minutes) adds the normal 900-second runner reserve and -300 seconds for staging. Slow staging reduces the tool's available time; -the runner preserves the reserve for logs, hashes, mirroring and receipt. -The budget estimate including the reserve is $38.27. +**Resources and ceiling.** For the first full attempt, class `head-to-head` +requests 16 physical cores with CPU limit 16 and 192 GiB with memory limit +192 GiB. The d844 plan uses non-preemptible placement; both class runners +have `retries=0`. At sixteen workers, 1,030 slices × 4.7 minutes / 16 is +18,153.75 seconds (about 5 hours 3 minutes). The tool budget is 19,200 +seconds (5 hours 20 minutes), leaving about 1,046 seconds for initialization +and compute margin. The 20,400-second timeout (5 hours 40 minutes) adds +the normal 900-second runner reserve and 300 seconds for staging. Slow +staging reduces the tool's available time; the runner preserves the reserve +for logs, hashes, mirroring and receipt. The budget estimate including the +reserve is $38.34. Using the existing runbook formula and [Modal's list prices](https://modal.com/pricing) -(checked 9 October 2026), the request held through the timeout costs -`(20 × $0.0000131 + 224 × $0.00000222) × 17,100 × 3 = $38.95`. -**The per-attempt ceiling at the request is below $40.** Memory has no hard -limit; use above 224 GiB bills above this estimate. Startup/image work, -the check, storage, timeout overshoot and another attempt are outside this -execution ceiling, as for the base stage. A 256 GiB class at this timeout -would cost **$42.60, above $40**; use the registered 224 GiB class for this -plan. A possible smaller fallback is 16 workers, 16 CPUs and 192 GiB with -a 20,700-second timeout (5 hours 45 minutes), listing at $39.49; that -requires a reviewed class and matching plan change before use. +(checked 10 October 2026), CPU and memory compute through the timeout costs +`(16 × $0.0000131 + 192 × $0.00000222) × 20,400 × 3 = $38.913408`, +or **$38.91, below $40**. The CPU and memory limits equal their requests, +so memory over-use OOM-kills the container instead of increasing the billed +memory allocation. The function timeout covers staging, tool initialization, +scoring and runner cleanup. Startup/image work outside that interval, the +check, storage, timeout-enforcement overshoot and another attempt remain +outside this compute ceiling; it is not a cap on total Modal account spend. The independent review's 9–10 GiB per worker is unmeasured. Each worker holds a full copy of the repaired frame, and the parent retains the -original and repaired frames. The 224 GiB request allows 200 GiB for -workers plus 24 GiB for the parent, runner and spawn serialization, with -limited spare capacity. This is an estimate, not a measured aggregate +original and repaired frames. The 192 GiB limit allows an estimated 160 GiB +for workers plus 32 GiB for the parent, runner and spawn serialization. +This is an estimate, not a measured aggregate peak. The receipt's `peak_rss_bytes` is a child-process peak from -`RUSAGE_CHILDREN`, not the sum of twenty workers; use Modal's container -memory measurements to assess this sizing after the run. The stage writes +`RUSAGE_CHILDREN`, not the sum of sixteen workers; profile representative +2,000-household slices of the full candidate and use Modal's container +memory measurements to assess this sizing after the run. Fewer workers +reduce aggregate memory exposure but cannot prevent one worker exceeding +the scorer's 20 GiB RSS guard. The stage writes scorecards and logs, mirrors `h2h.json` and `h2h.md` first, and has no checkpoint/resume state or additional disk/write-probe requirement. +A worker death or RSS-guard failure leaves a failed scorer exit. If the +runner survives, it writes a **FAILED receipt and logs**; the scorer writes +scorecards only after the comparison finishes. A whole-container OOM can +leave a partial bill with **no final receipt or mirrored output**, because +receipt creation and mirroring happen after the tool exits. Inspect the +container logs and measurements when no receipt appears; do not assume the +absence of a receipt means the attempt was free. + Stage the inputs in the `policyengine` workspace. Set these variables to the existing local files; the ledger path is the one used by Route A's base. `upload-commands` only hashes files and prints commands: it performs @@ -1112,7 +1130,7 @@ that `put` and let check mode verify its digest; do not overwrite it. ```bash INCUMBENT_H5=/path/to/populace-us-2024-spm-20260915/populace_us_2024.h5 CANDIDATE_H5=/path/to/populace-us-2024-0fb05b6-4b57d15a287c-20260930T150401Z/populace_us_2024.h5 -LEDGER_FACTS=$HOME/PolicyEngine/_buildh-runtime/inputs/consumer_facts_us_c5e5bf8.jsonl +LEDGER_FACTS=/path/to/consumer_facts_us_c5e5bf8.jsonl python3 tools/modal_us_stage_plan.py upload-commands \ docs/us-modal-stage-route-a-h2h-plan.json \ incumbent_h5="$INCUMBENT_H5" candidate_h5="$CANDIDATE_H5" ledger_facts="$LEDGER_FACTS" diff --git a/packages/microcosm-build/tests/engine_contract/us/test_us_modal_stage_release_head_to_head.py b/packages/microcosm-build/tests/engine_contract/us/test_us_modal_stage_release_head_to_head.py new file mode 100644 index 0000000000..2397762ea8 --- /dev/null +++ b/packages/microcosm-build/tests/engine_contract/us/test_us_modal_stage_release_head_to_head.py @@ -0,0 +1,65 @@ +"""Exercise the actual Modal parser probe with the registered US tools. + +The scorer imports the US engine through its sibling release tool, so this +subprocess regression belongs to ci_test_plan.py's engine-contract-us group. +It parses argv without calculating households or reading population H5 files. +""" + +from __future__ import annotations + +import json +import os +import sys + +import pytest + +from test_support.microcosm_build.us_modal_stage_plan_tool import ( + ROOT, + base_plan_data, + load_app, + plan_data, + plan_lib, + smoke_plan_data, +) + + +@pytest.mark.parametrize( + ("data", "stages"), + [ + pytest.param( + json.loads( + (ROOT / "docs" / "us-modal-stage-route-a-h2h-plan.json").read_text() + ), + None, + id="us-release-head-to-head", + ), + pytest.param(plan_data(), ["materialize"], id="us-acs-local-release"), + pytest.param(base_plan_data(), None, id="us-puf-support-base"), + ], +) +def test_registered_tool_parses_with_the_actual_subprocess_probe( + data: dict, stages: list[str] | None, monkeypatch +) -> None: + app = load_app(monkeypatch) + monkeypatch.setattr(plan_lib, "IMAGE_REPO_ROOT", str(ROOT)) + plan = plan_lib.parse_plan(data) + argv = plan_lib.planned_argv(plan) + argv[0] = sys.executable + env = {**os.environ, **plan.env} + # A caller's PYTHONPATH must not hide missing sibling-import support. + env.pop("PYTHONPATH", None) + + result = app._parse_check(plan, argv, env) + + assert result["returncode"] == 0, result + assert json.loads(result["stdout_tail"].splitlines()[-1]) == {"stages": stages} + + +def test_inline_runner_smoke_still_skips_the_parser_probe(monkeypatch) -> None: + app = load_app(monkeypatch) + plan = plan_lib.parse_plan(smoke_plan_data()) + + assert app._parse_check(plan, plan_lib.planned_argv(plan), {}) == { + "returncode": 0, + "skipped": "inline tool; nothing to parse", + } diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_plan_tool.py b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_plan_tool.py index 90307cd5fb..92b8e12789 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_plan_tool.py +++ b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_plan_tool.py @@ -1315,13 +1315,18 @@ def test_every_valid_plan_has_a_runner_with_its_class_and_placement(app) -> None options = runner.modal_options assert (options["cpu"], options["memory"], options["timeout"]) == ( resources.modal_cpu, - resources.memory_mib, + resources.modal_memory, resources.timeout_s, ) assert options.get("nonpreemptible", False) is nonpreemptible assert options["retries"] == 0 - # Memory is a request everywhere (an int, never a (request, limit)). - assert isinstance(options["memory"], int) + # The first scorer attempt caps memory to keep its compute cost under + # $40. Existing ACS/base/smoke requests retain their reviewed behavior. + if name == "head-to-head": + assert options["memory"] == (192 * 1024, 192 * 1024) + else: + assert isinstance(options["memory"], int) + assert resources.memory_limit_mib is None # The base sets a CPU limit equal to its request, and Modal throttles CPU # use above the limit, which is what the $15 ceiling counts on; the ACS # classes keep request-only. diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_puf_support_base.py b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_puf_support_base.py index 034b17ebd4..acb05a9120 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_puf_support_base.py +++ b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_puf_support_base.py @@ -2428,8 +2428,8 @@ def test_the_hand_off_never_overwrites_a_base(tmp_path: Path) -> None: def test_the_runbook_names_every_registered_tool() -> None: text = RUNBOOK.read_text() intro = text[: text.index("Two files do the work")] - assert len(plan_lib.TOOLS) == 3 - assert "Three tools are registered" in intro + assert len(plan_lib.TOOLS) == 4 + assert "Four tools are registered" in intro for name, tool in plan_lib.TOOLS.items(): assert f"`{name}`" in intro, name if tool.script is not None: diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py index e11cccaf85..06dac497fb 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py +++ b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py @@ -122,9 +122,9 @@ def test_d844_plan_validates_with_digest_pinned_loader_filenames() -> None: ) assert set(tool.stages) == {"score"} assert set(tool.inputs) == set(tool.stages["score"].required_inputs) == set(INPUTS) - assert plan.options == {"maximum_microsim_batch_size": 2000, "workers": 20} + assert plan.options == {"maximum_microsim_batch_size": 2000, "workers": 16} assert plan.nonpreemptible is True - assert plan.max_wall_seconds == 15_900 + assert plan.max_wall_seconds == 19_200 for role, (filename, digest) in INPUTS.items(): ref = plan.inputs[role] assert (ref.kind, ref.filename, ref.sha256) == ("volume", filename, digest) @@ -155,7 +155,7 @@ def test_modal_argv_equals_the_local_d844_command_apart_from_paths_and_workers( expected[index + 1] = plan_lib.input_local_path("/work", ref) elif item == "--out-prefix": expected[index + 1] = "/work/state/h2h" - assert argv[3:] == [*expected, "--workers", "20"] + assert argv[3:] == [*expected, "--workers", "16"] local_args = vars(scorer_parser.parse(LOCAL_ARGV)) modal_args = vars(scorer_parser.parse(argv[3:])) for flag in (*PATH_FLAGS, "--out-prefix"): @@ -163,7 +163,7 @@ def test_modal_argv_equals_the_local_d844_command_apart_from_paths_and_workers( assert isinstance(local_args.pop(name), Path) assert isinstance(modal_args.pop(name), Path) assert local_args.pop("workers") == 1 - assert modal_args.pop("workers") == 20 + assert modal_args.pop("workers") == 16 assert local_args == modal_args assert modal_args["age_targets"] is False assert modal_args["allow_unaged_dollar_targets"] is True @@ -238,8 +238,9 @@ def test_head_to_head_timeout_covers_the_slice_estimate_and_cost_cap() -> None: plan = _plan() resources = plan_lib.HEAD_TO_HEAD assert plan.resources is resources - assert (resources.cpu, resources.cpu_limit, resources.memory_gib) == (20, 20, 224) - assert resources.timeout_s == 17_100 + assert (resources.cpu, resources.cpu_limit, resources.memory_gib) == (16, 16, 192) + assert resources.memory_limit_mib == resources.memory_mib == 192 * 1024 + assert resources.timeout_s == 20_400 slice_wall_seconds = 1030 * 4.7 * 60 / plan.options["workers"] # At least ten minutes remain for initialization before the tool budget; # the container additionally reserves runner time and timeout margin. @@ -248,14 +249,24 @@ def test_head_to_head_timeout_covers_the_slice_estimate_and_cost_cap() -> None: plan.max_wall_seconds + plan.stage_spec.runner_overhead_seconds ) per_second = ( - 20 * plan_lib.CPU_USD_PER_CORE_SECOND + 224 * plan_lib.MEMORY_USD_PER_GIB_SECOND + resources.cpu * plan_lib.CPU_USD_PER_CORE_SECOND + + resources.memory_gib * plan_lib.MEMORY_USD_PER_GIB_SECOND ) - ceiling = round(per_second * 17_100 * 3, 2) - assert ceiling == pytest.approx(38.95, abs=0.005) + timeout_cost = ( + per_second * resources.timeout_s * plan_lib.NONPREEMPTIBLE_PRICE_MULTIPLIER + ) + assert timeout_cost < plan_lib.HEAD_TO_HEAD_COST_CAP_USD + ceiling = round(timeout_cost, 2) + assert ceiling == pytest.approx(38.91, abs=0.005) assert ceiling <= plan_lib.HEAD_TO_HEAD_COST_CAP_USD == 40 - assert resources.estimated_usd(resources.timeout_s, 3) == ceiling + assert ( + resources.estimated_usd(resources.timeout_s, plan.price_multiplier) == ceiling + ) assert plan_lib.estimated_usd_at_timeout(plan) == ceiling - assert plan_lib.summarize(plan)["estimated_usd_at_timeout"] == ceiling + summary = plan_lib.summarize(plan) + assert summary["estimated_usd_at_timeout"] == ceiling + assert summary["estimated_usd_at_max_wall"] == pytest.approx(38.34, abs=0.005) + assert summary["resources"]["memory_limit_gib"] == resources.memory_gib def test_head_to_head_registers_its_modal_functions_without_retries( @@ -266,9 +277,9 @@ def test_head_to_head_registers_its_modal_functions_without_retries( for nonpreemptible in (False, True): options = app.RUNNERS[(resources.name, nonpreemptible)].modal_options assert (options["cpu"], options["memory"], options["timeout"]) == ( - (20, 20), - 224 * 1024, - 17_100, + (16, 16), + (192 * 1024, 192 * 1024), + 20_400, ) assert options.get("nonpreemptible", False) is nonpreemptible assert options["retries"] == 0 @@ -282,3 +293,14 @@ def test_head_to_head_registers_its_modal_functions_without_retries( data = _plan_data() assert runner(data) == {"ok": True} assert calls == [data] + + +def test_a_memory_limit_below_the_request_is_refused() -> None: + with pytest.raises(ValueError, match="memory limit .* below the request"): + plan_lib.Resources( + "x", cpu=1, memory_mib=1024, timeout_s=60, memory_limit_mib=512 + ) + assert plan_lib.HEAD_TO_HEAD.modal_memory == (192 * 1024, 192 * 1024) + for resources in (plan_lib.CHECK, plan_lib.HEAVY, plan_lib.LIGHT, plan_lib.BASE): + assert resources.modal_memory == resources.memory_mib + assert resources.memory_limit_mib is None diff --git a/tools/modal_us_stage.py b/tools/modal_us_stage.py index ad4fac8a03..9cc4191fbc 100644 --- a/tools/modal_us_stage.py +++ b/tools/modal_us_stage.py @@ -333,8 +333,11 @@ def _check_input(ref: plan_lib.InputRef, work: Path) -> dict[str, object]: _PARSE_SNIPPET = """ import importlib.util, json, sys +from pathlib import Path +sys.path.insert(0, str(Path(sys.argv[1]).resolve().parent)) spec = importlib.util.spec_from_file_location("stage_tool", sys.argv[1]) module = importlib.util.module_from_spec(spec) +sys.modules[spec.name] = module spec.loader.exec_module(module) args = getattr(module, sys.argv[2])(sys.argv[3:]) print(json.dumps({"stages": list(getattr(args, "stages", [])) or None})) @@ -576,7 +579,7 @@ def _load_json(path: Path) -> dict | None: volumes=VOLUMES, secrets=_secrets(), cpu=plan_lib.CHECK.modal_cpu, - memory=plan_lib.CHECK.memory_mib, + memory=plan_lib.CHECK.modal_memory, timeout=plan_lib.CHECK.timeout_s, retries=0, ) @@ -998,7 +1001,7 @@ def _attempt_stage( volumes=VOLUMES, secrets=_secrets(), cpu=plan_lib.HEAVY.modal_cpu, - memory=plan_lib.HEAVY.memory_mib, + memory=plan_lib.HEAVY.modal_memory, timeout=plan_lib.HEAVY.timeout_s, retries=0, ) @@ -1011,7 +1014,7 @@ def run_stage_heavy(plan_data: dict) -> dict: volumes=VOLUMES, secrets=_secrets(), cpu=plan_lib.HEAVY.modal_cpu, - memory=plan_lib.HEAVY.memory_mib, + memory=plan_lib.HEAVY.modal_memory, timeout=plan_lib.HEAVY.timeout_s, retries=0, nonpreemptible=True, @@ -1025,7 +1028,7 @@ def run_stage_heavy_nonpreemptible(plan_data: dict) -> dict: volumes=VOLUMES, secrets=_secrets(), cpu=plan_lib.LIGHT.modal_cpu, - memory=plan_lib.LIGHT.memory_mib, + memory=plan_lib.LIGHT.modal_memory, timeout=plan_lib.LIGHT.timeout_s, retries=0, ) @@ -1038,7 +1041,7 @@ def run_stage_light(plan_data: dict) -> dict: volumes=VOLUMES, secrets=_secrets(), cpu=plan_lib.LIGHT.modal_cpu, - memory=plan_lib.LIGHT.memory_mib, + memory=plan_lib.LIGHT.modal_memory, timeout=plan_lib.LIGHT.timeout_s, retries=0, nonpreemptible=True, @@ -1052,7 +1055,7 @@ def run_stage_light_nonpreemptible(plan_data: dict) -> dict: volumes=VOLUMES, secrets=_secrets(), cpu=plan_lib.CHECK.modal_cpu, - memory=plan_lib.CHECK.memory_mib, + memory=plan_lib.CHECK.modal_memory, timeout=plan_lib.CHECK.timeout_s, retries=0, ) @@ -1073,7 +1076,7 @@ def run_stage_small(plan_data: dict) -> dict: volumes=VOLUMES, secrets=_secrets(), cpu=plan_lib.BASE.modal_cpu, - memory=plan_lib.BASE.memory_mib, + memory=plan_lib.BASE.modal_memory, timeout=plan_lib.BASE.timeout_s, retries=0, ) @@ -1086,7 +1089,7 @@ def run_stage_base(plan_data: dict) -> dict: volumes=VOLUMES, secrets=_secrets(), cpu=plan_lib.BASE.modal_cpu, - memory=plan_lib.BASE.memory_mib, + memory=plan_lib.BASE.modal_memory, timeout=plan_lib.BASE.timeout_s, retries=0, nonpreemptible=True, @@ -1100,7 +1103,7 @@ def run_stage_base_nonpreemptible(plan_data: dict) -> dict: volumes=VOLUMES, secrets=_secrets(), cpu=plan_lib.HEAD_TO_HEAD.modal_cpu, - memory=plan_lib.HEAD_TO_HEAD.memory_mib, + memory=plan_lib.HEAD_TO_HEAD.modal_memory, timeout=plan_lib.HEAD_TO_HEAD.timeout_s, retries=0, ) @@ -1113,7 +1116,7 @@ def run_stage_head_to_head(plan_data: dict) -> dict: volumes=VOLUMES, secrets=_secrets(), cpu=plan_lib.HEAD_TO_HEAD.modal_cpu, - memory=plan_lib.HEAD_TO_HEAD.memory_mib, + memory=plan_lib.HEAD_TO_HEAD.modal_memory, timeout=plan_lib.HEAD_TO_HEAD.timeout_s, retries=0, nonpreemptible=True, diff --git a/tools/modal_us_stage_plan.py b/tools/modal_us_stage_plan.py index 3fc74c0422..54718028a4 100644 --- a/tools/modal_us_stage_plan.py +++ b/tools/modal_us_stage_plan.py @@ -77,7 +77,8 @@ # Modal list prices for standard (non-sandbox) compute, read from # https://modal.com/pricing on 2026-09-22. Modal bills the higher of the # request and actual use, so an estimate from the request is exact while the -# stage stays inside its request and a floor when it uses more. +# stage stays inside its request and a floor when it uses more. Resource +# limits equal to the requests bound the head-to-head class's compute bill. CPU_USD_PER_CORE_SECOND = 0.0000131 MEMORY_USD_PER_GIB_SECOND = 0.00000222 # Modal applies this to the CPU and memory list price of a function set @@ -161,8 +162,10 @@ class Resources: limit can bill CPU above its request, and :meth:`estimated_usd` is then a floor. For a class whose limit equals its request, Modal throttles CPU use above the limit, which is the request, and the estimate counts CPU - at the request on that basis. Memory has no limit in any class: use - above the request is billed at use. + at the request on that basis. ``memory_limit_mib`` supplies Modal's hard + memory limit (``memory=(request, limit)``); exceeding it OOM-kills the + container. Memory remains request-only when no limit is set, so use + above the request can then raise the bill. """ name: str @@ -170,6 +173,7 @@ class Resources: memory_mib: int timeout_s: int cpu_limit: float | None = None + memory_limit_mib: int | None = None def __post_init__(self) -> None: if self.cpu_limit is not None and self.cpu_limit < self.cpu: @@ -177,6 +181,14 @@ def __post_init__(self) -> None: f"class {self.name!r}: CPU limit {self.cpu_limit} is below " f"the request {self.cpu}" ) + if ( + self.memory_limit_mib is not None + and self.memory_limit_mib < self.memory_mib + ): + raise ValueError( + f"class {self.name!r}: memory limit {self.memory_limit_mib} MiB " + f"is below the request {self.memory_mib} MiB" + ) @property def modal_cpu(self) -> float | tuple[float, float]: @@ -184,6 +196,16 @@ def modal_cpu(self) -> float | tuple[float, float]: return self.cpu if self.cpu_limit is None else (self.cpu, self.cpu_limit) + @property + def modal_memory(self) -> int | tuple[int, int]: + """The ``memory`` argument of the class's Modal functions, in MiB.""" + + return ( + self.memory_mib + if self.memory_limit_mib is None + else (self.memory_mib, self.memory_limit_mib) + ) + @property def memory_gib(self) -> float: return self.memory_mib / 1024 @@ -260,14 +282,22 @@ def estimated_usd(self, wall_seconds: float, multiplier: float = 1.0) -> float: "base", cpu=4.0, memory_mib=112 * 1024, timeout_s=16_500, cpu_limit=4.0 ) # Route A's head-to-head: each spawned worker retains a full repaired frame. -# The independent review's 9-10 GiB/worker is unmeasured: 20 * 10 GiB plus -# 24 GiB for the parent and headroom, not a measured aggregate peak. At -# 1,030 slices * 4.7 minutes / 20 workers the tool takes about 14,523 s. -# 17,100 s leaves staging, the normal 900 s runner reserve and compute margin. -# CPU is capped at the request; memory remains request-only like the other -# classes. The non-preemptible ceiling at the request is $38.95 at timeout. +# The independent review's 9-10 GiB/worker is unmeasured: 16 * 10 GiB plus +# 32 GiB for the parent and headroom, not a measured aggregate peak. At +# 1,030 slices * 4.7 minutes / 16 workers the tool takes about 18,154 s. +# 20,400 s leaves staging, the normal 900 s runner reserve and compute margin. +# CPU and memory are limited to their requests, bounding the non-preemptible +# execution-time compute estimate at $38.91 for the whole timeout. Exceeding +# the memory limit kills the container before it can write a final receipt. +# Other classes retain their reviewed request-only memory behavior: this +# first scorer attempt has an explicit $40 cap and unmeasured worker peaks. HEAD_TO_HEAD = Resources( - "head-to-head", cpu=20.0, memory_mib=224 * 1024, timeout_s=17_100, cpu_limit=20.0 + "head-to-head", + cpu=16.0, + memory_mib=192 * 1024, + timeout_s=20_400, + cpu_limit=16.0, + memory_limit_mib=192 * 1024, ) HEAD_TO_HEAD_COST_CAP_USD = 40.0 RESOURCE_CLASSES = { @@ -1973,6 +2003,11 @@ def build_receipt( "cpu": resources.cpu, "cpu_limit": resources.cpu_limit, "memory_mib": resources.memory_mib, + **( + {"memory_limit_mib": resources.memory_limit_mib} + if resources.memory_limit_mib is not None + else {} + ), "timeout_s": resources.timeout_s, "nonpreemptible": plan.nonpreemptible, }, @@ -2515,8 +2550,10 @@ def estimated_usd_at_timeout(plan: Plan) -> float: (modal.com/docs/guide/timeouts). This is the ceiling of one attempt at the request: for CPU it rests on a CPU limit equal to the request (``Resources.cpu_limit``), above which Modal throttles CPU use, and it - never holds for memory used above the request, which is billed at use - (modal.com/docs/guide/resources). Scheduling is outside the timeout, + holds for memory when its hard limit also equals the request + (``Resources.memory_limit_mib``). Without that limit, memory use above + the request is billed at use (modal.com/docs/guide/resources). + Scheduling is outside the timeout, container startup is timed separately (``startup_timeout``), and a function may run a handful of seconds past its timeout (modal.com/docs/guide/timeouts); Modal's billing report is the billed @@ -2541,6 +2578,11 @@ def summarize(plan: Plan) -> dict[str, object]: "cpu": resources.cpu, "cpu_limit": resources.cpu_limit, "memory_gib": resources.memory_gib, + **( + {"memory_limit_gib": resources.memory_limit_mib / 1024} + if resources.memory_limit_mib is not None + else {} + ), "timeout_h": resources.timeout_s / 3600, "timeout_s": resources.timeout_s, "nonpreemptible": plan.nonpreemptible, From 39a2f6b0cc98c770f9f1b414c66b9499e30cd015 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Wed, 11 Nov 2026 10:23:22 -0500 Subject: [PATCH 04/28] Re-pin the d844 head-to-head plan to the d1386 build and main's scorer Max cancelled the head-to-head of the September Route A release on 2026-10-15 and asked for it on the d1386 build instead. The candidate is populace-us-2024-b5db384-8b0c1950b65f-20261024T083103Z (H5 sha256 2d9c8586), the scorer pin moves to main 2cfe3043d (policyengine-us 2.2.1, the engine the d1386 manifest names), and the run id becomes route-a-h2h-d844-d1386-r1. The incumbent and the c5e5bf8 register stay as d844 fixed them. The class sizing is unchanged here; it waits on the at-scale memory measurement. Co-Authored-By: Claude Opus 5.5 --- docs/us-modal-stage-route-a-h2h-plan.json | 8 ++--- docs/us-modal-stage-runbook.md | 31 ++++++++++--------- ...est_us_modal_stage_release_head_to_head.py | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/docs/us-modal-stage-route-a-h2h-plan.json b/docs/us-modal-stage-route-a-h2h-plan.json index 92a0970c65..1289bd387c 100644 --- a/docs/us-modal-stage-route-a-h2h-plan.json +++ b/docs/us-modal-stage-route-a-h2h-plan.json @@ -2,9 +2,9 @@ "schema": "microcosm-modal-us-stage-plan/1", "tool": "us-release-head-to-head", "stage": "score", - "run_id": "route-a-h2h-d844-20261010", + "run_id": "route-a-h2h-d844-d1386-r1", "source": { - "commit": "7639ef8b02f65e295d8311cb51ec801f4030a3cd", + "commit": "2cfe3043d747b929e349c8de2486acf80b5f17f2", "branch": "main" }, "inputs": { @@ -13,8 +13,8 @@ "sha256": "6496cc4393d4d3c6574f76eca231de5898c803b9067645591fd5c4d3e65aee84" }, "candidate_h5": { - "uri": "volume://cas/sha256/417d23aed4d044de2e657a7b5d856136975d25739dbdb4ddd72866f841de1559/populace_us_2024.h5", - "sha256": "417d23aed4d044de2e657a7b5d856136975d25739dbdb4ddd72866f841de1559" + "uri": "volume://cas/sha256/2d9c8586c45c32e5ca27357317f4de93b526cc51dd28b15b71ed43e47e142e79/populace_us_2024.h5", + "sha256": "2d9c8586c45c32e5ca27357317f4de93b526cc51dd28b15b71ed43e47e142e79" }, "ledger_facts": { "uri": "volume://cas/sha256/b85437390021777e746f507c5890305496baf5fc7f2c78ba08ddb090f4839801/consumer_facts_us_c5e5bf8.jsonl", diff --git a/docs/us-modal-stage-runbook.md b/docs/us-modal-stage-runbook.md index 45ba210d69..4d0cbd9718 100644 --- a/docs/us-modal-stage-runbook.md +++ b/docs/us-modal-stage-runbook.md @@ -1624,13 +1624,16 @@ certification still determine whether the release is accepted. ## Route A head-to-head (d844) -`docs/us-modal-stage-route-a-h2h-plan.json` compares Route A -(`populace-us-2024-0fb05b6-4b57d15a287c-20260930T150401Z`) with the US +`docs/us-modal-stage-route-a-h2h-plan.json` compares the d1386 Route A +build (`populace-us-2024-b5db384-8b0c1950b65f-20261024T083103Z`) with the US default (`populace-us-2024-spm-20260915`) on the frozen -`consumer_facts_us_c5e5bf8.jsonl` ledger. The plan pins scorer commit -`7639ef8b02f65e295d8311cb51ec801f4030a3cd` on `main`, the merge of #1171 -(`--workers`, the per-slice release of Core's variable modules, and the -recycling guard). The runner registration comes from this checkout. A plan's +`consumer_facts_us_c5e5bf8.jsonl` ledger, the register d844 fixed before any +result. The d1386 build was calibrated on `consumer_facts_us_51aa40f.jsonl` +and the default on an older feed, so neither was fit to this register. The +plan pins scorer commit `2cfe3043d747b929e349c8de2486acf80b5f17f2` on +`main`, which carries #1171 (`--workers`, the per-slice release of Core's +variable modules, and the recycling guard) and locks policyengine-us 2.2.1, +the engine the d1386 manifest names. The runner registration comes from this checkout. A plan's pin is immutable: to pick up a later scorer change, update `source.commit`, then repeat the local validation and the Modal check. @@ -1662,8 +1665,8 @@ directories and stage to `/work/inputs/incumbent_h5/populace_us_2024.h5` and `/work/inputs/candidate_h5/populace_us_2024.h5`. Keep the `.h5` suffix and this filename: `_resolved_artifact_path` preserves them for the loader and artifact identity. Do not upload either H5 under an extensionless hash. -The incumbent is 826,917,837 bytes; the ledger is 164,603,204 bytes. The -candidate's size was not supplied; its digest is the byte identity. +The incumbent is 826,917,837 bytes, the candidate 2,509,287,855 bytes and +the ledger 164,603,204 bytes. **Resources and ceiling.** For the first full attempt, class `head-to-head` requests 16 physical cores with CPU limit 16 and 192 GiB with memory limit @@ -1718,7 +1721,7 @@ that `put` and let check mode verify its digest; do not overwrite it. ```bash INCUMBENT_H5=/path/to/populace-us-2024-spm-20260915/populace_us_2024.h5 -CANDIDATE_H5=/path/to/populace-us-2024-0fb05b6-4b57d15a287c-20260930T150401Z/populace_us_2024.h5 +CANDIDATE_H5=/path/to/populace-us-2024-b5db384-8b0c1950b65f-20261024T083103Z/populace_us_2024.h5 LEDGER_FACTS=/path/to/consumer_facts_us_c5e5bf8.jsonl python3 tools/modal_us_stage_plan.py upload-commands \ docs/us-modal-stage-route-a-h2h-plan.json \ @@ -1727,7 +1730,7 @@ python3 tools/modal_us_stage_plan.py upload-commands \ modal volume put microcosm-us-stage-inputs "$INCUMBENT_H5" \ cas/sha256/6496cc4393d4d3c6574f76eca231de5898c803b9067645591fd5c4d3e65aee84/populace_us_2024.h5 modal volume put microcosm-us-stage-inputs "$CANDIDATE_H5" \ - cas/sha256/417d23aed4d044de2e657a7b5d856136975d25739dbdb4ddd72866f841de1559/populace_us_2024.h5 + cas/sha256/2d9c8586c45c32e5ca27357317f4de93b526cc51dd28b15b71ed43e47e142e79/populace_us_2024.h5 modal volume put microcosm-us-stage-inputs "$LEDGER_FACTS" \ cas/sha256/b85437390021777e746f507c5890305496baf5fc7f2c78ba08ddb090f4839801/consumer_facts_us_c5e5bf8.jsonl @@ -1744,8 +1747,8 @@ client, and Modal then cancels the paid input (this happened to Route A's base on 2026-09-29). From the checkout that holds this plan: ```bash -mkdir -p modal-runs/route-a-h2h-d844-20261010 -cat > modal-runs/route-a-h2h-d844-20261010/launch.sh < modal-runs/route-a-h2h-d844-d1386-r1/launch.sh < Date: Thu, 12 Nov 2026 10:06:20 -0500 Subject: [PATCH 05/28] Size the d844 head-to-head from the memory probe: 224 GiB, preemptible, recycle workers The 11 November local probe (6 slices of chunk 5 on the d1386 frame) peaked at 10.98 GB sampled RSS. Its traced heap stepped up once at slice 3 and then grew 22-45 MB per slice, so the plan recycles each worker after 6 slices. The class grows to 224 GiB (16 workers at about 12 GiB plus 32 GiB for the parent). October's slice times put the run at about 7.7 hours on 16 workers, about $59 non-preemptible. The plan therefore runs preemptible, with a 52,200-second budget across attempts. One attempt held to its 53,400-second timeout costs $37.75 at list price, under the $40 cap. Co-Authored-By: Claude Opus 5.5 --- ...-release-head-to-head-modal-stage.added.md | 2 +- docs/us-modal-stage-route-a-h2h-plan.json | 7 +- docs/us-modal-stage-runbook.md | 96 +++++++++++-------- .../us/test_us_modal_stage_plan_tool.py | 4 +- ...est_us_modal_stage_release_head_to_head.py | 58 +++++++---- tools/modal_us_stage_plan.py | 32 ++++--- 6 files changed, 119 insertions(+), 80 deletions(-) diff --git a/changelog.d/us-release-head-to-head-modal-stage.added.md b/changelog.d/us-release-head-to-head-modal-stage.added.md index 4f6e7fb278..25d028db4c 100644 --- a/changelog.d/us-release-head-to-head-modal-stage.added.md +++ b/changelog.d/us-release-head-to-head-modal-stage.added.md @@ -1 +1 @@ -The US head-to-head scorer is a Modal stage: `us-release-head-to-head` (one `score` stage; digest-pinned incumbent, candidate and ledger-feed inputs; `workers`, `maximum_microsim_batch_size` and `worker_max_slices` as the only plan options), with a `head-to-head` resource class (16 CPUs and 192 GiB, both limited at the request; 20,400-second timeout; non-preemptible; CPU/memory list-price ceiling $38.91 through the timeout). `docs/us-modal-stage-route-a-h2h-plan.json` is the first 16-worker d844 run (Route A against `populace-us-2024-spm-20260915`), with a 19,200-second tool budget and pinned to the merge of #1171. The runbook documents the sizing estimate, costs outside the compute ceiling, the lack of a final receipt after a whole-container OOM, and operator-supplied input paths. Check mode imports sibling-dependent tools with their script directory on the module search path and registers the probed module before executing it. +The US head-to-head scorer is a Modal stage: `us-release-head-to-head` (one `score` stage; digest-pinned incumbent, candidate and ledger-feed inputs; `workers`, `maximum_microsim_batch_size` and `worker_max_slices` as the only plan options), with a `head-to-head` resource class (16 CPUs and 224 GiB, both limited at the request; 53,400-second timeout; CPU/memory list-price ceiling $37.75 through the timeout on preemptible placement). `docs/us-modal-stage-route-a-h2h-plan.json` is the 16-worker d844 run (the d1386 Route A build against `populace-us-2024-spm-20260915`), preemptible, recycling each worker after 6 slices, with a 52,200-second tool budget across attempts, pinned to the merge of #1171. The runbook documents the sizing estimate from October's slice times and the 11 November local memory probe, costs outside the compute ceiling, the lack of a final receipt after a whole-container OOM, the Python patch level recycling needs, and operator-supplied input paths. Check mode imports sibling-dependent tools with their script directory on the module search path and registers the probed module before executing it. diff --git a/docs/us-modal-stage-route-a-h2h-plan.json b/docs/us-modal-stage-route-a-h2h-plan.json index 1289bd387c..783f193181 100644 --- a/docs/us-modal-stage-route-a-h2h-plan.json +++ b/docs/us-modal-stage-route-a-h2h-plan.json @@ -23,7 +23,8 @@ }, "options": { "workers": 16, - "maximum_microsim_batch_size": 2000 + "maximum_microsim_batch_size": 2000, + "worker_max_slices": 6 }, "env": { "PYTHONUNBUFFERED": "1", @@ -33,6 +34,6 @@ "NUMEXPR_NUM_THREADS": "1", "BLIS_NUM_THREADS": "1" }, - "max_wall_seconds": 19200, - "nonpreemptible": true + "max_wall_seconds": 52200, + "nonpreemptible": false } diff --git a/docs/us-modal-stage-runbook.md b/docs/us-modal-stage-runbook.md index 4d0cbd9718..775f4c3dfe 100644 --- a/docs/us-modal-stage-runbook.md +++ b/docs/us-modal-stage-runbook.md @@ -419,7 +419,7 @@ local wall times in this table understate Modal's wall and cost. | check | n/a | check | 2 cores, 8 GiB, 30 min timeout | cents | | PUF-support base (`all`) | 72.5 GB, 2,788 s wall, 6,238 CPU-s | base | 4 cores (limit 4), 112 GiB, 4 h 35 min timeout | about $0.84 ($2.52 non-preemptible) | | ACS multispine staging (`all`) | 42.4 GB, 7,218 s wall, 103,105 CPU-s | acs-staging | 16 cores (limit 16), 80 GiB, 17 h timeout | about $2.79 ($8.38 non-preemptible) | -| Route A head-to-head (`score`) | unmeasured aggregate peak; about 80 core-hours estimated locally | head-to-head | 16 cores (limit 16), 192 GiB (limit 192), 5 h 40 min timeout | $38.91 non-preemptible compute through the timeout | +| Route A head-to-head (`score`) | 10.98 GB peak sampled RSS in a 6-slice local probe of one worker; about 7.7 h estimated on 16 workers | head-to-head | 16 cores (limit 16), 224 GiB (limit 224), 14 h 50 min timeout | $37.75 preemptible compute through the timeout | The prices are Modal's list prices for standard compute, read from [modal.com/pricing](https://modal.com/pricing) on 22 September 2026 and @@ -1637,17 +1637,23 @@ the engine the d1386 manifest names. The runner registration comes from this che pin is immutable: to pick up a later scorer change, update `source.commit`, then repeat the local validation and the Modal check. -The stage runs the local comparison's argv with staged paths and -`--workers 16` added: +The stage runs the local comparison's argv with staged paths, +`--workers 16` and `--worker-max-slices 6` added: ```text ---incumbent X --candidate Y --ledger-facts Z --out-prefix P --maximum-microsim-batch-size 2000 --workers 16 +--incumbent X --candidate Y --ledger-facts Z --out-prefix P --maximum-microsim-batch-size 2000 --worker-max-slices 6 --workers 16 ``` Only `workers`, `maximum_microsim_batch_size` and `worker_max_slices` are -plan options. `worker_max_slices` is unset in the d844 plan: the image's -Python 3.14 patch level decides whether the scorer accepts recycling (it -refuses below 3.14.7), and the per-slice module release is the memory fix. Every +plan options. The d844 plan sets `worker_max_slices` to 6, so the stage adds +`--worker-max-slices 6` and each worker is replaced after six slices. The +local probe of 11 November 2026 ran six slices of chunk 5 on the d1386 +frame: its traced heap stepped up once at slice 3 and then grew 22 to 45 MB +per slice, so six slices is the range it measured. The scorer refuses +recycling on Python below 3.14.7, and the image pins only `3.14`; it +refuses before it loads either frame, so a too-old image fails in minutes. +Check mode's receipt records the image's Python in its runner identity: +confirm 3.14.7 or later there before the paid run. Every path flag, `--out-prefix`, the candidate-manifest pin, both spellings of each boolean, and the alternative batch-size spelling are runner-owned. The builder omits `--age-targets` and `--allow-unaged-dollar-targets`, so @@ -1668,41 +1674,51 @@ and artifact identity. Do not upload either H5 under an extensionless hash. The incumbent is 826,917,837 bytes, the candidate 2,509,287,855 bytes and the ledger 164,603,204 bytes. -**Resources and ceiling.** For the first full attempt, class `head-to-head` -requests 16 physical cores with CPU limit 16 and 192 GiB with memory limit -192 GiB. The d844 plan uses non-preemptible placement; both class runners -have `retries=0`. At sixteen workers, 1,030 slices × 4.7 minutes / 16 is -18,153.75 seconds (about 5 hours 3 minutes). The tool budget is 19,200 -seconds (5 hours 20 minutes), leaving about 1,046 seconds for initialization -and compute margin. The 20,400-second timeout (5 hours 40 minutes) adds -the normal 900-second runner reserve and 300 seconds for staging. Slow -staging reduces the tool's available time; the runner preserves the reserve -for logs, hashes, mirroring and receipt. The budget estimate including the -reserve is $38.34. +**Resources and ceiling.** Class `head-to-head` requests 16 physical +cores with CPU limit 16 and 224 GiB with memory limit 224 GiB: about 12 GiB +per worker (the 10 October measurement: 5.45 GiB frame RSS and 2.17 GiB +pickled) for 16 workers, plus 32 GiB for the parent, which retains the +original and repaired frames, the runner and spawn serialization. The local +probe's peak sampled RSS of 10.98 GB for one process sits inside that +allowance. It was sampled on a loaded Mac, where compressed pages leave RSS +low, so it is an indication, not a measured aggregate peak. The receipt's +`peak_rss_bytes` is a child-process peak from `RUSAGE_CHILDREN`, not the +sum of sixteen workers; use Modal's container memory measurements to assess +the sizing after the run. Fewer workers reduce aggregate memory exposure +but cannot prevent one worker exceeding the scorer's 20 GiB RSS guard. + +October's sequential run averaged 5.2, 4.7, 6.2, 5.4 and 10.4 minutes per +2,000-household slice in registry chunks 1 to 5, each of 206 slices (29 +incumbent and 177 candidate). On 16 workers that is about 24,640 seconds of +scoring. Recycling after six slices respawns about 172 workers; at an +allowance of 300 seconds each for the engine import and frame load, that +adds about 3,220 seconds, for an estimate of about 27,860 seconds (7.7 +hours). The probe's own slice times ran under tracemalloc on a loaded host +and do not measure speed. + +The d844 plan runs on preemptible placement; both class runners have +`retries=0`. Modal restarts a preempted attempt from zero, and the scorer +has no resume, so the plan's 52,200-second budget (14 hours 30 minutes) +spans attempts (see "Preemption and restarts"): a restart after up to about +six and a half hours of a run still completes. The 53,400-second timeout +(14 hours 50 minutes) adds the normal 900-second runner reserve and 300 +seconds for staging. The budget estimate including the reserve is $37.54. Using the existing runbook formula and [Modal's list prices](https://modal.com/pricing) -(checked 10 October 2026), CPU and memory compute through the timeout costs -`(16 × $0.0000131 + 192 × $0.00000222) × 20,400 × 3 = $38.913408`, -or **$38.91, below $40**. The CPU and memory limits equal their requests, -so memory over-use OOM-kills the container instead of increasing the billed -memory allocation. The function timeout covers staging, tool initialization, -scoring and runner cleanup. Startup/image work outside that interval, the -check, storage, timeout-enforcement overshoot and another attempt remain -outside this compute ceiling; it is not a cap on total Modal account spend. - -The independent review's 9–10 GiB per worker is unmeasured. Each worker -holds a full copy of the repaired frame, and the parent retains the -original and repaired frames. The 192 GiB limit allows an estimated 160 GiB -for workers plus 32 GiB for the parent, runner and spawn serialization. -This is an estimate, not a measured aggregate -peak. The receipt's `peak_rss_bytes` is a child-process peak from -`RUSAGE_CHILDREN`, not the sum of sixteen workers; profile representative -2,000-household slices of the full candidate and use Modal's container -memory measurements to assess this sizing after the run. Fewer workers -reduce aggregate memory exposure but cannot prevent one worker exceeding -the scorer's 20 GiB RSS guard. The stage writes -scorecards and logs, mirrors `h2h.json` and `h2h.md` first, and has no -checkpoint/resume state or additional disk/write-probe requirement. +(checked 10 October 2026), CPU and memory compute through one attempt's +timeout costs `(16 × $0.0000131 + 224 × $0.00000222) × 53,400 = $37.747392`, +or **$37.75, below $40**. The same run non-preemptible costs three times +as much, about $59 for the 7.7-hour estimate alone. The CPU and memory +limits equal their requests, so memory over-use OOM-kills the container +instead of increasing the billed memory allocation. The function timeout +covers staging, tool initialization, scoring and runner cleanup. Startup +and image work outside that interval, the uncharged part of each preempted +attempt (up to about two minutes after its last ledger record, plus the +restart's lock wait of up to 270 seconds), the check, storage and +timeout-enforcement overshoot remain outside this compute ceiling; it is +not a cap on total Modal account spend. The stage writes scorecards and +logs, mirrors `h2h.json` and `h2h.md` first, and has no checkpoint/resume +state or additional disk/write-probe requirement. A worker death or RSS-guard failure leaves a failed scorer exit. If the runner survives, it writes a **FAILED receipt and logs**; the scorer writes diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_plan_tool.py b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_plan_tool.py index 7b5d521d0d..e43ce64cf9 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_plan_tool.py +++ b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_plan_tool.py @@ -1856,10 +1856,10 @@ def test_every_valid_plan_has_a_runner_with_its_class_and_placement(app) -> None ) assert options.get("nonpreemptible", False) is nonpreemptible assert options["retries"] == 0 - # The first scorer attempt caps memory to keep its compute cost under + # The scorer caps memory at its request to keep its compute cost under # $40. Existing ACS/base/smoke requests retain their reviewed behavior. if name == "head-to-head": - assert options["memory"] == (192 * 1024, 192 * 1024) + assert options["memory"] == (224 * 1024, 224 * 1024) else: assert isinstance(options["memory"], int) assert resources.memory_limit_mib is None diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py index 907b2e3977..a8b68cc36f 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py +++ b/packages/microcosm-build/tests/engine_free/us/test_us_modal_stage_release_head_to_head.py @@ -122,9 +122,13 @@ def test_d844_plan_validates_with_digest_pinned_loader_filenames() -> None: ) assert set(tool.stages) == {"score"} assert set(tool.inputs) == set(tool.stages["score"].required_inputs) == set(INPUTS) - assert plan.options == {"maximum_microsim_batch_size": 2000, "workers": 16} - assert plan.nonpreemptible is True - assert plan.max_wall_seconds == 19_200 + assert plan.options == { + "maximum_microsim_batch_size": 2000, + "workers": 16, + "worker_max_slices": 6, + } + assert plan.nonpreemptible is False + assert plan.max_wall_seconds == 52_200 for role, (filename, digest) in INPUTS.items(): ref = plan.inputs[role] assert (ref.kind, ref.filename, ref.sha256) == ("volume", filename, digest) @@ -138,7 +142,7 @@ def test_d844_plan_validates_with_digest_pinned_loader_filenames() -> None: assert plan.stage_spec.mirror_first == ("h2h.json", "h2h.md") -def test_modal_argv_equals_the_local_d844_command_apart_from_paths_and_workers( +def test_modal_argv_equals_the_local_d844_command_apart_from_paths_and_workers_options( scorer_parser, ) -> None: plan = _plan() @@ -155,7 +159,7 @@ def test_modal_argv_equals_the_local_d844_command_apart_from_paths_and_workers( expected[index + 1] = plan_lib.input_local_path("/work", ref) elif item == "--out-prefix": expected[index + 1] = "/work/state/h2h" - assert argv[3:] == [*expected, "--workers", "16"] + assert argv[3:] == [*expected, "--worker-max-slices", "6", "--workers", "16"] local_args = vars(scorer_parser.parse(LOCAL_ARGV)) modal_args = vars(scorer_parser.parse(argv[3:])) for flag in (*PATH_FLAGS, "--out-prefix"): @@ -164,6 +168,8 @@ def test_modal_argv_equals_the_local_d844_command_apart_from_paths_and_workers( assert isinstance(modal_args.pop(name), Path) assert local_args.pop("workers") == 1 assert modal_args.pop("workers") == 16 + assert local_args.pop("worker_max_slices") is None + assert modal_args.pop("worker_max_slices") == 6 assert local_args == modal_args assert modal_args["age_targets"] is False assert modal_args["allow_unaged_dollar_targets"] is True @@ -238,13 +244,24 @@ def test_head_to_head_timeout_covers_the_slice_estimate_and_cost_cap() -> None: plan = _plan() resources = plan_lib.HEAD_TO_HEAD assert plan.resources is resources - assert (resources.cpu, resources.cpu_limit, resources.memory_gib) == (16, 16, 192) - assert resources.memory_limit_mib == resources.memory_mib == 192 * 1024 - assert resources.timeout_s == 20_400 - slice_wall_seconds = 1030 * 4.7 * 60 / plan.options["workers"] - # At least ten minutes remain for initialization before the tool budget; - # the container additionally reserves runner time and timeout margin. - assert plan.max_wall_seconds >= slice_wall_seconds + 10 * 60 + assert (resources.cpu, resources.cpu_limit, resources.memory_gib) == (16, 16, 224) + assert resources.memory_limit_mib == resources.memory_mib == 224 * 1024 + assert resources.timeout_s == 53_400 + # October's sequential run: mean minutes per slice in registry chunks 1-5, + # each chunk 29 incumbent + 177 candidate slices. + chunk_minutes = (5.2, 4.7, 6.2, 5.4, 10.4) + slices = 5 * (29 + 177) + assert slices == 1030 + workers = plan.options["workers"] + scoring_seconds = (slices // 5) * sum(chunk_minutes) * 60 / workers + respawns = slices / plan.options["worker_max_slices"] + respawn_seconds = respawns * 300 / workers + estimate = scoring_seconds + respawn_seconds + assert estimate == pytest.approx(27_861.5, abs=1) + # Preemptible: the budget spans attempts, so it holds a restart after + # more than six hours of a completed attempt's run. + assert plan.nonpreemptible is False + assert plan.max_wall_seconds >= 1.8 * estimate assert resources.timeout_s > ( plan.max_wall_seconds + plan.stage_spec.runner_overhead_seconds ) @@ -252,12 +269,11 @@ def test_head_to_head_timeout_covers_the_slice_estimate_and_cost_cap() -> None: resources.cpu * plan_lib.CPU_USD_PER_CORE_SECOND + resources.memory_gib * plan_lib.MEMORY_USD_PER_GIB_SECOND ) - timeout_cost = ( - per_second * resources.timeout_s * plan_lib.NONPREEMPTIBLE_PRICE_MULTIPLIER - ) + assert plan.price_multiplier == 1.0 + timeout_cost = per_second * resources.timeout_s * plan.price_multiplier assert timeout_cost < plan_lib.HEAD_TO_HEAD_COST_CAP_USD ceiling = round(timeout_cost, 2) - assert ceiling == pytest.approx(38.91, abs=0.005) + assert ceiling == pytest.approx(37.75, abs=0.005) assert ceiling <= plan_lib.HEAD_TO_HEAD_COST_CAP_USD == 40 assert ( resources.estimated_usd(resources.timeout_s, plan.price_multiplier) == ceiling @@ -265,7 +281,7 @@ def test_head_to_head_timeout_covers_the_slice_estimate_and_cost_cap() -> None: assert plan_lib.estimated_usd_at_timeout(plan) == ceiling summary = plan_lib.summarize(plan) assert summary["estimated_usd_at_timeout"] == ceiling - assert summary["estimated_usd_at_max_wall"] == pytest.approx(38.34, abs=0.005) + assert summary["estimated_usd_at_max_wall"] == pytest.approx(37.54, abs=0.005) assert summary["resources"]["memory_limit_gib"] == resources.memory_gib @@ -278,14 +294,14 @@ def test_head_to_head_registers_its_modal_functions_without_retries( options = app.RUNNERS[(resources.name, nonpreemptible)].modal_options assert (options["cpu"], options["memory"], options["timeout"]) == ( (16, 16), - (192 * 1024, 192 * 1024), - 20_400, + (224 * 1024, 224 * 1024), + 53_400, ) assert options.get("nonpreemptible", False) is nonpreemptible assert options["retries"] == 0 plan = _plan() runner = app.RUNNERS[(plan.resources.name, plan.nonpreemptible)] - assert runner is app.run_stage_head_to_head_nonpreemptible + assert runner is app.run_stage_head_to_head calls = [] monkeypatch.setattr( app, "_run_stage", lambda data: calls.append(data) or {"ok": True} @@ -300,7 +316,7 @@ def test_a_memory_limit_below_the_request_is_refused() -> None: plan_lib.Resources( "x", cpu=1, memory_mib=1024, timeout_s=60, memory_limit_mib=512 ) - assert plan_lib.HEAD_TO_HEAD.modal_memory == (192 * 1024, 192 * 1024) + assert plan_lib.HEAD_TO_HEAD.modal_memory == (224 * 1024, 224 * 1024) for resources in (plan_lib.CHECK, plan_lib.HEAVY, plan_lib.LIGHT, plan_lib.BASE): assert resources.modal_memory == resources.memory_mib assert resources.memory_limit_mib is None diff --git a/tools/modal_us_stage_plan.py b/tools/modal_us_stage_plan.py index 90f5da8b5b..b056dbb8f6 100644 --- a/tools/modal_us_stage_plan.py +++ b/tools/modal_us_stage_plan.py @@ -443,23 +443,29 @@ def estimated_usd(self, wall_seconds: float, multiplier: float = 1.0) -> float: BASE = Resources( "base", cpu=4.0, memory_mib=112 * 1024, timeout_s=16_500, cpu_limit=4.0 ) -# Route A's head-to-head: each spawned worker retains a full repaired frame. -# The independent review's 9-10 GiB/worker is unmeasured: 16 * 10 GiB plus -# 32 GiB for the parent and headroom, not a measured aggregate peak. At -# 1,030 slices * 4.7 minutes / 16 workers the tool takes about 18,154 s. -# 20,400 s leaves staging, the normal 900 s runner reserve and compute margin. -# CPU and memory are limited to their requests, bounding the non-preemptible -# execution-time compute estimate at $38.91 for the whole timeout. Exceeding -# the memory limit kills the container before it can write a final receipt. -# Other classes retain their reviewed request-only memory behavior: this -# first scorer attempt has an explicit $40 cap and unmeasured worker peaks. +# Route A's head-to-head: each spawned worker retains a full repaired frame, +# about 12 GiB per worker (5.45 GiB frame RSS and 2.17 GiB pickled, measured +# 2026-10-10). 16 workers * 12 GiB plus 32 GiB for the parent and headroom +# is 224 GiB. The local memory probe of 2026-11-11 (6 slices of chunk 5 on +# the d1386 frame, tracemalloc) peaked at 10.98 GB sampled RSS; its traced +# heap stepped up once at slice 3 and then grew 22-45 MB per slice, so plans +# recycle each worker after 6 slices (--worker-max-slices), the range the +# probe covered. October's sequential run averaged 5.2, 4.7, 6.2, 5.4 and +# 10.4 minutes per slice in registry chunks 1-5, each of 206 slices: about +# 24,600 s on 16 workers, plus about 3,200 s for 172 worker respawns at +# 300 s each. The plan runs preemptible with a 52,200 s budget across +# attempts (see "Preemption and restarts" in the runbook), so it can absorb +# one restart after more than six hours. CPU and memory are limited to their +# requests, so one attempt held to its timeout costs $37.75 at list price, +# under the $40 cap. Exceeding the memory limit kills the container before +# it can write a final receipt. HEAD_TO_HEAD = Resources( "head-to-head", cpu=16.0, - memory_mib=192 * 1024, - timeout_s=20_400, + memory_mib=224 * 1024, + timeout_s=53_400, cpu_limit=16.0, - memory_limit_mib=192 * 1024, + memory_limit_mib=224 * 1024, ) HEAD_TO_HEAD_COST_CAP_USD = 40.0 # full-staging-a3 (MEASURED): 103,104.6 CPU-s / 7,218.1 wall-s = 14.3 From dc7836e2bb9f8cfdee922ca3f2114971cf3d0f80 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Mon, 16 Nov 2026 12:26:28 -0500 Subject: [PATCH 06/28] Run d844 non-preemptible without recycling; add a go/no-go projection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The r1 review of d1776a051 found the preemptible plan could not finish (λ≈0.67/h against a 7-8 h run with no resume) and that Modal's debian_slim 3.14 image serves Python 3.14.2, which the scorer's recycling guard refuses. - Plan: non-preemptible, no worker_max_slices, 16 workers. - Class head-to-head: 16 CPU and 288 GiB, both limited; the timeout derives from HEAD_TO_HEAD_COST_CAP_USD at the non-preemptible list price (15,705 s at $40). At $40 the run cannot finish; the cap is Max's call. - Check mode reports the image venv's Python and runs a tool's option preflights, so a plan that sets worker_max_slices runs the scorer's _assert_worker_recycling_supported in the image. - tools/us_head_to_head_projection.py projects the end time and worker memory from the streamed scorer log and answers WAIT, GO or NO-GO; tests check its bounds on simulated pools. - Runbook: launch with --run --spawn under launchd, a watcher that stops the app on NO-GO, and the sizing evidence with its gaps. Co-Authored-By: Claude Opus 5.5 --- ...-release-head-to-head-modal-stage.added.md | 2 +- docs/us-modal-stage-route-a-h2h-plan.json | 7 +- docs/us-modal-stage-runbook.md | 256 ++++++---- ...est_us_modal_stage_release_head_to_head.py | 9 +- .../us/test_us_head_to_head_projection.py | 342 +++++++++++++ .../us/test_us_modal_stage_plan_tool.py | 7 +- ...est_us_modal_stage_release_head_to_head.py | 157 ++++-- tools/modal_us_stage.py | 41 +- tools/modal_us_stage_plan.py | 78 ++- tools/us_head_to_head_projection.py | 478 ++++++++++++++++++ 10 files changed, 1197 insertions(+), 180 deletions(-) create mode 100644 packages/microcosm-build/tests/engine_free/us/test_us_head_to_head_projection.py create mode 100644 tools/us_head_to_head_projection.py diff --git a/changelog.d/us-release-head-to-head-modal-stage.added.md b/changelog.d/us-release-head-to-head-modal-stage.added.md index 25d028db4c..aa50a3ec91 100644 --- a/changelog.d/us-release-head-to-head-modal-stage.added.md +++ b/changelog.d/us-release-head-to-head-modal-stage.added.md @@ -1 +1 @@ -The US head-to-head scorer is a Modal stage: `us-release-head-to-head` (one `score` stage; digest-pinned incumbent, candidate and ledger-feed inputs; `workers`, `maximum_microsim_batch_size` and `worker_max_slices` as the only plan options), with a `head-to-head` resource class (16 CPUs and 224 GiB, both limited at the request; 53,400-second timeout; CPU/memory list-price ceiling $37.75 through the timeout on preemptible placement). `docs/us-modal-stage-route-a-h2h-plan.json` is the 16-worker d844 run (the d1386 Route A build against `populace-us-2024-spm-20260915`), preemptible, recycling each worker after 6 slices, with a 52,200-second tool budget across attempts, pinned to the merge of #1171. The runbook documents the sizing estimate from October's slice times and the 11 November local memory probe, costs outside the compute ceiling, the lack of a final receipt after a whole-container OOM, the Python patch level recycling needs, and operator-supplied input paths. Check mode imports sibling-dependent tools with their script directory on the module search path and registers the probed module before executing it. +The US head-to-head scorer is a Modal stage: `us-release-head-to-head` (one `score` stage; digest-pinned incumbent, candidate and ledger-feed inputs; `workers`, `maximum_microsim_batch_size` and `worker_max_slices` as the only plan options), with a `head-to-head` resource class (16 CPUs and 288 GiB, both limited at the request, and a timeout derived from `HEAD_TO_HEAD_COST_CAP_USD`: at d844's $40 cap and the non-preemptible list price, 15,705 seconds). `docs/us-modal-stage-route-a-h2h-plan.json` is the 16-worker d844 run (the d1386 Route A build against `populace-us-2024-spm-20260915`), non-preemptible, without worker recycling, with a 14,505-second tool budget, pinned to `main` at 2cfe3043d, which carries #1171. At $40 it cannot finish; the cap is Max's to raise. Check mode reports the image venv's Python and runs a tool's option preflights (`ToolSpec.option_preflights`), so a plan that sets `worker_max_slices` runs the scorer's recycling guard in the image and fails the check on Python below 3.14.7. `tools/us_head_to_head_projection.py` reads the stage's streamed log and answers `WAIT`, `GO` or `NO-GO` against the plan's time budget, the class memory limit and the scorer's 20 GiB per-process limit; the runbook's watcher stops the app on `NO-GO`. The runbook documents the sizing evidence and its gaps, costs outside the compute ceiling, the lack of a final receipt after a whole-container OOM, and operator-supplied input paths. Check mode imports sibling-dependent tools with their script directory on the module search path and registers the probed module before executing it. diff --git a/docs/us-modal-stage-route-a-h2h-plan.json b/docs/us-modal-stage-route-a-h2h-plan.json index 783f193181..f29fe87b76 100644 --- a/docs/us-modal-stage-route-a-h2h-plan.json +++ b/docs/us-modal-stage-route-a-h2h-plan.json @@ -23,8 +23,7 @@ }, "options": { "workers": 16, - "maximum_microsim_batch_size": 2000, - "worker_max_slices": 6 + "maximum_microsim_batch_size": 2000 }, "env": { "PYTHONUNBUFFERED": "1", @@ -34,6 +33,6 @@ "NUMEXPR_NUM_THREADS": "1", "BLIS_NUM_THREADS": "1" }, - "max_wall_seconds": 52200, - "nonpreemptible": false + "max_wall_seconds": 14505, + "nonpreemptible": true } diff --git a/docs/us-modal-stage-runbook.md b/docs/us-modal-stage-runbook.md index 3a0a5094cf..829ea47eba 100644 --- a/docs/us-modal-stage-runbook.md +++ b/docs/us-modal-stage-runbook.md @@ -1650,38 +1650,38 @@ and the default on an older feed, so neither was fit to this register. The plan pins scorer commit `2cfe3043d747b929e349c8de2486acf80b5f17f2` on `main`, which carries #1171 (`--workers`, the per-slice release of Core's variable modules, and the recycling guard) and locks policyengine-us 2.2.1, -the engine the d1386 manifest names. The runner registration comes from this checkout. A plan's -pin is immutable: to pick up a later scorer change, update `source.commit`, -then repeat the local validation and the Modal check. +the engine the d1386 manifest names. The runner registration comes from this +checkout. A plan's pin is immutable and freezes the yardstick: to pick up a +later scorer change, update `source.commit`, then repeat the local +validation and the Modal check. -The stage runs the local comparison's argv with staged paths, -`--workers 16` and `--worker-max-slices 6` added: +The stage runs the local comparison's argv with staged paths and +`--workers 16` added: ```text ---incumbent X --candidate Y --ledger-facts Z --out-prefix P --maximum-microsim-batch-size 2000 --worker-max-slices 6 --workers 16 +--incumbent X --candidate Y --ledger-facts Z --out-prefix P --maximum-microsim-batch-size 2000 --workers 16 ``` Only `workers`, `maximum_microsim_batch_size` and `worker_max_slices` are -plan options. The d844 plan sets `worker_max_slices` to 6, so the stage adds -`--worker-max-slices 6` and each worker is replaced after six slices. The -local probe of 11 November 2026 ran six slices of chunk 5 on the d1386 -frame: its traced heap stepped up once at slice 3 and then grew 22 to 45 MB -per slice, so six slices is the range it measured. The scorer refuses -recycling on Python below 3.14.7, and the image pins only `3.14`; it -refuses before it loads either frame, so a too-old image fails in minutes. -Check mode's receipt records the image's Python in its runner identity: -confirm 3.14.7 or later there before the paid run. Every -path flag, `--out-prefix`, the candidate-manifest pin, both spellings of -each boolean, and the alternative batch-size spelling are runner-owned. -The builder omits `--age-targets` and `--allow-unaged-dollar-targets`, so -the scorer uses the same defaults as the sequential run: `False` and -`True`, respectively. The crosswalk and candidate pool/attestation flags -are also omitted; the scorer chooses its normal bundled crosswalk. -Changing this scoring yardstick requires a reviewed registration change. -The plan sets the five native numerical thread counts to `1`, so sixteen -spawned workers do not each start a sixteen-thread BLAS/OpenMP pool. -That is an execution choice; the engine-free argv test does not prove -numerical parity across platforms or thread counts. +plan options. The d844 plan does not set `worker_max_slices`, so each +worker lives for its artifact's whole pool. The scorer refuses recycling +below Python 3.14.7, and the image's `3.14` resolves to 3.14.2 on Modal's +2025.06 image builder (`modal/builder/base-images.json` in modal 1.3.0). +Check mode reports the image venv's Python under `environment.python` and +under the parser probe's `python`, and when a plan sets `worker_max_slices` +it runs the scorer's own `_assert_worker_recycling_supported` in the image +(`ToolSpec.option_preflights`), so a recycling plan fails the check instead +of the paid run. Every path flag, `--out-prefix`, the candidate-manifest +pin, both spellings of each boolean, and the alternative batch-size +spelling are runner-owned. The builder omits `--age-targets` and +`--allow-unaged-dollar-targets`, so the scorer uses the same defaults as the +sequential run: `False` and `True`, respectively. The crosswalk and candidate +pool/attestation flags are also omitted; the scorer chooses its normal +bundled crosswalk. Changing this scoring yardstick requires a reviewed +registration change. The plan sets the five native numerical thread counts +to `1`, so sixteen spawned workers do not each start a sixteen-thread +BLAS/OpenMP pool. That is an execution choice; the engine-free argv test +does not prove numerical parity across platforms or thread counts. Both H5 inputs retain the filename `populace_us_2024.h5` in separate CAS directories and stage to `/work/inputs/incumbent_h5/populace_us_2024.h5` @@ -1691,59 +1691,65 @@ and artifact identity. Do not upload either H5 under an extensionless hash. The incumbent is 826,917,837 bytes, the candidate 2,509,287,855 bytes and the ledger 164,603,204 bytes. -**Resources and ceiling.** Class `head-to-head` requests 16 physical -cores with CPU limit 16 and 224 GiB with memory limit 224 GiB: about 12 GiB -per worker (the 10 October measurement: 5.45 GiB frame RSS and 2.17 GiB -pickled) for 16 workers, plus 32 GiB for the parent, which retains the -original and repaired frames, the runner and spawn serialization. The local -probe's peak sampled RSS of 10.98 GB for one process sits inside that -allowance. It was sampled on a loaded Mac, where compressed pages leave RSS -low, so it is an indication, not a measured aggregate peak. The receipt's -`peak_rss_bytes` is a child-process peak from `RUSAGE_CHILDREN`, not the -sum of sixteen workers; use Modal's container memory measurements to assess -the sizing after the run. Fewer workers reduce aggregate memory exposure -but cannot prevent one worker exceeding the scorer's 20 GiB RSS guard. - -October's sequential run averaged 5.2, 4.7, 6.2, 5.4 and 10.4 minutes per -2,000-household slice in registry chunks 1 to 5, each of 206 slices (29 -incumbent and 177 candidate). On 16 workers that is about 24,640 seconds of -scoring. Recycling after six slices respawns about 172 workers; at an -allowance of 300 seconds each for the engine import and frame load, that -adds about 3,220 seconds, for an estimate of about 27,860 seconds (7.7 -hours). The probe's own slice times ran under tracemalloc on a loaded host -and do not measure speed. - -The d844 plan runs on preemptible placement; both class runners have -`retries=0`. Modal restarts a preempted attempt from zero, and the scorer -has no resume, so the plan's 52,200-second budget (14 hours 30 minutes) -spans attempts (see "Preemption and restarts"): a restart after up to about -six and a half hours of a run still completes. The 53,400-second timeout -(14 hours 50 minutes) adds the normal 900-second runner reserve and 300 -seconds for staging. The budget estimate including the reserve is $37.54. - -Using the existing runbook formula and [Modal's list prices](https://modal.com/pricing) -(checked 10 October 2026), CPU and memory compute through one attempt's -timeout costs `(16 × $0.0000131 + 224 × $0.00000222) × 53,400 = $37.747392`, -or **$37.75, below $40**. The same run non-preemptible costs three times -as much, about $59 for the 7.7-hour estimate alone. The CPU and memory -limits equal their requests, so memory over-use OOM-kills the container -instead of increasing the billed memory allocation. The function timeout -covers staging, tool initialization, scoring and runner cleanup. Startup -and image work outside that interval, the uncharged part of each preempted -attempt (up to about two minutes after its last ledger record, plus the -restart's lock wait of up to 270 seconds), the check, storage and -timeout-enforcement overshoot remain outside this compute ceiling; it is -not a cap on total Modal account spend. The stage writes scorecards and -logs, mirrors `h2h.json` and `h2h.md` first, and has no checkpoint/resume -state or additional disk/write-probe requirement. - -A worker death or RSS-guard failure leaves a failed scorer exit. If the -runner survives, it writes a **FAILED receipt and logs**; the scorer writes -scorecards only after the comparison finishes. A whole-container OOM can -leave a partial bill with **no final receipt or mirrored output**, because -receipt creation and mirroring happen after the tool exits. Inspect the -container logs and measurements when no receipt appears; do not assume the -absence of a receipt means the attempt was free. +**What the run does.** The scorer compiles the register once (33,147 +specs in five chunks of up to 8,192; chunk 5 holds 379, among them the +eleven JCT reform measures), then scores the incumbent in one pool of +spawned workers and the candidate in a fresh pool. Each artifact has the +same number of 2,000-household slices in every chunk: 29 for the +incumbent and 177 for the candidate, so 145 and 885 slices. Each worker +receives the repaired frame once, when it starts. + +**Memory.** Class `head-to-head` requests 16 physical cores and 288 GiB, +each limited at the request. Without recycling a candidate worker scores +about 55 slices, so the class allows 16 GiB for each of 16 workers plus +32 GiB for the parent, which retains the original and repaired frames. +Nothing has measured a worker on the d1386 frame or on Modal. "About +12 GiB per worker" is an inference from the September candidate's frame +(5.45 GiB in-process and 2.17 GiB pickled, measured 10 October). October's +sequential run grew 37 to 59 MB per slice in chunks 1 to 4 and died of a +`MemoryError` at 20.3 GiB in chunk 5, under the older scorer. The local +probe of 11 November, on the d1386 frame and the current scorer, saw the +traced heap grow 22 to 45 MB per slice after a one-time step at slice 3, +over six slices of chunk 5 only. The 23 September materialize acceptance +attempt peaked at 66.3 to 74.5 GB on Modal against 51.0 GB on the Mac +(1.30 to 1.46 times). The go/no-go step below measures each worker's peak +from the run's own log and stops a run that would not fit. Exceeding the hard limit OOM-kills the container, which then +writes **no final receipt and mirrors no output**: inspect the container +logs and Modal's measurements, and do not assume the absence of a receipt +means the attempt was free. The receipt's `peak_rss_bytes` is a +child-process peak from `RUSAGE_CHILDREN`, not the sum of sixteen workers. + +**Time.** October's sequential run averaged 5.2, 4.7, 6.2, 5.4 and 10.4 +minutes per slice in registry chunks 1 to 5. It scored only incumbent +slices (29 in each of chunks 1 to 4 and 12 in chunk 5, when chunk 5 held 73 +specs) and died at chunk 5. Applying those means to all 1,030 slices gives +about 6,580 slice-minutes, or about 24,700 seconds of scoring on 16 +workers, before loading both artifacts, two pool starts and the scorecards. +That estimate is unvalidated. Chunk 5's mean rests on 12 slices at 73 +specs, and chunk 5 now holds 379. The only candidate timings are the +11 November probe's six chunk-5 slices under `tracemalloc`, at 734 to +1,849 seconds each (mean 1,188, 1.9 times October's chunk-5 mean), on a +loaded Mac; tracing slows Python, so they do not bound the untraced time. + +**Placement and the cap.** The plan runs non-preemptible. The scorer has +no resume, and at the preemption rate measured in "Preemption and restarts" +(about 0.67 per hour) a preemptible attempt of seven to eight hours finishes +under 1% of the time. `HEAD_TO_HEAD_COST_CAP_USD` sets the class timeout: +the cap divided by the class's non-preemptible list price, +`(16 × $0.0000131 + 288 × $0.00000222) × 3 = $0.00254688` per second +($9.17 an hour). At Max's $40 cap (10 October) that is 15,705 seconds +(4.4 hours), and the plan's `max_wall_seconds` of 14,505 leaves the +runner's 900-second reserve and 300 seconds for staging. **At $40 the run +cannot finish**: the estimate above needs about seven hours. A cap only +Max can set must come first. Raising the cap is a change to +`HEAD_TO_HEAD_COST_CAP_USD` alone; then set the plan's `max_wall_seconds` +to the new timeout less 1,200. The CPU and memory limits equal their +requests, so the timeout bounds one attempt's compute bill. Startup and +image work outside the timeout, the check, storage and +timeout-enforcement overshoot remain outside this ceiling; it is not a cap +on total Modal account spend. A changed plan is a new plan sha256 with a +fresh runner budget, so record every attempt's spend for this comparison +in the run folder and keep the total inside Max's cap yourself. Stage the inputs in the `policyengine` workspace. Set these variables to the existing local files; the ledger path is the one used by Route A's @@ -1767,7 +1773,7 @@ modal volume put microcosm-us-stage-inputs "$CANDIDATE_H5" \ modal volume put microcosm-us-stage-inputs "$LEDGER_FACTS" \ cas/sha256/b85437390021777e746f507c5890305496baf5fc7f2c78ba08ddb090f4839801/consumer_facts_us_c5e5bf8.jsonl -# Validate locally, then check on Modal after the reviewed scorer repin. +# Validate locally, then check on Modal. python3 tools/modal_us_stage_plan.py validate docs/us-modal-stage-route-a-h2h-plan.json MICROCOSM_MODAL_PLAN=docs/us-modal-stage-route-a-h2h-plan.json \ modal run tools/modal_us_stage.py @@ -1777,30 +1783,87 @@ Require `CHECK OK`, including the pinned parser and all three volume digests, before the paid run. Launch the paid run under launchd, never from a session shell: a restart of the launching session kills a session-owned client, and Modal then cancels the paid input (this happened to Route A's -base on 2026-09-29). From the checkout that holds this plan: +base on 2026-09-29). Launch it with `--run --spawn`, which returns once the +stage is spawned (see "Commands"), and record the launch time, the app id +(`ap-…`) and the printed `function_call_id`. From the checkout that holds +this plan: ```bash -mkdir -p modal-runs/route-a-h2h-d844-d1386-r1 -cat > modal-runs/route-a-h2h-d844-d1386-r1/launch.sh < "modal-runs/$R/launch.sh" < modal-runs/$R/started-at +exec modal run --detach tools/modal_us_stage.py --run --spawn SH -chmod +x modal-runs/route-a-h2h-d844-d1386-r1/launch.sh +chmod +x "modal-runs/$R/launch.sh" ``` Submit that script as a transient launchd job. On the build Mac the helper is `lsubmit.sh