Skip to content

US base: check the policyengine-us lock file once per run, and import torch only where it is used - #1750

Merged
anth-volk merged 13 commits into
mainfrom
claude/us-base-engine-lock-once-3d03d8
Nov 26, 2026
Merged

anth-volk merged 13 commits into
mainfrom
claude/us-base-engine-lock-once-3d03d8

Conversation

@anth-volk

@anth-volk anth-volk commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Tracker task 1.5 · 1 (project "15. US build memory, CPU and run time", substage 1.5 "Base stage fixed costs").

What this changes

Every process that imports microcosm.build.us_runtime builds US_SPINE_AGREEMENT_REGISTRY at module load. That loads the US take-up contract, which runs assert_engine_abi_lock_current: it derives engine_abi.lock.json afresh from the installed policyengine-us and compares bytes. The derivation imports policyengine-us, builds two tax-benefit systems (PolicyEngineUSEngine().take_up_contract()) and indexes policyengine-us's source code for the remaining-stage input manifest. A --stage all base run starts 90 such processes: 24 step processes, and 66 QRF workers (one per QRF variable) inside primary_qrf_chain. The tracker counts these as 89.

After this change:

  • A passed check issues a record. When assert_engine_abi_lock_current passes the full comparison, the process remembers what it compared: the lock file's SHA-256, the installed policyengine-us version, and the SHA-256 of the canonical JSON of the take-up and sources domains. engine_abi_lock_check_environment(root) returns that record as MICROCOSM_ENGINE_ABI_LOCK_CHECK_RECORD, with the issuing process's ID.
  • Who passes it on.
    • --stage all adds it to each step process's environment (_staged_subprocess_environment, one added call).
    • run_primary_puf_qrf_chain adds its caller's own record to every QRF worker it starts, whether or not the caller passes an environment. The base tool's primary_qrf_chain step passes none. An inherited record would not do: its issuer is the worker's grandparent, so the worker would ignore it. tools/build_us_multispine_pool.py calls the chain the same way, so its workers benefit too. Review round 1 caught that, without this, the base stage's workers still ran the full check.
    • primary_qrf_worker_launch_environment() adds the calling process's record too. That environment is used for the QRF workers the release tool's stacked spine starts and for the clean import trace behind the QRF worker identity.
  • What a child does with it. A process whose environment holds a record issued by its own parent (issuer_pid == os.getppid()) does not derive the lock. It reads the lock file and refuses to run when:
    • the lock file's SHA-256 differs from the record's;
    • the installed policyengine-us version differs, or policyengine-us is not installed;
    • the take-up and sources domains' digest differs;
    • the record is malformed.
      It still checks that the lock is valid against its schema and names the recorded engine version. It then issues the same record to its own children.
  • No record, or someone else's record. A process with no record, or with a record issued by any process other than its parent, runs the full check as before. That covers a named --stage run by hand, the release tool, tests and every other importer. The process-ID binding follows the existing TELEMETRY_PARENT_PID_VARIABLE rule, so a record inherited through an intermediate process is ignored instead of trusted.

What the record is keyed on, and why

  • Lock file SHA-256 and installed policyengine-us version: the tracker task's key.
  • The take-up and sources domains: added. The fresh derivation reads these two bundle domains as well as the engine. The child loads them anyway to build its take-up projection, so hashing them costs milliseconds. Without them, a child would project an edited take_up.yaml through the lock its parent checked against the old one.
  • Microcosm's own code: not recorded. A record reaches only the issuing process's direct children, which run the same checkout within the same run. Hashing microcosm's sources in every child is the per-child cost task 1.5 · 2 removes. A source edit during a base run is the base stage's run-config check to catch (builder_code_identity), not this record's.
  • The installed policyengine-us files: not recorded. The record uses the distribution version, as the task title says. A same-version reinstall with different contents during a run would not be noticed. The dist-info RECORD digest could be added cheaply if wanted.

The other option: build the registry on first use

I checked whether building US_SPINE_AGREEMENT_REGISTRY on first use would, on its own, keep the check out of the base processes. I tried it with the registry assignment temporarily replaced by an empty tuple.

  • At import: nothing else loads the take-up contract. A QRF worker import then took 5.4–5.7 s and did not import policyengine-us.
  • During a step: I found no base step that reads the take-up contract. Its readers are the spine-agreement check, take-up seeding in the release tool's pool, graph.py (whose module-level _ROOT_CELLS reads it), the QBI reconciliation validations in multispine_pool, register_consistency and the local-area take-up. This is from reading the code, not from a run.
  • So a lazy registry alone would most likely mean no base process, the parent included, checks the lock file at all. It would also stop importing us_runtime from checking the lock file for every other importer. This PR keeps the parent record as the tracker title asks. Combined with a lazy registry, each worker start would drop by a further ~3 s (YAML loading, schema validation and the registry build). That would also need each QRF worker to check the record explicitly at start, so it still refuses a changed lock file. Left as a possible follow-up.

Measurements

Wall time and peak resident set size (ru_maxrss from wait4) of one process start, measured from a Python driver that issues the record and starts each child itself. Each child runs --help, so it does its imports, including the lock check, and exits. The figures are medians of 3 starts on a 10-core, 32 GB Mac at load average 5–6 from other sessions, so they run higher than the tracker's idle-machine 21–26 s.

  • Step process start (tools/build_us_puf_support_base.py --help):
    • before this branch: 37.8 s wall, 35.5 CPU-s, 1.54 GB;
    • with the record: 9.0 s, 8.6 CPU-s, 0.47 GB;
    • with the record and torch moved: 6.3 s, 6.1 CPU-s, 0.30 GB.
  • QRF worker start (python -m microcosm.build.us_runtime.puf_qrf_worker --help):
    • before: 36.6 s, 34.9 CPU-s, 1.75 GB;
    • with the record: 9.1 s, 8.9 CPU-s, 0.46 GB;
    • with the record and torch moved: 8.4 s, 7.7 CPU-s, 0.29 GB.
  • Without a record (a named --stage run, the release tool), a start still runs the full check: 36.5 s and 1.65–1.75 GB on this branch.
  • Per base run: all 90 step-process and QRF-worker starts now take the record path, and only the --stage all process runs the full check. At these figures that saves about 41 CPU-minutes per run on this machine: 24 step starts × 29 CPU-s plus 66 worker starts × 27 CPU-s.
  • Profile before the change (cProfile, so times are inflated about 2x): 69 s in load_take_up_contract, of which 56 s is the fresh derivation (45 s for the engine contract, 32 s of that building the two systems; 11 s for the remaining-stage manifest).
  • The QRF worker identity's clean import trace takes 9.2 s with a record instead of 52.8 s.

QRF worker identity

The clean import trace in worker_identity.py now receives the record of the process computing the identity. So it opens the same files whether or not that process itself received a record from its parent. The monolith (_run_all), a staged run and a named --stage run therefore compute the same identity.

  • The record's value is not part of the identity, and the variable is not in _BOUND_ENVIRONMENT_NAMES or _WORKER_ENVIRONMENT_OVERRIDES.
  • With the record, the trace opens three fewer microcosm files: us_runtime/gate_shadow.py, us_runtime/multispine_pool.py and us_runtime/us_late_overlap_ownership.py. It also imports 46 fewer standard-library modules (389 → 343), and neither policyengine-us nor torch.
  • So the identity digest changes once. Decision 1.1 · 1 allows that: the digest fingerprints how the build works, not a data output.
  • No committed file pins the digest (the bundle resolves it at run time through resolver_op), so no recorded expectation changes.
  • Recorded bindings in checkpoint directories or pools made before this change will not match the new identity, as after any code change.
  • The trace itself now takes 9.2 s instead of 52.8 s.

Torch

python -X importtime showed one source of torch in a step process and a QRF worker: microcosm.calibrate.solve's module-level import torch (and its from microcosm.calibrate.gates import HardConcrete). It is reached through microcosm.build → country_spec → ledger_targets → microcosm.calibrate. Of the brief's candidates:

  • gates.py is loaded only through solve.
  • uk_runtime/firm_generation.py is not loaded at all by these processes, so it is left alone.

The twelve solve functions that use torch at run time now import it themselves, and _optimize imports HardConcrete. Annotations keep TYPE_CHECKING imports.

Breaking the chain anywhere else would have meant editing at least seven modules that import from solve at module level, one of them an attested kernel source too (puf_aggregate_records).

Re-pinned, on Anthony's choice to do it in this PR. solve.py and us_runtime/puf_qrf_chain.py are in the source lists whose digest the spec engine's legacy-v1 seed protocol records (spec_engine/seeds.py). The protocol records the digest; it does not use it to make draws. So these move:

  • EXPECTED_HASHES["seed_map"] and ["seed_protocol"] in spec_engine/inventory_coverage.py, with a comment saying why, as earlier moves there have;
  • docs/evidence/spec-engine/us-f0-coverage.json;
  • the spec_sha256 pins in tests/engine_free/shared/test_spec_engine_loader.py and tests/engine_workflow/us/test_us_multispine_pool_tool.py.

All of these were written by tools/repin_us_spec_engine_contracts.py, run in the documented order. Its first pass wrote covered_item_count == 40 into test_spec_engine_coverage_tool.py while the seed digests were still stale. A second pass restored 41, and --check then passes. tools/spec_engine_coverage.py reports 42,404 of 42,404 configuration fields and 41 of 41 inventory checks.

Two test pins of the solver's helper sources also move, in pre_best_iterate/controls.json and test_l2_basis.py: _apply_constraint and _relative_error_loss now begin with import torch. The two tests that compare the recorded pre-change optimizer with the current one still return identical bytes in all 10 cases.

No other copy of an old digest remains in the repository. The spec_sha256 of the am, be, nz and uk bundles also changes, but nothing pins those.

Overlap

Merging and UK builds

From review: merging this re-keys the UK solve.

  • calibrate.adam@1 hashes all of calibrate.solve, and every UK solve kernel embeds its hash.
  • uk.full.problem@1 also hashes calibrate.solve.
  • The torch import move changes solve.py's bytes, so the next UK full build re-solves.
  • A build run with --require-solve-reuse against a graph store written before the merge stops with SolveReuseError.

So merge before a UK build that writes the store or after the build that reuses it, not between the two. The changelog fragment says so too.

Review

Adversarial review by independent reviewers, two per round:

  • Round 1 found that the base tool's QRF workers inherited only the --stage all process's record. Their parent is the step process, so they ignored it and still ran the full check. Fixed in f9f4c6874, with a failing test first (56bf1eb58).

  • Round 2 found three things:

    It also found several inaccurate comments and an engine test that asserted only an exit code. Both reviewers confirmed the record path with real processes at three levels: parent, step process, and a QRF worker started by the real run_primary_puf_qrf_chain.

  • Review on GitHub at 5ba293efb found nothing blocking. It raised the UK point above and answered the open items below.

  • Round 3 found no high- or medium-severity defects and no existing test that the branch makes fail. Its three wording points are fixed in the last commit. One reviewer checked the rewritten torch test by making the launcher stop forcing TORCH_DEVICE_BACKEND_AUTOLOAD; the test then failed, as it should.

Tests

Failing tests came first in each red-green pair (6b67ee4af, 56bf1eb58, da07ae5ea). Every test was run on its own; no suite was run.

New tests. All pass on the rebased branch with policyengine-us 2.2.1 installed. The engine-free files also pass in an environment without policyengine-us, as in the engine-free CI job.

  • packages/microcosm-build/tests/engine_free/shared/test_spec_engine_engine_abi_check_record.py (15), with a fake engine:
    • a passed check issues a record of what it compared;
    • the parent's record replaces the fresh derivation;
    • a child refuses a different lock file, a different or missing policyengine-us, changed take-up or sources domains, and five kinds of malformed record;
    • a record from another process is ignored and the full check still refuses a stale lock;
    • without a record the full check runs.
  • packages/microcosm-build/tests/engine_free/us/test_us_engine_abi_lock_check_record.py (10):
    • step processes, the QRF workers run_primary_puf_qrf_chain starts (with and without a caller environment) and the launch environment receive the record;
    • real step and QRF worker processes refuse to start when the lock file or the installed policyengine-us differs from their parent's record;
    • neither process imports torch at start.
  • packages/microcosm-build/tests/engine_contract/us/test_us_engine_abi_lock_check_record.py (4):
    • the issued record matches the lock file and the installed engine;
    • a step process and a QRF worker with their parent's record start without importing policyengine-us;
    • the full load_bundle("us") accepts the record (same domains digest) and does not import policyengine-us.
  • packages/microcosm-calibrate/tests/engine_free/shared/test_solve_torch_import.py (2): importing microcosm.calibrate does not import torch; a solver function imports it on first use.

Existing tests whose pins or code this branch changes, run by node ID. All pass.

  • packages/microcosm-calibrate/tests/engine_free/shared/test_l2_basis.py::test_defaults_reproduce_the_pre_change_optimizer_bytes (7 cases) and packages/microcosm-calibrate/tests/engine_free/shared/test_solve.py::test_best_iterate_preserves_pre_change_excluded_paths (3 cases). Both compare the recorded pre-change optimizer with the current one byte for byte.
  • packages/microcosm-build/tests/engine_free/us/test_us_stacked_spine.py::test_stacked_worker_first_torch_import_forces_autoload_off, rewritten for the new import order, in both environments.
  • packages/microcosm-build/tests/engine_free/shared/test_spec_engine_loader.py::test_semantic_hash_has_golden_vector_and_surface_separation.
  • packages/microcosm-build/tests/engine_workflow/us/test_us_multispine_pool_tool.py::test_constants_adapter_equals_live_constants_and_stays_out_of_identities.
  • On Python 3.14:
    • packages/microcosm-graph/tests/engine_free/shared/test_graph_parity_pins.py::test_the_pinned_implementation_hash_is_the_registered_kernel_s[calibrate];
    • packages/microcosm-graph/tests/engine_free/shared/test_graph_parity_pins.py::test_every_pinned_platform_key_is_the_one_that_platform_would_compute[calibrate];
    • packages/microcosm-graph/tests/engine_free/shared/test_acceptance_h_parity.py::test_h1_kernel_parity.

Checks. These all pass:

  • tools/repin_us_spec_engine_contracts.py --check;
  • tools/spec_engine_coverage.py (42,404 of 42,404 configuration fields, 41 of 41 inventory checks);
  • python3 tools/ci_test_plan.py verify;
  • ruff check and ruff format --check on every changed file.

Not run: the base bit-equivalence test. packages/microcosm-build/tests/engine_workflow/us/test_us_puf_support_base_equivalence.py::test_monolith_and_staged_builds_are_bit_exact_at_every_boundary needs CPS 2022–24, puf_2024.h5 and ACS 2022 inputs. None of them is on the Mac this was built on. The data-placement ruling in docs/us-modal-stage-runbook.md allows the PUF only on the policyengine Modal volumes. Anthony pre-approved this test at reduced size (5,000 households). Running it would have needed either the inputs here or a Modal run. On the review's reasoning (under "Open"), Anthony decided on 2026-11-26 to skip it for this change.

Open

  • The bit-equivalence test: skipped, on Anthony's decision of 2026-11-26. Review judged it not needed for this change:
    • torch reads its thread count from the environment at its first parallel operation, not at import (checked with torch 2.12.0), so the solve keeps its thread count and summation order;
    • nothing in microcosm reads the recursion limit or warning filters that importing policyengine-us used to set.
  • Engine matched by version only. A child compares the policyengine-us version string only, not its installed files. policyengine-core is not compared either; the docstring of _LockCheckInputs says so. Review found this enough: on Modal the image fixes both packages, and the lock's engine entry names policyengine-us alone.
  • Global state no longer set at start. Step processes and QRF workers no longer import policyengine-us or torch at start, so they no longer get the global state those imports set:
    • Python's recursion limit raised to 3000 (via IPython's jedi);
    • an ignore-all warnings filter;
    • torch's own warning filters;
    • one draw from Python's global random, which importing policyengine-us made (in rich.style).
      Review found no base step that depends on any of these. The only microcosm code that uses the global random, the QRF's leaf shuffle, seeds it first.
  • Building the registry on first use, as a possible follow-up (see above).
  • A Modal plan could set the record variable. Raised by round 3, not changed here. tools/modal_us_stage_plan.py lets a plan set MICROCOSM_* variables, and the runner does not remove MICROCOSM_ENGINE_ABI_LOCK_CHECK_RECORD from a container's environment. It does refuse and remove MICROCOSM_TELEMETRY_PARENT_PID. A plan that set a well-formed record whose issuer ID equals the tool's parent process ID in the container would let --stage all skip deriving the lock. That needs someone to set it on purpose. Refusing the name there, as is done for the telemetry variable, would close it. Review agreed this can be a follow-up.

🤖 Generated with Claude Code

anth-volk and others added 12 commits November 26, 2026 00:19
…check

Every process that imports microcosm.build.us_runtime derives
engine_abi.lock.json afresh from the installed policyengine-us (two
tax-benefit system builds and an index of policyengine-us source) and
compares bytes. These tests describe a record of a passed check that a
process hands its children:

- a passed check records the lock file's SHA-256, the installed
  policyengine-us version and the SHA-256 of the take-up and sources
  domains, bound to the issuing process ID;
- a child that receives its parent's record compares those values instead
  of deriving the lock, and refuses a lock file, installed policyengine-us
  or domains that differ, or a malformed record;
- a record issued by any process other than the parent is ignored, and a
  process with no record still runs the full check;
- the base tool's step processes, the QRF workers and the QRF worker
  identity's import trace receive the record;
- real step and QRF worker processes refuse to start when the lock file or
  the installed policyengine-us differs from the record, and start without
  importing policyengine-us when it matches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…en a record

A process that passes the full check of engine_abi.lock.json now
remembers what it compared: the lock file's SHA-256, the installed
policyengine-us version and the SHA-256 of the take-up and sources
domains. engine_abi_lock_check_environment() hands that record, bound
to the issuing process ID, to the processes it starts through
MICROCOSM_ENGINE_ABI_LOCK_CHECK_RECORD.

A process holding a record issued by its own parent reads the lock file
and compares the three values instead of deriving the lock afresh (two
tax-benefit system builds and an index of policyengine-us source). It
refuses to run when the lock file, the installed policyengine-us or the
domains differ, or the record is malformed. A process with no record, or
one issued by any other process, runs the full check as before.

The base tool's --stage all process passes its record to each step
process. primary_qrf_worker_launch_environment() passes the calling
process's record to the QRF workers and to the clean import trace behind
the QRF worker identity, so that trace opens the same files however the
process computing the identity was started. The identity digest changes
once: the trace no longer opens gate_shadow.py, multispine_pool.py or
us_late_overlap_ownership.py.

Measured on a 10-core Mac at load average 5-6, median of 3 starts:
a step process start fell from 37.8 s and 1.54 GB peak RSS to 9.0 s and
0.47 GB, and a QRF worker start from 36.6 s and 1.75 GB to 9.1 s and
0.46 GB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
run_primary_puf_qrf_chain starts the QRF workers from the step process.
When its caller passes no environment, as the base tool's primary_qrf_chain
step does, each worker only inherits the step process's environment, whose
record was issued by the --stage all process. The worker's parent is the
step process, so it ignores that record and still derives the lock afresh.
The test requires every worker the chain starts to receive the record of
the step process's own check, with or without a caller environment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
run_primary_puf_qrf_chain now adds us_engine_abi_lock_check_environment()
to every worker's environment, whether or not its caller passes an
environment. The base tool's primary_qrf_chain step passes none, so its
workers previously inherited only the --stage all process's record, which
they ignore because their parent is the step process, and each one derived
the lock afresh. tools/build_us_multispine_pool.py calls the chain the same
way and gains the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Importing microcosm.calibrate imports microcosm.calibrate.solve, whose
module-level `import torch` (and its import of HardConcrete from gates)
loads torch in every US base step process and QRF worker, about 1.4 s
and 100-200 MB each, although none of them calibrates. The tests require
that importing the calibration package, or starting a base step process
or QRF worker, does not import torch, and that a solver function that
uses torch imports it on first use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
microcosm.calibrate.solve imported torch, and HardConcrete from
microcosm.calibrate.gates, at module level. Every importer of
microcosm.calibrate therefore loaded torch, including each US base step
process and QRF worker, none of which calibrates. The twelve solve
functions that use torch at run time now import it themselves, and
_optimize imports HardConcrete; annotations keep their TYPE_CHECKING
imports. No computation changes: the pre-change optimizer comparisons in
test_l2_basis.py and test_solve.py still return identical bytes.

solve.py and puf_qrf_chain.py are among the sources whose digest the
spec engine's legacy-v1 seed protocol records (it is recorded, not used
to draw), so these move, re-pinned with
tools/repin_us_spec_engine_contracts.py:
- EXPECTED_HASHES seed_map and seed_protocol in inventory_coverage.py;
- docs/evidence/spec-engine/us-f0-coverage.json;
- the spec_sha256 pins in test_spec_engine_loader.py and
  test_us_multispine_pool_tool.py.
The helper-source pins for _apply_constraint and _relative_error_loss in
pre_best_iterate/controls.json and test_l2_basis.py move because both
helpers now begin with `import torch`.

With the lock-check record, a step process start now takes 6.3 s and
0.30 GB peak RSS and a QRF worker start 8.4 s and 0.29 GB (median of 3
on a 10-core Mac at load average 5), against 37.8 s / 1.54 GB and
36.6 s / 1.75 GB before this branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Round 1 of review noted that a child compares only the policyengine-us
version string. State that a same-version reinstall or a changed
policyengine-core during a run is not noticed by a child with a record.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_stacked_worker_first_torch_import_forces_autoload_off exited at the
worker's first torch import, which used to happen while the worker's
parent packages loaded. Now that microcosm.calibrate.solve imports torch
inside the functions that use it, loading the worker imports no torch, so
the child reached main() and failed on the test's placeholder manifest.

The child now loads the worker module, checks that torch is still absent,
then makes the process's first torch import itself and records the same
controls, plus the device-backend setting the launcher passed before the
worker module could set its own.

Also correct three comments that said solve imports torch at load time, or
that step processes pass the parent's record on to their QRF workers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_the_full_us_bundle_loader_accepts_the_parents_record asserted only
the child's exit code, which a child that ignored the record and ran the
full check would also pass. It now also requires that the child imports
no policyengine-us. The changelog now says that the QRF workers of the
multispine pool tool and the release tool's stacked spine receive a record
too, since run_primary_puf_qrf_chain adds it for every caller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After rebasing onto main (which moved the same pins for #1686's shared
SIPP read), re-run tools/repin_us_spec_engine_contracts.py in its
documented order, twice so the coverage test's covered-item count is
taken after the seed digests are current, then tools/spec_engine_coverage.py
and the re-pin tool's --check:
- EXPECTED_HASHES seed_map and seed_protocol in inventory_coverage.py;
- docs/evidence/spec-engine/us-f0-coverage.json;
- the spec_sha256 pins in test_spec_engine_loader.py and
  test_us_multispine_pool_tool.py, each with a line saying why it moved.

calibrate.adam@1's implementation hash covers solve.py's bytes, so re-pin
the calibrate graph parity case with tools/graph_parity_repin.py on
arm64/darwin/py3.14, the platform it was recorded on. The tool refuses if
the kernel's output bytes move; they did not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The refusal messages no longer repeat engine_abi.lock.json, which
  SpecValidationError already prints from its source.
- The _LockCheckInputs docstring says only direct children act on a
  record, since every descendant can inherit the variable.
- docs/spec-engine.md says a process issues a record after the full
  comparison or after matching its own parent's record.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main changed solve.py (weights bounded against a declared reference) and
re-pinned the same digests this branch moves. The five pin files that
conflicted take main's side and are regenerated on the merged tree:
- tools/repin_us_spec_engine_contracts.py in its documented order, run
  twice, then tools/spec_engine_coverage.py (42404/42404 fields, 41/41
  inventory checks) and --check: EXPECTED_HASHES seed_map and
  seed_protocol, docs/evidence/spec-engine/us-f0-coverage.json, and the
  spec_sha256 pins in test_spec_engine_loader.py and
  test_us_multispine_pool_tool.py, with this branch's reason lines added
  after main's;
- tools/graph_parity_repin.py calibrate on arm64/darwin/py3.14; the
  kernel's output bytes did not move.

Main's new solve.py code uses torch only inside functions that already
import it, and nothing in solve.py imports torch at module level. The
solver helper-source pins still match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk marked this pull request as ready for review November 26, 2026 14:16
@anth-volk
anth-volk requested a review from juaristi22 November 26, 2026 14:16

@juaristi22 juaristi22 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 5ba293efb. A child with its parent's record refuses every mismatch it should, nothing a step computes depends on what this moves, and nothing on our side blocks it.

On your open points:

  • The bit-equivalence run: not needed for this change. torch takes its thread count from the environment at its first parallel operation, not at import (checked with torch 2.12.0), so the solve keeps its thread count and summation order. Nothing in microcosm reads the recursion limit or the warnings filters that importing policyengine-us used to set. That import also drew once from Python's global random (in rich.style), and the only microcosm code using it, the QRF's leaf shuffle, seeds it first.
  • Engine matched by version only: enough. On Modal the image fixes both packages, and during a local run the full check caught a policyengine-core change only when it changed the derived lock, whose engine entry names policyengine-us alone.
  • The Modal plan variable: fine as a follow-up; refusing it as MICROCOSM_TELEMETRY_PARENT_PID is refused would close it.

For UK builds, as with #1746: merging moves calibrate.adam@1, whose hash every UK solve kernel embeds, and uk.full.problem@1, which hashes calibrate.solve itself. The next UK full build therefore re-solves, and a dense build run with --require-solve-reuse against a store written before the merge stops with SolveReuseError. It's worth merging between such a pair, not in the middle.

What I checked

  • With policyengine-us 2.2.1 and real processes, a child with its parent's record imports neither policyengine-us nor torch: a step-tool start takes 6.1 s and 0.30 GB instead of 31.5 s and 1.69 GB, and a QRF worker start 5.7 s and 0.29 GB instead of 27.4 s and 1.63 GB.
  • A child refuses a record with a different lock SHA-256, engine version or domains digest, or one that isn't JSON, and ignores a record from any process other than its parent, so it runs the full check.
  • All 13 functions in solve.py that use torch or HardConcrete import them, and the new order (scikit-learn's OpenMP before torch's) runs on macOS. The seed formula doesn't read the source digests, so the moved seed_map and seed_protocol pins change no draw.
  • All 190 targeted engine-free tests (among them the whole of test_solve.py and test_l2_basis.py, and test_h1_kernel_parity on the calibrate pin's own platform) and the 16 that need policyengine-us pass locally, as do repin_us_spec_engine_contracts.py --check and spec_engine_coverage.py. It merges cleanly with #1737 and #1747, and CI is green apart from engine-free, which is still running.

Review of #1750 noted that calibrate.adam@1, whose hash every UK solve
kernel embeds, and uk.full.problem@1 both hash calibrate.solve, so the
torch import move re-keys the UK solve: a build run with
--require-solve-reuse against a graph store written before the merge
stops with SolveReuseError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk merged commit 4b78a9b into main Nov 26, 2026
12 checks passed
@anth-volk
anth-volk deleted the claude/us-base-engine-lock-once-3d03d8 branch November 26, 2026 18:20
anth-volk added a commit that referenced this pull request Nov 26, 2026
Brings in task 1.5 · 1, which adds the policyengine-us lock-file check
record to _staged_subprocess_environment. No conflicts: this branch
merges MICROCOSM_US_BASE_PARENT_DIGESTS on top of that environment in
_run_staged_all, and the two use different variables.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
juaristi22 added a commit that referenced this pull request Nov 26, 2026
…nd, the table_copies hash binding, and US and NZ changes (#931)

Main took five pull requests since e29843d: #1734 (New Zealand's receipt
target cap), #1749 (staging hands a run's files over at its start and its
results at its end, with no upload interval), #1761 (the UK stage,
population and calibration hashes bind microcosm.frame.table_copies), #1725
(the US post-export merged baseline sweep) and #1750 (the US base engine
lock checked once). No UK feed or engine pin moves.

Eight files conflicted.
- uk_runtime/graph_calibration.py, graph_kernels.py and graph_population.py:
  #1761 binds table_copies into the stage, population and calibration
  hashes; this branch already binds it, as frame_table_copies, in every UK
  kernel that computes through it (bbe3633), so the merge keeps this
  branch's side. The population kernels #1761 binds are gone on the
  clone-first spine, so its new test in test_uk_kernel_frame_copies holds
  the national problem kernel, which copies through context_frame, in their
  place, with the pool checkpoint kernel as the control.
- test_uk_rowwise_candidate: #1749's dense role without an upload interval;
  this branch's removal of the constituency vintage stays.
- The US seed map and seed protocol, the loader's golden spec vector and
  the US pool test's spec pin, computed on the merged tree, and the US F0
  coverage report, regenerated (--check passes, and so does the US
  re-pinner's --check).

The UK gate contract pins, the stage table and the coverage manifest are
current on the merged tree.

Checks: with policyengine-uk hidden, as in CI's engine-free job, the
tests main's five pull requests change, the UK graph's binding rules,
the kernel frame copies (main's new test among them), the clone-first
nesting, the transport binding rule and identity, the graph parity pins,
the spec-engine loader and the Child Benefit stage and gate tests
(2,729 pass); the US coverage report and pins (--check); and the UK gate
pins, the stage table and the coverage manifest (--check).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants