Skip to content

Run API v1 on .py 6.20.5, which records US dataset inputs - #4381

Draft
anth-volk wants to merge 13 commits into
masterfrom
v2plan/d5-13-py-dataset-inputs
Draft

anth-volk wants to merge 13 commits into
masterfrom
v2plan/d5-13-py-dataset-inputs

Conversation

@anth-volk

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

Copy link
Copy Markdown
Collaborator

Fixes #4380

Summary

This raises API v1's .py pin (policyengine[models]) from 6.20.4 to 6.20.5. 6.20.5 holds only PolicyEngine/policyengine.py#783, which lists a US dataset's stored columns in input_variables. From .py 6.0.0 to 6.20.4, PolicyEngineUSLatest.run built a US simulation empty and stored each dataset column with set_input, so policyengine-core's input_variables, which it fills only when the simulation is constructed, didn't list most of them. policyengine-us's marginal_tax_rate recalculates household net income in a branch of the simulation that deletes every variable not in that list, so the branch lost the household's income other than earnings, its age and its location, and cliff_gap counted the lost income as a cliff gap.

API v1's target=cliff economy results come from the simulation service, which runs .py on the version API v1 sends as policyengine_version (its installed POLICYENGINE_VERSION). API v1 has run .py 6.x since 2026-09-29, so its cliff results have shown the inflated gaps since then. They're correct once API v1 sends 6.20.5, which is what this PR does. API v1's /v2/ routes read the model catalog for the same installed version.

This PR replaces the bundle workflow's PR for the same release (#4390), which is closed without merging.

What 6.20.5 changes for API v1

  • US economy results calculated from datasets (the simulation service's 6.20.5 app): marginal_tax_rate keeps the household's inputs, so target=cliff results no longer count lost income as cliff gaps. In .py's example, a 67-year-old in Wake County, North Carolina, with $15,000 of earnings and $24,000 of Social Security in 2026 had a cliff_gap of $22,645; it is now policyengine-us's $0.
  • US labor supply responses, which read marginal tax rates, change too. In .py's example, one earner's response to a reform moves from -$591.09 to policyengine-us's -$655.38. The release's changelog also names the federal, state and FICA marginal rates and the trust fund revenue attribution variables.
  • Unchanged: policyengine-core (3.34.10), policyengine-us (2.2.2), policyengine-uk (2.179.2) and the certified data releases; the bundle manifest changes only its version labels. API v1's in-process household calculations are built from situations, not datasets, so they don't change.
  • Stored economy results: API v1 keeps economy results in its Redis cache (runtime_cache/reform_impacts.py), each for at most 30 days. The cache version (constants._build_runtime_cache_version) and the economy options hash (_build_options_hash) both include the .py version, so after the raise no request reads a result calculated on 6.20.4 or earlier, and each such result expires within 30 days of being written. Nothing is deleted by hand.
  • The /v2/ model catalog: the master deploy's "Seed and validate the v2 metadata catalog" step publishes the 6.20.5 catalog before Cloud Run deploys, as for every bundle update.

What the merge waits for

Tracker tasks before this one (D5 · 13 in "5. Detailed-save API"), and what each must reach:

CI until then:

  • Before D5 · 12 is on staging: the job "Ensure PolicyEngine bundle is the simulation API's latest" fails, and the test shards, the Docker and Cloud Run image builds and the environment-variable tests, which depend on it, are skipped.
  • After D5 · 12 deploys: every API v1 master deploy stops at "Ensure staging model version aligns with simulation API" until this PR merges, so it merges soon after D5 · 12 reaches production.

Changes

  • pyproject.toml, docker/Dockerfile, uv.lock: .py 6.20.4 → 6.20.5 (uv lock --upgrade-package policyengine). The lock's policyengine changes are the same as the bundle workflow's (Update PolicyEngine bundle to 6.20.5 #4390).
  • tests/unit/test_constants.py: a new test checks that POLICYENGINE_VERSION, the version API v1 sends as policyengine_version, is at least FIRST_RELEASE_RECORDING_DATASET_INPUTS (6.20.5), the first release that records dataset inputs. A neighbouring test from Update PolicyEngine bundle to 6.20.4 #4377 already checks that this version equals the installed one, which the /v2/ routes read.
  • changelog.d/py-dataset-inputs.fixed.md: the fix, for people who use or run API v1. Its name differs from the bundle workflow's update-policyengine-bundle-<version>.changed.md.

Tests

  • New test tests/unit/test_constants.py::TestPolicyEngineBundleVersions::test__requests_name_a_release_that_records_dataset_inputs, run by its node ID:
    • committed first on the 6.20.4 pin (c6eab652), where it fails on its assertion: assert <Version('6.20.4')> >= <Version('6.20.5')>. CI's shard 6 at 24815f9c failed on the same assertion, and only on it (2,150 other tests passed);
    • after the raise (5491248f), it passes.
  • make quality (the commit hook) passed on every commit, and uv lock --check passes. check_changelog_fragment.sh against master passes. No other tests were run locally.

Review

Two rounds of adversarial review before the PR opened, each by a subagent working only from the code (files kept outside the repository).

  • Round 1: no high-priority bugs. Medium: the test, constant and fragment assumed the fix ships as 6.20.5, and a 6.20.5 without the fix would pass; the fragment claimed labor supply responses change, which hadn't been checked. Low: the fragment's name, update-policyengine-bundle-6.20.5.fixed.md, matched the bundle workflow's fragment for the same release. Fixes: the version stayed an assumption until the raise, which checked that 6.20.5 holds Update PolicyEngine US to 0.479.1 #783 and nothing else; the labor supply claim was removed until .py's 6.20.5 changelog measured it; the fragment was renamed py-dataset-inputs.fixed.md; the docstring describes marginal_tax_rate's branch exactly.
  • Round 2: no bugs at any priority. Its quality findings are fixed: the docstring is written relative to FIRST_RELEASE_RECORDING_DATASET_INPUTS, and the wording names the adults marginal_tax_rate raises (the two with the highest market income).
  • Bugs left: none. The pin raise (5491248f) was added after the review rounds, as planned; its lock change matches the bundle workflow's.

Environment variables

This PR adds or changes no environment variable, secret or workflow. After merging, the deploy's catalog step reads the same variables as every bundle update (V2_DATA_WRITE_DATABASE_URL, HUGGING_FACE_TOKEN from PE_UK_PRIVATE_HF_READ_TOKEN, SIMULATION_ENTRYPOINT_URL; GitHub Actions secrets wired through push.yml's secrets: inherit), and 6.20.5 changes no data release they read.

🤖 Generated with Claude Code

github-actions Bot and others added 12 commits December 1, 2026 01:45
API v1's economy requests send its installed .py version as
policyengine_version, and the simulation service runs each request on the
app it deployed for that version; the /v2/ routes read that version's
catalog. Releases before 6.20.4 rank households with equal incomes with
numpy's default sort, whose order depends on the CPU. This test fails on
the 6.20.0 pin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The changelog fragment names the stable inequality sort and the
policyengine-uk, policyengine-core and UK data release changes from 6.20.1
to 6.20.3. The dynamic parameters' docstring names the installed
policyengine-uk version, whose gov.dynamic. folder is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The changelog fragment says policyengine-core's reform and caching fixes may
also change some US household results, and that the /v2/ model catalog gets
a 6.20.4 version for both countries. The docstring states the range of
policyengine-uk versions it was checked against, so the next bundle update
doesn't make it wrong.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
uv.lock is master's, relocked with uv lock --upgrade-package policyengine as
the bundle update workflow does: policyengine 6.20.4, policyengine-core
3.34.10 and policyengine-uk 2.179.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
master moved the simulation client pin to 0.20261201.454, and its lock
conflicted with this branch's. uv.lock is master's lock relocked with
`uv lock --upgrade-package policyengine`, so it differs from master's
only in policyengine 6.20.4, policyengine-core 3.34.10 and
policyengine-uk 2.179.2.

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

API v1 sends its installed .py version with each economy request, and the
simulation service runs the request on that version's app. From .py 6.0.0
to 6.20.4, a US simulation built from a dataset doesn't list the dataset's
columns in input_variables, so policyengine-us's marginal_tax_rate copies
delete them and target=cliff results count the lost income as cliff gaps.
This test fails until API v1 pins the release that fixes it (expected
6.20.5).

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Describe marginal_tax_rate's branch exactly (the two highest earners, and
the lost age and location as well as income), say that 6.20.5 is the
expected release until the fix is published, drop the fragment's labor
supply claim until the release is checked, and give the fragment a name
the bundle workflow's fragment for the same release won't share.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Write the docstring relative to FIRST_RELEASE_RECORDING_DATASET_INPUTS, name
the fragment in the constant's comment, and describe marginal_tax_rate's
adults and the lost inputs exactly.

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

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.77%. Comparing base (d385ad0) to head (5491248).
⚠️ Report is 26 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4381      +/-   ##
==========================================
- Coverage   93.90%   93.77%   -0.14%     
==========================================
  Files         459      459              
  Lines       26172    26644     +472     
  Branches     4047     4149     +102     
==========================================
+ Hits        24578    24986     +408     
- Misses        909      954      +45     
- Partials      685      704      +19     
Flag Coverage Δ
integration 60.92% <ø> (+0.26%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Raise policyengine[models] from 6.20.4 to 6.20.5 in pyproject.toml and
docker/Dockerfile and relock (uv lock --upgrade-package policyengine).
6.20.5 holds only PolicyEngine/policyengine.py#783, which lists a US
dataset's stored columns in input_variables; the bundle's other package
versions and data releases are unchanged. Cite #783 in the test's constant
and name the labor supply change in the changelog fragment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk anth-volk changed the title Run API v1 on the .py release that records US dataset inputs Run API v1 on .py 6.20.5, which records US dataset inputs Dec 3, 2026

This branch had an error being deployed

1 failed deployment
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.

Run API v1 on the .py release that records US dataset inputs

1 participant