Route all analysis microdata loading through policyengine.py's managed path - #77
Merged
Conversation
…d path
Standing rule (2026-08-01): population/analysis compute always goes through
the latest released policyengine (>=5.0.1) — pe.us.managed_microsimulation()
/ pe.uk.managed_microsimulation() — never a directly-imported country-package
Microsimulation, whose default dataset can lag the certified bundle. Direct
country-package use remains fine for engine development and tests.
- backend-builder + new-tool Modal templates: install policyengine[us]==
latest (pins country model + certified bundle), compute statewide impacts
via managed_microsimulation, pre-cache the certified dataset in the image
snapshot, surface sim.policyengine_bundle provenance; note the
HUGGING_FACE_TOKEN requirement for UK microsim images
- policyengine skill: state the latest-release floor in Setup, document the
policyengine_bundle provenance attribute and UK twin, harden the
deprecation note
- microsim-runner: pin the local path to latest policyengine (>=5.0.1)
- anti-rot lint: ban `from policyengine_{us,uk} import ... Microsimulation`
in skills/targets/docs so the deprecated pattern cannot return; deliberate
deprecation notes carry <!-- stale-ok -->
managed_microsimulation behavior (kwargs forwarding, bundle pinning,
policyengine_bundle attribute, HF-cache materialization) verified against
the policyengine.py 5.0.1 tag source.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…m guard
Adversarial review (sol) of the first round found two blockers:
1. Live scaffolding still prescribed the bare country package for
society-wide Modal work: the policyengine-tools skill's Pattern C
image installed policyengine-us==X.Y.Z, and the dashboard planner
emitted policyengine_package: policyengine-us for a microsimulation
endpoint. Both now install the top-level policyengine[us]==X.Y.Z
(>=5.0.1) and route population endpoints through
pe.us.managed_microsimulation(); the planner's NJ-pattern prose stops
teaching a bare policyengine-us pin.
2. The anti-rot guard caught only a same-line
"from policyengine_{us,uk} import ... Microsimulation". It now also
catches submodule/whitespace variants, module-qualified
policyengine_us.Microsimulation(...) constructors, and paren-wrapped
multiline imports (whole-file pass), scans .ipynb, and a parametrized
corpus pins nine banned and eight allowed spellings. stale-ok is
documented (CONTRIBUTING + lint reason) to also cover
explicitly-scoped engine-development examples. Residual limits
(aliased constructors, import *) are documented in the module
docstring.
Nits from the same review: new-tool's Pattern C label, backend-builder's
simulation.py import table row, microsim-runner's local-path summary,
and the writing skill's installation example now all name the top-level
package / managed entry point.
Verified: HUGGING_FACE_TOKEN is read by policyengine 5.0.1
(src/policyengine/bundle.py:596, HF_TOKEN fallback; provenance manifest
reads HUGGING_FACE_TOKEN only). uv run pytest
--ignore=tests/test_skill_examples.py: 86 passed. Wrapper smoke build:
OK.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sol's round-2 verification confirmed blocker 1 closed but kept the guard
blocker open: backslash-continued imports (from policyengine_us import \
<newline> Microsimulation) evaded both the line pass and the paren pass.
The import guard now walks logical lines in a whole-file pass —
(?:[^\n\|backslash]|backslash-newline)* — so same-line and
backslash-continued forms match while a plain newline still terminates;
a word boundary after policyengine_(us|uk) keeps policyengine_us_data
and other sibling packages out. Corpus grows to 12 banned + 10 allowed
spellings (three backslash forms, a backslash-continued Simulation
import, and a policyengine_us_data boundary case). Residual limits are
re-documented: aliased constructors, import *, and dot-split qualified
constructors remain reviewer territory.
Round-2 nits: the tools skill names both MicroSeries spellings (.calc()
US / .calculate() UK); new-tool spells the extras as policyengine[us] /
policyengine[uk] instead of the invalid [us|uk]; microsim-runner's
local-path summary points at the managed pe.{us,uk} surfaces rather
than overstating managed_microsimulation (its flow uses
policyengine.core.Simulation + ensure_datasets); skills/README and the
plugin-maintenance skill now describe the broadened stale-ok semantics
and the maintenance skill's pattern summary includes the microsim
guard.
uv run pytest --ignore=tests/test_skill_examples.py: 91 passed.
Wrapper smoke build: OK.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Aug 2, 2026
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.
Standing rule (2026-08-01)
Analysis/population compute always goes through the latest released
policyengine(>=5.0.1):pe.us.managed_microsimulation()/pe.uk.managed_microsimulation(), which return a bundle-pinned country-packageMicrosimulationwith the same MicroSeries interface and provenance onsim.policyengine_bundle. Directly-imported country-packageMicrosimulationis deprecated for analysis (its default dataset can lag the certified bundle) but remains fine for engine development and tests — YAML tests, variable authoring, and household-levelSimulationdebugging are untouched.What changed
The catalog rebuild (#61) already routed the core skills through the managed surface; this PR fixes the two remaining offenders, hardens the prose, and adds enforcement:
targets/claude/agents/dashboard/backend-builder.md— the last file teaching bareMicrosimulation()for statewide impacts. Now: image installspolicyengine[us]==LATEST(pins exactly-matched country model + certified bundle — verified against the 5.0.1 pins:policyengine-us==1.764.6,policyengine-core==3.30.0),run_statewideusesmanaged_microsimulation()and returnspolicyengine_bundleprovenance, the snapshot function pre-caches the certified dataset in the image's HF cache, and UK microsim images get aHUGGING_FACE_TOKENnote (private dataset repo).targets/claude/commands/new-tool.md— same Modal-template fixes; adds the managed-path rule for tools that need population-scale results.skills/policyengine/SKILL.md— states the latest-release floor in Setup, documentssim.policyengine_bundleand the UK twin, hardens the deprecation note, clarifies thatmanaged_microsimulation(reform=...)is how the country-package reform surface is reached in analysis.targets/claude/agents/microsim-runner.md— local path pinned to latest (>=5.0.1).tests/test_no_stale_references.py— new anti-rot pattern banningfrom policyengine_{us,uk} import ... Microsimulationacross skills/targets/docs, so the deprecated pattern cannot silently return. The three deliberate deprecation notes carry<!-- stale-ok -->.Verification
managed_microsimulationmechanics (keyword-onlydataset=, kwargs forwarding to the country package,allow_unmanagedgate,policyengine_bundlestamping,hf_hub_downloadcache materialization) read from the policyengine.py 5.0.1 tag source, per the repo's verify-before-writing rule.uv run pytest --ignore=tests/test_skill_examples.py— 69 passed.python3 scripts/build_claude_wrapper.pysmoke build — OK.🤖 Generated with Claude Code
Round 2 — adversarial cross-review fixes
A sol (gpt-5.6-sol) adversarial review of the first round found two blockers, both fixed in the second commit:
skills/policyengine-tools/SKILL.mdPattern C installedpolicyengine-us==X.Y.Zfor society-wide Modal workers, andtargets/claude/agents/dashboard/dashboard-planner.mdemittedpolicyengine_package: policyengine-usfor a microsimulation endpoint (both ship in the dashboard-builder/app-development/complete bundles). Both now installpolicyengine[us]==X.Y.Z(>=5.0.1) and route population endpoints throughpe.us.managed_microsimulation(); the planner's NJ-pattern prose stops teaching a barepolicyengine-uspin.from policyengine_{us,uk} import ... Microsimulation. It now also catches submodule/whitespace variants, module-qualifiedpolicyengine_us.Microsimulation(...), and paren-wrapped multiline imports (whole-file pass); scans.ipynb; and a parametrized corpus (9 banned + 8 allowed spellings) pins its behavior.<!-- stale-ok -->semantics are documented (CONTRIBUTING + lint reason) to also cover explicitly-scoped engine-development examples; residual limits (aliased constructors,import *) are documented in the module docstring.Round-2 nits fixed: new-tool's Pattern C label, backend-builder's
simulation.pyimport-table row, microsim-runner's local-path summary, and the writing skill's installation example all name the top-level package / managed entry point. A repo-wide sweep forpolicyengine-{us,uk}==,uv add policyengine-{us,uk}, andpip install policyengine-{us,uk}returns nothing.Additional verification:
HUGGING_FACE_TOKENconfirmed against the policyengine 5.0.1 tag (src/policyengine/bundle.py:596reads it withHF_TOKENfallback; the provenance manifest readsHUGGING_FACE_TOKENonly — the note names the universally-honored variable). Tests: 86 passed. Wrapper smoke build: OK.