Skip to content

Allow explicit local US data without unused bundle certification - #761

Merged
MaxGhenis merged 20 commits into
mainfrom
codex/us-local-unmanaged-runtime
Dec 3, 2026
Merged

MaxGhenis merged 20 commits into
mainfrom
codex/us-local-unmanaged-runtime

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #760

What changes

A bare import policyengine defers both country namespaces and makes no network call. First US access, and construction from an explicit local file with allow_unmanaged=True, no longer certify the unused bundled dataset. Local provenance records the file's SHA-256 and the checked wrapper, country, Core and SPM versions, with compatibility_basis="unverified_explicit_local_unmanaged", certified_by=None, country_id="us" and managed_by. UK initialisation keeps its eager compatibility check.

Pass allow_unmanaged=True to fetch a Hugging Face URI other than the bundled default. The wrapper checks US bundled-data certification before it fetches either kind of URI.

Where certification now runs

  • US managed materialisation, the managed year-file helpers, US model runs and output reuse, model bundle receipts, model TRACE and run-record exports check current US runtime compatibility on each call and refuse an unverified offline fallback.
  • Before it creates the output directory, run-record export refuses a supplied bundle TRO unless it matches the attached model's country, bundle manifest, data build and certified runtime. When the bundle pins the model wheel's SHA-256, export also refuses a TRO unless it lists exactly one model wheel, with the pinned name, version and SHA-256. With an attached model, export recomputes the supplied bundle TRO's composition fingerprint from its artifact hashes and refuses a TRO whose stated fingerprint differs. It also refuses a TRO whose artifact digests aren't 64 lowercase hex digits.
  • Selecting a managed URI directly uses the bundle's selection rules; the compatibility check happens when the data is materialised.
  • create_datasets() and ensure_datasets() accept explicit local files with allow_unmanaged=True. A missing absolute local source raises FileNotFoundError before certification in create, ensure and load.
  • The standalone long-term loader checks that a local HDF5 file holds all its own storage, and checks its metadata, before it reads the tables. It accepts in-file virtual storage.
  • The receipt and the TRACE certification comment name the certified US version, and the local SPM path checks the version actually loaded.

Caches

US year files record the source and runtime that produced them. Saved and in-memory US outputs record the calculation inputs, the resolved legacy SPM profile, the policy and dynamic reforms, the effective scope, the requested columns and the runtime. Unread annotation columns and unused ID aliases change neither the calculation nor the cache identity. A file whose identity is missing or differs is stale, and the ensure helpers regenerate it.

Native input periods

native_input_period="2017" sets both defaults before the first US country constructor for an explicit local .h5 file in TIME_PERIOD_ARRAYS format. The wrapper keeps the stored annual and monthly period keys and values. It refuses directories, HDF5 links and storage outside the file, and non-.h5 paths, the last before hashing. It turns an empty root into ValueError and preserves unrelated I/O failures. The native clock needs a four-digit year string and can't combine with projection, scoping or conflicting defaults. Callers still choose the tax-benefit system and structural start date.

This includes the follow-up from #773: country_id="us" in local provenance, a factory check for a file before construction, a real Core mixed-period constructor test that checks the loaded values, and a check that Hugging Face transport certifies before its request.

Workflows

  • PR code checks run on opened, synchronised, reopened and edited pull requests and on manual dispatch. A PR that changes only docs/**, README.md, CONTRIBUTING.md, CHANGELOG.md or CODE_OF_CONDUCT.md skips the code jobs. The changelog check compares the PR head with its actual target (origin/main on manual dispatch). The required job checks every dependency's result, including the bundle verification skip on forks.
  • UK candidate qualification starts on manual dispatch only; its scheduled recovery and requalification paths stay in the file, marked dormant.
  • Publish installs and smoke-tests the built wheel before the PyPI upload and the GitHub release. The pypi environment controls deployment authorisation for trusted publishing. Pages uses actions/configure-pages@v5.

Changes since 2cb1d96db

6e87cad6:

  • Run-record export accepts the shipped US TRO when the data release manifest is available. The certificate built from that manifest has no Core binding, and the shipped TRO says bundle_pin. At 2cb1d96db, export refused that pair. Export now treats an omitted binding and bundle_pin as the same binding when the certificate names no exact Core version. It still compares a certified binding and the Core version exactly.
  • At 2cb1d96db, export never checked a supplied TRO's model wheel. Export now refuses a TRO whose wheel differs from the bundle's pinned wheel.
  • For the output cache identity of a raw legacy SPM file, the US model hashes the same household and SPM-unit links that legacy declaration derivation selects. At 2cb1d96db, the model also hashed the unused alias columns, and pandas raised TypeError on a list-valued alias.
  • The SPM runbook dates its pins, bundle checks and sidecar hash to wrapper release 6.20.2, under the title "Canonical SPM wrapper development history".
  • New tests export the shipped US TRO with and without an available data release manifest. They require export to refuse Core binding, Core version and wheel substitutions before it creates the output directory. Another test changes the scope weight file under an unchanged request and requires the memory and disk caches to return the new weights. Other tests add a list-valued unread column or unused ID alias to a saved request and require memory and disk cache hits, including for a registered raw legacy SPM file.

6f22b8b3:

  • The run record cites a supplied TRO's composition fingerprint. At 2cb1d96db, export read that fingerprint without checking it. With an attached model, export now recomputes it from the TRO's artifact hashes and refuses a TRO whose stated fingerprint differs. The shipped US and UK TRO fingerprints match their artifact hashes. A new test case replaces the fingerprint and requires refusal with and without an available data release manifest.

760b1860:

  • At 6f22b8b3, export raised a raw TypeError on a numeric artifact digest while it sorted the hashes, and it accepted a TRO that had a non-hex digest and a matching fingerprint. Export now refuses any artifact digest that isn't 64 lowercase hex digits as invalid bundle provenance. Two new test cases cover an integer digest and a non-hex digest with a matching fingerprint, each with and without an available data release manifest.

Verification

At 760b1860, only py_compile, git diff --check, ruff format --check and ruff check have run locally. GitHub CI passed all 16 checks at this head across Code changes (all 14 jobs, including PR code checks and Test on Python 3.11–3.14, run), Docs changes and Agent notes, running the test cases added since 2cb1d96db.

Linux pytest runs used Python 3.13.5 in the repository's frozen uv dev environment, with no credentials. 751a6bec has the same source tree as 2cb1d96db. Counts are passed, failed and skipped.

Run Passed Failed Skipped
968af6150, the 9 test files this PR changes, with 20 regression cases overlaid 456 16 0
751a6bec, the 9 test files this PR changes 472 0 0
751a6bec, the other 137 test files 4,536 0 15
  • The 20 cases overlaid at 968af6150 covered both output cache paths and valid cache hits, the identity of raw legacy SPM files, unread list-valued columns, supplied TRO mismatches, missing local paths and HDF5 virtual storage.
  • With 23 cases overlaid on 7aec0df9b, 19 failed and 4 passed. All 23 passed at 968af6150.
  • Socket audits at 968af6150 and 751a6bec recorded no network attempt through a bare import, first US access and real local construction, under both the installed US 2.2.2 and simulated 2.3.0 metadata.
  • Python 3.13.13 built the wheel and sdist at 751a6bec. The extracted publish smoke step passed on the built wheel and stopped a corrupt wheel at install and a failing wheel at import. The installed wheel's import and bundle CLI made no audited network attempt.
  • Actionlint 1.7.11, Ruff 0.17.6, the Towncrier fragment check, git diff --check and both SPM bundle checks passed at 751a6bec. Both vendored TRACE sidecars at that commit bind its bundle manifest.

At 2cb1d96db, the Python 3.11–3.14 test jobs and the required PR code checks job failed. Each test job had one failure: run-record export refused the shipped US TRO in test_supplied_run_record_tro_matches_certified_us_bundle[None]. The other 11 jobs passed, including lint, Mypy and the four installation smoke jobs.

The local runs didn't cover Darwin, population runs that need a credential, branch protection or the PyPI environment's configuration. #762 tracks repeated offline certification requests and the remaining P3 edge cases. #784 tracks a TRO bound to a certified Core version, which the publisher path would still refuse; no current bundle uses that binding.

axiom: n/a: wrapper runtime, dataset provenance and release workflow plumbing.

🤖 Generated with Claude Code

MaxGhenis and others added 13 commits November 30, 2026 18:39
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nance

Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: GPT-6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cy columns

Round 3 found that this branch rejected the shipped US TRO, causing all four CI test failures; that the model wheel went unchecked; and that an unused raw legacy alias broke the cache hash. An omitted Core binding and bundle_pin now resolve to the validated manifest pin, while explicit bindings and versions stay strict. A pinned wheel digest now requires one wheel with that name and SHA-256. The cache hash uses the same household and SPM-unit link selector as legacy declaration derivation. The SPM runbook now dates its pins to wrapper release 6.20.2 and is titled as history. Tests cover each case and the two scope gaps round 3 named.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The run record cites the supplied bundle TRO's composition fingerprint, but the validator only read it. It now recomputes the fingerprint from the artifact hashes and refuses a TRO whose claimed value differs. The shipped US and UK TROs match their artifacts, and a new mismatch case covers a replaced fingerprint on both certification paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A numeric digest raised a raw TypeError while the fingerprint sorted
them, and a non-hex string passed once the fingerprint was recomputed.
The validator now requires each digest to be 64 lowercase hex digits
and refuses others as invalid provenance. Two new cases cover a
non-hex string with a matching fingerprint and an integer digest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis
MaxGhenis marked this pull request as ready for review December 3, 2026 12:54
@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Merging at 760b1860fec32a06217e65314fa398fa54bf95f8.

  • Independent model review (GPT-6.2 Sol, Subfleet 20261202-221140-ukhub-r4-7281, lanes-1202/7281/r4/out.md) at 6f22b8b3: VERDICT: APPROVE.
  • Follow-up commit 760b1860fec32a06217e65314fa398fa54bf95f8 (Refuse a supplied TRO whose artifact digests aren't SHA-256 hex) rejects non-hex and non-string TRO artifact digests and adds two regression cases (src/policyengine/provenance/trace.py, tests/test_us_unmanaged_runtime.py). Latent certified-core publisher binding is tracked in #784.
  • All 16 live PR checks pass at 760b1860fec32a06217e65314fa398fa54bf95f8 (Code changes 47110184662 including Python 3.11–3.14 tests, Agent notes 47110184116, PR code checks 47028018871, and Docs changes 47028018821), with MERGEABLE / CLEAN and conflict-free merge-tree against 7024e226 (6.20.7).

@MaxGhenis
MaxGhenis merged commit ba6c1b5 into main Dec 3, 2026
31 checks passed
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.

Allow explicit local US data without certifying the unused default bundle

2 participants