Skip to content

Record each US build's resource plan in its manifests and telemetry - #1864

Draft
anth-volk wants to merge 11 commits into
mainfrom
claude/1-8-4-resource-plan-record
Draft

anth-volk wants to merge 11 commits into
mainfrom
claude/1-8-4-resource-plan-record

Conversation

@anth-volk

@anth-volk anth-volk commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1863

Task 1.8 · 4 of project 15 ("US build memory, CPU and run time"): each US build run records the resource plan it ran under (memory budget, core limit, workers, threads, batch size) in its manifests and its telemetry. Stage 2's planner (task 2.6) can then size workers from the costs builds report and the plan each cost was measured under.

Built on #1853 (task 1.8 · 1, --memory-budget and --max-cores), which has merged, as has task 1.8 · 2; main is merged in, with their changes kept beside this PR's (1.8 · 2's stage_resource_use and record_stage_resources next to resource_plan), so this PR's diff against main is its own change.

What the change does

One plan per run (microcosm.build.resource_plan). Each run of a build command builds one plan when it starts, after it reads its budget (host_resources.report_resource_budget):

  • machine: total memory and usable cores, and where each reading came from (modal_request, cgroup_limit, physical_memory; modal_cpu_limit, cgroup_quota, process_cpu_count, …);
  • memory_budget: the setting, its bytes, and its source (--memory-budget, MICROCOSM_MEMORY_BUDGET or default);
  • max_cores: the setting and its source; cores: the usable cores, at most --max-cores;
  • threads: MICROCOSM_THREADS and each variable the build commands fill (OMP_NUM_THREADS, OPENBLAS_NUM_THREADS, MKL_NUM_THREADS, BLIS_NUM_THREADS, VECLIB_MAXIMUM_THREADS, NUMEXPR_NUM_THREADS, LOKY_MAX_CPU_COUNT, NUMEXPR_MAX_THREADS), as the libraries read them, null when unset. A test holds this list to tools/us_build_thread_environment.py's;
  • qrf: POPULACE_FIT_N_JOBS and POPULACE_FIT_PREDICT_WORKERS, configured and resolved, as the primary-QRF worker would start with them (worker_identity.audit_thread_controls, made public). A setting the QRF would refuse is recorded as {"error": ...}: the plan never stops a build;
  • batch_size: the command's batch or chunk option and value (--maximum-microsim-batch-size, --hh-chunk, --chunksize, the probe's --batch-size; null for the base, which has none);
  • post_export_workers: for certification and the probe, the post-export workers chosen.

A full plan is under 2,048 bytes of compact JSON (a test checks it), well within the emitter's 8,192-byte limit on a first event's details.

Telemetry. The run's first event carries the plan as details.identity.resource_plan (runtime_identity, LocalTelemetryEmitter.start and program_telemetry take resource_plan). The collector stores details as sent; no collector, emitter or interface change is needed. A run without a plan sends the identity it always has.

National release.

  • The build run's plan goes in its telemetry and in build_record.json, now schema 4. Certification refuses a schema 3 record with its existing message ("Certify the build with the code it was built with (), or build it again into a new --out").
  • Certification makes its own plan, from the budget its post-export worker plan read and the batch size the build recorded, with the workers it chose. Its telemetry carries it, and both manifests get resource_plan: {"build": …, "certification": …}: at the top level of build_manifest.json, and in the build object of release_manifest.json, beside timing, which the build-folder rewrite moves to the top level.

The post-export worker plan moves into the resource plan.

  • PostExportWorkerPlan.record() keeps only the workers' figures (mode, chosen_by, workers, maximum_batch_size, worker_peak_bytes, planned_peak_bytes, memory_cap_bytes, max_units_per_worker). The machine, budget and core limit are recorded once, at the top of the plan.
  • It is resource_plan.certification.post_export_workers. A serial run records it too; before, a serial run's execution was {"mode": "serial"} alone.
  • The pooled scorer's execution record keeps what the pool did and no longer carries resources; _PostExportPooling no longer takes them.
  • The release tool's _post_export_pooling_from_environment is split into _post_export_worker_plan_from_environment (the plan, serial included) and _post_export_pooling (the pool it starts, None for serial). The probe's post_export_pooling_for is split into post_export_worker_plan_for and post_export_pool_for.

Post-export probe. Its report holds its plan (resource_plan); the report's schema goes from 2 to 3, as its comment asks for any layout change. A probe of the frame-based stages alone, which reads no budget for its work, records a budget it cannot read as the plan's error and stops nothing.

Local-area release. Its stages can run in separate invocations on machines of their own (the Modal plan runs materialize and calibrate on the large class, and qa, finalize and package on the small one).

  • Each invocation keeps its plan in resource_plans.json in the checkpoint directory (InvocationPlans): one entry per invocation, with its start time, its telemetry run ID and the stages it finished, each added as it finishes. A stage finished again moves to the later entry, and an entry left with no stages is removed, so each stage keeps the plan of the invocation that produced its results. An invocation refused by a stage's own checks, or whose first stage fails, leaves no entry.
  • The package stage is handed the entries with its own added (InvocationPlans.entries_after) and writes them into both manifests as resource_plan; the file takes the stage only once do_package returns, so a package run refused before writing anything takes nothing.
  • No stage deletes the file: the stages delete only named files.

Base and ACS staging. Each writes resource_plan.json, with the same entries, beside its summary, never inside it: the base's resume check hashes the summary, so a plan in it would stop a resume on another machine or with another budget.

  • The base lists the steps an invocation added to the checkpoint run context (stage_run_context.json's completed): a resumed --stage all run skips the steps an earlier run finished, and a failed run keeps the ones it finished. On the compatibility path (no checkpoint directory) it lists all once the run returns.
  • A base run that starts with nothing finished (a new checkpoint directory, or the compatibility path) starts a new build: once it finishes a step, the earlier build's entries go. One refused before any step leaves them.
  • A base child stage, whose parent records its telemetry, writes nothing.
  • The ACS staging command lists all once its build returns 0.

A plans file that cannot be read (not strict JSON, another schema) is left out with a warning and replaced by the next record; one that cannot be written gives a warning. The plan never stops a build.

Decisions (Anthony, 2–3 December 2026)

  1. One plan per command run, not per stage ("Once per run"). The release manifests hold two, the build run's and certification's.
  2. The base and ACS staging commands write their own file plus telemetry ("Own file + telemetry"), leaving the hashed summary unchanged.
  3. The full set of figures ("Full set"): machine, budget and core limit with sources, every thread variable, the QRF workers, the batch or chunk size.
  4. The post-export worker plan moves into the resource plan ("Move it").
  5. The build record goes to schema 4 ("Bump to 4").
  6. Local-area invocations each save their plan in the checkpoint directory for the package stage ("Save and collect").

Outputs unchanged (decision 1.1 · 1)

The plan is run metadata. It only reads: the environment, host_resources and joblib.cpu_count() (through audit_thread_controls). It is written only to:

  • telemetry;
  • build_record.json;
  • the manifests;
  • the probe report;
  • new files: resource_plans.json in the local-area checkpoint directory, and resource_plan.json beside the base and staging summaries.

No H5, calibrated weights, target values or calibration_diagnostics.json change, and no thread variable is set or changed. The four build commands already import microcosm.fit.qrf and scikit-learn when they load (checked by importing each tool and inspecting sys.modules), so the QRF reading changes no import order. Neither existing comparison reads the new blocks:

  • certification's check of the rebuilt batching plan (post_export_scoring_plan);
  • the probe's compare_post_export_plans, which reads only post_export_scoring.consumers.

The Modal receipt lists the new files, and its comparison with a local reference reads only named checkpoint files.

Tests

Each change comes after a commit of tests that fail before it. Interfaces the tests call are added as stubs that record nothing; the worker-plan and pool split in the first commit is real, because it is a refactor. Each run below selected tests by node ID:

  • 97410ee5a (tests) and 08eb38767 (change). 43 tests, 58 cases with parametrization:
    • on the tests commit, 32 failed, each on an assertion (AssertionError, or pytest's "DID NOT RAISE"), and 26 passed. The 26 are guards, plus existing tests whose helpers changed;
    • on the change, all 58 passed.
  • Review round 1, 7a627747a and c249fffe4: on the tests commit, 7 new tests failed on assertions, and 12 repaired or guard tests passed; on the fix, 77 cases passed.
  • Review round 2, ef774ead7 and fde8e8599: on the tests commit, 6 new tests failed on assertions; on the fix, 82 cases passed.
  • Review round 3, 70abe1165 and f8b336a1e: on the tests commit, 2 new tests failed through pytest.fail, and 22 repaired tests passed; on the fix, all 166 added or changed cases passed.

New tests:

  • engine_free/shared/test_resource_plan.py: the plan's figures and sources, defaults, QRF override and refusal, post-export workers, the thread list, the plan's size, and the invocation merge and file (including damaged files).
  • test_telemetry_identity.py, test_program_telemetry.py: the plan in the first event.
  • test_us_fiscal_refresh_builder.py:
    • schema 4 and the build's plan;
    • refusing a schema 3 record;
    • certification's plan in its telemetry and handed to the manifests;
    • both plans in both manifests, with the release contract's checks passing;
    • the build run's plan in its telemetry and record;
    • the plan's batch size.
  • test_us_post_export_pool.py, test_us_post_export_pooled_scoring.py, test_us_post_export_probe.py: the worker-only record, serial and pooled; the split functions; the execution record without resources; the probe's plan and report.
  • test_us_modal_build_programs_telemetry.py:
    • each of the three programs sends and keeps its plan;
    • local-area invocations merged across three runs;
    • a refused local-area stage, or a refused package stage, takes nothing;
    • the package stage is handed its own plan;
    • a resumed, failed or refused base run, and a new base build;
    • a failed base compatibility run, or a refused ACS staging run, records nothing;
    • a base child stage writes nothing.
  • test_us_acs_local_release_tool.py: package writes every invocation's plan into both manifests.

Existing tests this branch updated, because the commands now read attributes their real parsers define, or the interfaces moved:

  • the stand-in arguments of nine tests (test_us_fiscal_refresh_builder, test_us_puf_support_base_builder, test_us_modal_build_programs_telemetry), with output paths in each test's temporary directory;
  • the runtime_identity stand-ins in test_emitter_adapter;
  • two test_us_post_export_pool tests, which read the budget from the worker plan rather than its record.

Review

Three rounds of adversarial review, each in a fresh session, before this PR; every bug was fixed with a test that failed first, and none is left open. The review files are kept in the project's notes, not in the repository.

  • Round 1: 3 bugs.
    • High: nine existing tests' stand-in arguments lacked attributes the commands now read. Fixed in the tests.
    • Medium: entries were recorded at an invocation's start, with the stages it was asked to run, so a resumed base run replaced the earlier run's entry and a refused run took over an entry. Fixed: entries list the stages an invocation finished.
    • Low: a frame-only probe stopped on an unreadable budget. Fixed: recorded as the plan's error.
  • Round 2: 2 bugs.
    • Medium: the package stage added itself before running, so a refused package took the stage. Fixed with entries_after.
    • Low: the base's file kept an earlier build's entries after a new build. Fixed: replaces_earlier.
    • Also fixed: a failed write leaves no staged file.
  • Round 3: 3 bugs.
    • High: test_emitter_adapter's runtime_identity stand-ins took no arguments. Fixed in the tests.
    • High: two pool tests read the budget from the worker record. Fixed in the tests.
    • Low: a plans file holding NaN made the next write raise. Fixed: strict-JSON read.
    • Also fixed: the staged file's cleanup no longer hides an interrupt.

Code-quality points left as they are:

  • the base reads stage_run_context.json itself, rather than through microcosm.build.outer_stage_runtime;
  • several wiring tests compare call-site text, as the repository's neighbouring tests do.

What this PR's merge waits for

Earlier tasks of substage 1.8, each to be merged (nothing in them is deployed: no package release, endpoint or schema this PR uses once deployed):

Not in this PR

  • Per-stage plans: task 2.6's planner adds them when it chooses workers per stage.
  • The local-area chunk options that tasks 1.7 · 2 and 1.7 · 4 are changing: the plan records --hh-chunk as it is today. The local-area --batch option (households per microsimulation within a chunk) is not recorded; the decision named --hh-chunk.

🤖 Generated with Claude Code

anth-volk and others added 11 commits December 3, 2026 01:48
Tests that fail before the change, with the interfaces they call as stubs
that record nothing, so each new test fails on its assertions:

- microcosm.build.resource_plan: one plan per run (machine, memory budget
  and core limit with their sources, thread variables, QRF workers, batch
  size, post-export workers) and one entry per invocation in a plans file;
- the plan in the run's first telemetry event (runtime_identity,
  LocalTelemetryEmitter.start, program_telemetry);
- the release: the build run's plan in build_record.json, schema 4;
  certification's own plan; both in the manifests; the post-export worker
  plan's record holds only the workers' figures, and the pooled execution
  record no longer carries it;
- the export probe's report;
- the local-area release's plans per invocation, which package writes into
  both manifests; the base and ACS staging commands' resource_plan.json.

The worker plan and the pool are split apart in the release tool and the
probe (_post_export_worker_plan_from_environment, _post_export_pooling,
post_export_worker_plan_for, post_export_pool_for) so a serial plan is
still a plan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tracker task 1.8 · 4)

Each run of a US build command records the plan it ran under, once per run,
as run metadata that no output depends on (microcosm.build.resource_plan):
the machine's memory and usable cores with their sources, the memory budget
and core limit with theirs (the option, its variable or the default),
MICROCOSM_THREADS and every thread variable it fills, the QRF's fit jobs and
prediction workers (worker_identity.audit_thread_controls, now public), the
command's batch or chunk option and, for certification and the probe, the
post-export workers chosen.

- The run's first telemetry event carries it (details.identity.resource_plan)
  through runtime_identity, LocalTelemetryEmitter.start and
  program_telemetry.
- The national release's build run records its plan in build_record.json,
  schema 4; certification refuses a schema 3 record and names the code that
  built it. Certification adds its own plan and writes both into the
  manifests as resource_plan (top level of build_manifest.json, the build
  object of release_manifest.json, which the build-folder layout moves to
  its top level).
- PostExportWorkerPlan.record() holds only the workers' figures and is
  resource_plan.certification.post_export_workers, for serial scoring too;
  the pooled execution record no longer carries it.
- The probe's report (schema 3) holds its plan.
- The local-area release keeps each invocation's plan, with the stages it
  ran, in resource_plans.json in its checkpoint directory (a stage run again
  keeps only its latest plan); the package stage writes every plan into both
  manifests.
- The base (parent invocation only) and ACS staging commands write
  resource_plan.json beside their summary, one entry per invocation; the
  base's summary and its resume check are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… · 4)

Tests that fail before the fix, with InvocationPlans as a stub:

- An invocation's entry lists the stages it finished, added as each one
  finishes: a refused or failed local-area stage takes nothing from the run
  that finished it; a resumed base --stage all run lists the steps it added
  to the checkpoint run context, a failed run's included; a failed
  compatibility run, a refused base run and a refused ACS staging run leave
  no entry; the package stage still finds its own plan among those it
  writes; a plans file that cannot be written warns and stops nothing.
- A probe of the frame-based stages alone records a memory budget it cannot
  read instead of stopping.

Nine existing tests stood in parsed arguments without the attributes the
real parsers define and the commands now read (maximum_microsim_batch_size,
out, chunksize); their stand-ins gain them, with output paths in each
test's temporary directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'s unreadable budget (tracker task 1.8 · 4)

Review round 1's findings:

- A plans file's entry now lists the stages its invocation finished, added
  as each one finishes (InvocationPlans), instead of the stages it was asked
  to run, recorded at its start. A local-area stage refused by its own
  checks, or failing, takes nothing from the run that finished it; the
  package stage adds itself before it runs, so its manifests hold its own
  plan. The base lists the steps an invocation added to the checkpoint run
  context (a resumed --stage all run skips the steps an earlier run
  finished, and a failed run keeps the ones it finished), or, on the
  compatibility path, "all" once it returns. The ACS staging command adds
  "all" once its build returns 0. Entries of one invocation are merged by
  its start time and telemetry run.
- A plans file that cannot be written is reported on standard error; the
  build goes on.
- A probe of the frame-based stages alone records a memory budget it cannot
  read as its plan's error instead of stopping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… · 4)

Tests that fail before the fix, with InvocationPlans.entries_after and its
replaces_earlier option as stubs:

- the local-area package stage is handed the plans its manifests hold, its
  own included, and the plans file takes the stage only once it returns, so
  a package run refused before writing anything takes nothing from the run
  that packaged;
- a base run that starts with nothing finished (a new checkpoint directory,
  or the compatibility path) replaces the earlier build's entries once it
  finishes a step; one refused before any step leaves them;
- a failed rename of the plans file leaves no staged file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…st one's entries (tracker task 1.8 · 4)

Review round 2's findings:

- The local-area package stage is handed the plans its manifests record,
  its own added (InvocationPlans.entries_after), and the plans file takes
  the stage only once do_package returns, so a package run refused before
  writing anything (an existing release directory, say) takes nothing from
  the run that packaged.
- A base run that starts with nothing finished (a new checkpoint directory,
  or the compatibility path) builds anew: once it finishes a step, the
  earlier build's entries in --out's resource_plan.json go
  (replaces_earlier). One refused before any step leaves them.
- record_invocation_plan removes its staged file when the write or the
  rename fails.
- Comments say "finished" where entries list the stages an invocation
  finished.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… · 4)

Tests that fail before the fix: a plans file holding NaN is replaced, not
fatal; a write interrupted while its staged file cannot be removed raises
the interrupt, not the removal's error.

Tests the change left on the old interface:
- test_emitter_adapter's stand-ins for runtime_identity take the
  resource_plan keyword LocalTelemetryEmitter.start now passes;
- test_us_post_export_pool reads the memory budget and core limit from the
  worker plan's budget, since its record holds only the workers' figures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…p's error (tracker task 1.8 · 4)

Review round 3's findings:

- read_invocation_plans refuses NaN and Infinity, so a file another
  program wrote with them is left out with a warning and replaced by the
  next record, instead of making that record's strict write raise.
  InvocationPlans.add also reduces a ValueError to a warning: the plan
  never stops a build.
- record_invocation_plan's removal of its staged file after a failed write
  no longer replaces the original error (an interrupt, say) with its own.
- The base's comment and the runbook give the right reason a new build
  replaces the earlier build's entries: its outputs replace the earlier
  build's in --out when it finishes.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts resolved by keeping both sides: 1.8 · 2's record_stage_resources
and stage_resource_use beside this branch's resource_plan, in
program_telemetry, LocalTelemetryEmitter.start, the release tool's build
record, manifests and emitter starts, and the local-area release's main
and package stage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
….8 · 4)

_run_local_main_with_stubbed_stages, which 1.8 · 2 added, stood in parsed
arguments without hh_chunk, which the parser always gives and main now
reads for the run's resource plan, and a do_package stand-in that took no
options, where main now hands it resource_plans. engine-free (3.14) failed
on test_each_stage_s_resource_use_reaches_its_end_event_and_the_checkpoint.

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

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

US builds: record each run's resource plan (budget, workers, threads, batch size) in the manifests and telemetry

1 participant