Skip to content

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

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

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

Conversation

@anth-volk

Copy link
Copy Markdown
Collaborator

Fixes #4380
Do not merge: raise the .py pin (pyproject.toml, docker/Dockerfile, uv.lock) to the .py release that contains the dataset-inputs fix (expected 6.20.5), and set FIRST_RELEASE_RECORDING_DATASET_INPUTS and the changelog fragment to that release (this PR's own step, once the release is published).

Summary

This moves API v1 onto the .py release that lists a US dataset's inputs in input_variables (expected 6.20.5). 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 them. policyengine-us's marginal_tax_rate recalculates each adult's 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 only once API v1 sends the fixed release, which is what this PR does. API v1's /v2/ routes read the model catalog for the same installed version.

The pin raise itself isn't in this PR yet: the release isn't published. Until it is, the PR holds the test that fails before the raise and the changelog fragment. Once .py publishes the release, this PR checks that the release's history contains the fix's merge, raises both pins and relocks (uv lock --upgrade-package policyengine), sets FIRST_RELEASE_RECORDING_DATASET_INPUTS and the changelog fragment to that version, adds to the fragment anything else the release changes for API v1, and removes the "Do not merge" line. The bundle update workflow will open its own "Update PolicyEngine bundle to " PR for the same release; that one gets closed without merging, as a duplicate of this PR.

This branch is built on #4377 (auto/update-policyengine-bundle-6.20.4, .py 6.20.0 → 6.20.4), which changes the same pins first. Until #4377 merges, this PR's diff includes its commits.

What the merge waits for

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

  • D5 · 9 (Update PolicyEngine bundle to 6.20.4 #4377, .py 6.20.4): merged. It changes the same pins first; this PR needs nothing from its deployment beyond what D5 · 12's deployment requires.
  • D5 · 11 (the .py fix, PolicyEngine/policyengine.py): deployed, meaning its release is published. This PR pins that release.
  • D5 · 12 (PolicyEngine/policyengine-sim-api, the simulation service on the same release): deployed. API v1 sends its installed .py version with each economy request, and its version check requires the simulation service's latest to be that version.
  • Every other earlier task in substage D5 (D5 · 1 to D5 · 8, D5 · 10) is already complete.

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. The new test also fails until the raise.
  • 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.

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.x, and each such result expires within 30 days of being written. Nothing is deleted by hand.

Changes

  • 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 until the release is published), 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.
  • Once the release exists: pyproject.toml, docker/Dockerfile, uv.lock.

Tests

  • New test tests/unit/test_constants.py::TestPolicyEngineBundleVersions::test__requests_name_a_release_that_records_dataset_inputs. On the 6.20.4 pin (c6eab652) it fails on its assertion: assert <Version('6.20.4')> >= <Version('6.20.5')>. It's run again after the raise.
  • make quality (the commit hook) passed on every commit; check_changelog_fragment.sh against master passes. No other tests were run locally.

Review

Two rounds of adversarial review, 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 the fix also corrects labor supply responses, which hasn't been checked on .py's dataset path. 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 constant's comment says 6.20.5 is expected and the pin raise sets it to the release that contains the fix; the labor supply claim is removed; the fragment is 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, the constant's comment names the fragment, and the wording names the adults marginal_tax_rate raises (the two with the highest market income).
  • Bugs left: none. The release version stays an assumption until the release is published; the pin raise checks it.

Environment variables

This PR adds or changes no environment variable, secret or workflow.

🤖 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.88%. Comparing base (d385ad0) to head (24815f9).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4381      +/-   ##
==========================================
- Coverage   93.90%   93.88%   -0.03%     
==========================================
  Files         459      459              
  Lines       26172    26172              
  Branches     4047     4047              
==========================================
- Hits        24578    24571       -7     
- Misses        909      916       +7     
  Partials      685      685              
Flag Coverage Δ
integration 60.65% <ø> (ø)

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.

This branch was previously deployed

1 inactive 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