Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/modal-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- aca_calc/**
- src/aca_api/**
- tests/test_api_explain.py
- tests/test_api_scenarios.py
- tests/test_enhanced_ptc_reform.py
- tests/test_modal_requirements.py
- tests/test_smoke_test_api.py
Expand All @@ -24,6 +25,7 @@ on:
- aca_calc/**
- src/aca_api/**
- tests/test_api_explain.py
- tests/test_api_scenarios.py
- tests/test_enhanced_ptc_reform.py
- tests/test_modal_requirements.py
- tests/test_smoke_test_api.py
Expand Down Expand Up @@ -63,7 +65,7 @@ jobs:
uv venv --python 3.11
uv pip install -r modal-requirements.txt
- name: Run the API tests
run: .venv/bin/python -m pytest tests/test_api_explain.py tests/test_enhanced_ptc_reform.py tests/test_modal_requirements.py tests/test_smoke_test_api.py
run: .venv/bin/python -m pytest tests/test_api_explain.py tests/test_api_scenarios.py tests/test_enhanced_ptc_reform.py tests/test_modal_requirements.py tests/test_smoke_test_api.py

deploy:
name: Deploy and smoke-test
Expand Down
9 changes: 8 additions & 1 deletion aca_calc/calculations/household.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ def build_household_situation(
"spm_units": {"your household": {"members": ["you"]}},
"tax_units": {"your tax unit": {"members": ["you"]}},
"households": {
"your household": {"members": ["you"], "state_name": {year: state}}
"your household": {
"members": ["you"],
# The credit measures income against the prior year's poverty
# guideline (aca_magi_fraction), so the state is set for that
# year too. Without it, Alaska and Hawaii households get the
# 48 states' lower guideline.
"state_name": {year - 1: state, year: state},
}
},
}

Expand Down
44 changes: 28 additions & 16 deletions aca_calc/calculations/reforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,41 @@
ENHANCED_INITIAL = [0, 0, 0.02, 0.04, 0.06]
ENHANCED_FINAL = [0, 0.02, 0.04, 0.06, 0.085]

ENHANCED_PERIOD = "2026-01-01.2100-12-31"
# H.R. 1834 extends the enhanced schedule for 2026 through 2028.
ENHANCED_PERIOD = "2026-01-01.2028-12-31"


def _enhanced_schedule() -> dict:
"""The enhanced schedule as policyengine-us parameter overrides.

The three lists are replaced together: the threshold list has one more
entry than the rate lists, and current law's lists have a 133% FPL
threshold the enhanced schedule doesn't.
"""
return {
"gov.aca.required_contribution_percentage.threshold": {ENHANCED_PERIOD: ENHANCED_THRESHOLDS},
"gov.aca.required_contribution_percentage.initial": {ENHANCED_PERIOD: ENHANCED_INITIAL},
"gov.aca.required_contribution_percentage.final": {ENHANCED_PERIOD: ENHANCED_FINAL},
}


# gov.aca.ptc_income_eligibility's third bracket starts at 400% FPL; from 2026
# it makes incomes there ineligible.
NO_INCOME_CAP = {"gov.aca.ptc_income_eligibility[2].amount": {ENHANCED_PERIOD: True}}


def create_enhanced_ptc_reform():
"""Create reform extending enhanced PTCs (IRA extension) from 2026 on.
"""H.R. 1834: extend the enhanced premium tax credits for 2026-2028.

Restores the ARPA/IRA applicable-percentage schedule and removes the 400%
FPL eligibility limit, so households above 400% FPL pay at most 8.5% of
income for the benchmark plan.

The three schedule lists are replaced together: the threshold list has one
more entry than the rate lists, and the 2026 law's lists have a 133% FPL
threshold the enhanced schedule doesn't.
income for the benchmark plan. H.R. 1834 passed the House on January 8,
2026; it has not been enacted.

Returns:
Reform: PolicyEngine reform object
"""
return Reform.from_dict(
{
"gov.aca.required_contribution_percentage.threshold": {ENHANCED_PERIOD: ENHANCED_THRESHOLDS},
"gov.aca.required_contribution_percentage.initial": {ENHANCED_PERIOD: ENHANCED_INITIAL},
"gov.aca.required_contribution_percentage.final": {ENHANCED_PERIOD: ENHANCED_FINAL},
"gov.aca.ptc_income_eligibility[2].amount": {ENHANCED_PERIOD: True},
},
country_id="us",
)
return Reform.from_dict({**_enhanced_schedule(), **NO_INCOME_CAP}, country_id="us")


def _contrib_reform(module: str, name: str):
Expand All @@ -57,6 +66,9 @@ def _contrib_reform(module: str, name: str):
def create_700fpl_reform():
"""Create 700% FPL extension reform (Bipartisan Health Insurance Affordability Act).

Introduced by Reps. Dunn (R-FL) and Schneider (D-IL) on December 9, 2025;
not enacted.

This implements the proposed bill's schedule:
- 200-250% FPL: 2% to 4%
- 250-300% FPL: 4% to 6%
Expand Down
1 change: 1 addition & 0 deletions changelog.d/aca-2027-backend.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Model 2027 coverage in the calculator API (requests without a year still get 2026), with H.R. 1834, and return 2026 current law for the same household and incomes alongside 2027 when asked (show_prior_year). Report the benchmark premium at each income. Pin policyengine-us 2.115.0, which has the published 2027 premiums, and give the Modal function 4 GB.
1 change: 1 addition & 0 deletions changelog.d/aca-2027-backend.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Draw the FPL lines from the prior year's poverty guideline, which the credit uses, and give Alaska and Hawaii households their own guideline for the credit instead of the 48 states'.
15 changes: 7 additions & 8 deletions modal-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
#
# Captured with `pip freeze` from the live aca-calc-api container on 2026-11-03,
# minus the 14 packages that Modal's 2025.06 image builder installs at the same
# versions. Deploying from this file reproduces the calculator that has served
# since May 2026 (policyengine-us 1.691.3), so a redeploy changes only the code.
# versions. Since then policyengine-us has moved from 1.691.3 to 2.115.0
# (2026-11-09), the first release with the published 2027 premiums
# (policyengine-us #10682), with the policyengine-core and spm-calculator
# versions it requires; every other pin is unchanged.
#
# To upgrade a package, change its pin here, run the tests against the new set,
# and compare /api/calculate results before deploying.
Expand Down Expand Up @@ -58,11 +60,8 @@ parso==0.8.7
pexpect==4.9.0
plotly==5.24.1
pluggy==1.6.0
policyengine-core==3.26.4
# PyPI no longer serves policyengine-us 1.691.3 (of the 1.691 series it keeps
# only 1.691.1), so this builds it from its release commit. The build matches
# the live container's installed files hash for hash.
policyengine-us @ https://github.com/PolicyEngine/policyengine-us/archive/2cb12a24dad22d85a82549f6d164b9d5fbadbe5e.tar.gz
policyengine-core==3.34.9
policyengine-us==2.115.0
prompt_toolkit==3.0.52
psutil==6.1.1
ptyprocess==0.7.0
Expand All @@ -81,7 +80,7 @@ shellingham==1.5.4
six==1.17.0
sniffio==1.3.1
sortedcontainers==2.4.0
spm-calculator==0.3.1
spm-calculator==1.1.0
stack-data==0.6.3
standard-imghdr==3.13.0
starlette==1.0.0
Expand Down
26 changes: 21 additions & 5 deletions modal_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@

import modal

app = modal.App("aca-calc-api")
# The live app is aca-calc-api. A preview deploy sets ACA_API_APP_NAME, say
# aca-calc-api-preview, to run a branch's backend beside it with caches of its
# own; the image carries the name, so its containers open the same caches.
APP_NAME = os.environ.get("ACA_API_APP_NAME", "aca-calc-api")
CACHE_SUFFIX = APP_NAME.removeprefix("aca-calc-api")

app = modal.App(APP_NAME)

# Persistent cache for calculation results (7-day TTL handled in application)
calculation_cache = modal.Dict.from_name("aca-calc-cache", create_if_missing=True)
calculation_cache = modal.Dict.from_name(f"aca-calc-cache{CACHE_SUFFIX}", create_if_missing=True)

# Persistent cache for AI explanations
explanation_cache = modal.Dict.from_name("aca-explain-cache", create_if_missing=True)
explanation_cache = modal.Dict.from_name(
f"aca-explain-cache{CACHE_SUFFIX}", create_if_missing=True
)

# Exact package versions from the live container, so a deploy changes only this
# repo's code. Read the notes in the file before changing a pin.
Expand All @@ -25,15 +33,23 @@
.add_local_dir("src/aca_api", "/root/src/aca_api", copy=True)
# The commit a CI deploy came from. The API reports it, so the smoke test
# can tell this deploy's containers from the previous version's.
.env({"PYTHONPATH": "/root", "ACA_API_COMMIT": os.environ.get("ACA_API_COMMIT", "")})
.env(
{
"PYTHONPATH": "/root",
"ACA_API_COMMIT": os.environ.get("ACA_API_COMMIT", ""),
"ACA_API_APP_NAME": APP_NAME,
}
)
)


@app.function(
image=image,
secrets=[modal.Secret.from_name("anthropic-api-key")],
timeout=300,
memory=2048,
# policyengine-us 2.x needs about 0.9 GB to load and 2.4-2.9 GB once a
# request has run its scenarios' reforms.
memory=4096,
)
@modal.asgi_app()
def fastapi_app():
Expand Down
25 changes: 20 additions & 5 deletions scripts/smoke_test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
Usage: python scripts/smoke_test_api.py API_URL [--explain] [--commit SHA [--wait SECONDS]]

Checks /api/health, then both calculator endpoints: /api/calculate-stream,
which the calculator page calls, and /api/calculate, its fallback. Both
requests set skip_cache, so the deployed code computes each answer instead of
returning one from the 7-day calculation cache, and the stream check confirms
that it did. With --explain it checks /api/health and then /api/explain
which the calculator page calls, and /api/calculate, its fallback, and then a
2027 calculation with 2026 alongside, as the calculator page asks. The
requests set skip_cache, so the deployed code computes
each answer instead of returning one from the 7-day calculation cache, and the
stream check confirms that it did. With --explain it checks /api/health and then /api/explain
instead of the calculator: it requests a fixed household's AI narrative, which
calls the Anthropic API unless the answer is already in the 7-day explanation
cache.
Expand Down Expand Up @@ -170,6 +171,20 @@ def check_calculate(base):
check_result("/api/calculate", call(f"{base}/api/calculate", FRESH))


def check_calculate_2027(base):
# Requests without a year get 2026; the calculator page asks for 2027, with
# 2026 current law for the same household alongside. The credit measures
# income against the prior year's poverty guideline.
result = call(f"{base}/api/calculate", {**FRESH, "year": 2027, "show_prior_year": True})
assert result.get("year") == 2027, f"asked for 2027, got {result.get('year')}"
assert result.get("fpl_year") == 2026, (
f"2027 credits use the 2026 guideline, got {result.get('fpl_year')}"
)
assert max(result.get("ptc_prior_year") or [0]) > 0, "no 2026 credits came back"
assert (result.get("fpl_prior_year") or 0) > 0, "no 2026 guideline came back"
check_result("/api/calculate (2027)", result)


def check_explain(base):
# A fixed household, so after the first deploy the answer usually comes
# from the explanation cache rather than a new Anthropic API call.
Expand Down Expand Up @@ -234,7 +249,7 @@ def main():
if args.explain:
checks = [check_health, check_explain]
else:
checks = [check_health, check_calculate_stream, check_calculate]
checks = [check_health, check_calculate_stream, check_calculate, check_calculate_2027]
for check in checks:
from_this_deploy(check, base)

Expand Down
Loading
Loading