Repository navigation
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-budgetand--max-cores), which has merged, as has task 1.8 · 2;mainis merged in, with their changes kept beside this PR's (1.8 · 2'sstage_resource_useandrecord_stage_resourcesnext toresource_plan), so this PR's diff againstmainis 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_BUDGETordefault);max_cores: the setting and its source;cores: the usable cores, at most--max-cores;threads:MICROCOSM_THREADSand 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,nullwhen unset. A test holds this list totools/us_build_thread_environment.py's;qrf:POPULACE_FIT_N_JOBSandPOPULACE_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;nullfor 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.startandprogram_telemetrytakeresource_plan). The collector storesdetailsas sent; no collector, emitter or interface change is needed. A run without a plan sends the identity it always has.National release.
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").resource_plan: {"build": …, "certification": …}: at the top level ofbuild_manifest.json, and in thebuildobject ofrelease_manifest.json, besidetiming, 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.resource_plan.certification.post_export_workers. A serial run records it too; before, a serial run'sexecutionwas{"mode": "serial"}alone.executionrecord keeps what the pool did and no longer carriesresources;_PostExportPoolingno longer takes them._post_export_pooling_from_environmentis split into_post_export_worker_plan_from_environment(the plan, serial included) and_post_export_pooling(the pool it starts,Nonefor serial). The probe'spost_export_pooling_foris split intopost_export_worker_plan_forandpost_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'serrorand 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).
resource_plans.jsonin 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.InvocationPlans.entries_after) and writes them into both manifests asresource_plan; the file takes the stage only oncedo_packagereturns, so a package run refused before writing anything takes nothing.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.stage_run_context.json'scompleted): a resumed--stage allrun skips the steps an earlier run finished, and a failed run keeps the ones it finished. On the compatibility path (no checkpoint directory) it listsallonce the run returns.allonce 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)
Outputs unchanged (decision 1.1 · 1)
The plan is run metadata. It only reads: the environment,
host_resourcesandjoblib.cpu_count()(throughaudit_thread_controls). It is written only to:build_record.json;resource_plans.jsonin the local-area checkpoint directory, andresource_plan.jsonbeside the base and staging summaries.No H5, calibrated weights, target values or
calibration_diagnostics.jsonchange, and no thread variable is set or changed. The four build commands already importmicrocosm.fit.qrfand scikit-learn when they load (checked by importing each tool and inspectingsys.modules), so the QRF reading changes no import order. Neither existing comparison reads the new blocks:post_export_scoring_plan);compare_post_export_plans, which reads onlypost_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) and08eb38767(change). 43 tests, 58 cases with parametrization:AssertionError, or pytest's "DID NOT RAISE"), and 26 passed. The 26 are guards, plus existing tests whose helpers changed;7a627747aandc249fffe4: on the tests commit, 7 new tests failed on assertions, and 12 repaired or guard tests passed; on the fix, 77 cases passed.ef774ead7andfde8e8599: on the tests commit, 6 new tests failed on assertions; on the fix, 82 cases passed.70abe1165andf8b336a1e: on the tests commit, 2 new tests failed throughpytest.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: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 withoutresources; the probe's plan and report.test_us_modal_build_programs_telemetry.py: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:
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;runtime_identitystand-ins intest_emitter_adapter;test_us_post_export_pooltests, 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.
error.entries_after.replaces_earlier.test_emitter_adapter'sruntime_identitystand-ins took no arguments. Fixed in the tests.Code-quality points left as they are:
stage_run_context.jsonitself, rather than throughmicrocosm.build.outer_stage_runtime;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
--hh-chunkas it is today. The local-area--batchoption (households per microsimulation within a chunk) is not recorded; the decision named--hh-chunk.🤖 Generated with Claude Code