Skip to content

Commit 4fb9977

Browse files
authored
Deploy Modal worker for API v4 migration (#466)
1 parent 3cda207 commit 4fb9977

5 files changed

Lines changed: 54 additions & 18 deletions

File tree

projects/policyengine-api-simulation/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ dependencies = [
1818
"policyengine-fastapi",
1919
"policyengine==0.13.0",
2020
"policyengine-core>=3.23.5",
21-
"policyengine-uk>=2.22.8",
22-
"policyengine-us>=1.370.2",
21+
"policyengine-uk==2.88.0",
22+
"policyengine-us==1.653.3",
2323
"tables>=3.10.2",
2424
"modal>=0.73.0",
2525
"logfire>=3.0.0",

projects/policyengine-api-simulation/src/modal/gateway/endpoints.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def _build_policyengine_bundle(
7373
resolved_dataset = None
7474
return PolicyEngineBundle(
7575
model_version=resolved_version,
76+
data_version=payload.get("data_version"),
7677
dataset=resolved_dataset,
7778
)
7879

projects/policyengine-api-simulation/src/modal/gateway/models.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
MAX_GATEWAY_REQUEST_BYTES = 262_144
2121

2222

23-
INTERNAL_PASSTHROUGH_FIELDS = frozenset({"_metadata"})
23+
INTERNAL_PASSTHROUGH_FIELDS = frozenset({"_metadata", "_runtime_bundle"})
2424

2525

2626
def _move_internal_telemetry_alias(value):
@@ -35,12 +35,11 @@ def _move_internal_telemetry_alias(value):
3535
def _strip_internal_passthrough_fields(value):
3636
"""Drop internal-only fields the gateway adds to payloads in flight.
3737
38-
When the parent batch entrypoint forwards a payload to the worker we
39-
attach ``_metadata`` describing resolved routing. That enrichment is
40-
consumed by :mod:`src.modal.budget_window_context`, not by the request
41-
model itself. We strip it before strict validation so ``extra="forbid"``
42-
keeps catching unknown fields from *callers* without breaking the
43-
internal round-trip.
38+
Parent batch entrypoints attach ``_metadata`` describing resolved routing,
39+
and the v4 API attaches ``_runtime_bundle`` describing provenance that the
40+
gateway returns separately. Strip those fields before strict validation so
41+
``extra="forbid"`` keeps catching unknown caller fields without breaking
42+
internal round-trips.
4443
"""
4544

4645
if not isinstance(value, dict):

projects/policyengine-api-simulation/tests/gateway/test_endpoints.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,40 @@ def test__given_submission_with_uk_alias_data__then_bundle_dataset_is_versioned_
311311
== "hf://policyengine/policyengine-uk-data-private/enhanced_frs_2023_24.h5@1.40.3"
312312
)
313313

314+
def test__given_submission_with_runtime_bundle__then_accepts_internal_provenance(
315+
self, mock_modal, client: TestClient
316+
):
317+
mock_modal["dicts"]["simulation-api-us-versions"] = {
318+
"latest": "1.500.0",
319+
"1.500.0": "policyengine-simulation-us1-500-0-uk2-66-0",
320+
}
321+
322+
request_body = {
323+
"country": "us",
324+
"scope": "macro",
325+
"reform": {},
326+
"data": "enhanced_cps_2024",
327+
"data_version": "1.78.2",
328+
"_runtime_bundle": {
329+
"model_version": "1.500.0",
330+
"data_version": "1.78.2",
331+
},
332+
"_metadata": {"process_id": "process-123"},
333+
}
334+
335+
response = client.post("/simulate/economy/comparison", json=request_body)
336+
337+
assert response.status_code == 200
338+
data = response.json()
339+
assert data["policyengine_bundle"] == {
340+
"model_version": "1.500.0",
341+
"data_version": "1.78.2",
342+
"dataset": "hf://policyengine/policyengine-us-data/enhanced_cps_2024.h5@1.77.0",
343+
}
344+
assert mock_modal["func"].last_payload["data_version"] == "1.78.2"
345+
assert "_runtime_bundle" not in mock_modal["func"].last_payload
346+
assert "_metadata" not in mock_modal["func"].last_payload
347+
314348
def test__given_submission_with_unknown_alias_data__then_bundle_dataset_is_preserved(
315349
self, mock_modal, client: TestClient
316350
):

projects/policyengine-api-simulation/uv.lock

Lines changed: 11 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)