Repository navigation
Remove the API v2 app's plain worker functions and the callers' fallbacks to them - #1159
Merged
Merged
Conversation
Failing tests for 1.5 · 14. The API v2 app (src/modal/v2_app.py) defines no plain run_single_simulation_us, run_single_simulation_uk or run_single_simulation_segment_us function. The entry service, the coordinator's child spawns and the segment fan-out start those workers only through their Modal classes: an app without the class fails the spawn with Modal's not-found error, and no function is looked up. Tests that called the plain functions now call the class methods, and the Modal options the capacity, timeout and wait-window tests read come from the worker classes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1.5 · 14. The API v2 app defines its US and UK single-simulation workers and its US segment worker only as methods of SimulationWorkerUS, SimulationWorkerUK and SimulationSegmentWorkerUS. The plain functions of the same names, kept since 1.5 · 9 for callers on older code, are gone: the Cloud Run entrypoint revisions kept for rollback in prod and staging were built from 1.5 · 9's release and start the workers through the classes. The entry service's standalone simulation runs and cliff calculations, the coordinator's child spawns and the segment fan-out start the workers only through their classes, with no fallback to a plain function, as the user decided. Modal looks a class up when its method first spawns, so an app without the class fails that spawn with NotFoundError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1 found no behaviour bugs, and two smaller gaps: - The entry service's branch that starts a simulation callable with no worker class as a plain function had lost its only test. A new test covers it for standalone runs and cliff calculations; it passes on the existing code, which it only covers. - Stage12SegmentRunner's docstring still said its constructor looks the segment worker up. Modal now looks the class up when run() spawns the first segment, and the docstring says so. The test stand-ins for Modal classes no longer define hydrate, which no caller uses now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…worker removal branch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #1158
Same-Repository Draft PR Check
PolicyEngine/policyengine-sim-api, not a personal fork.Changelog
changelog.d/v2-remove-plain-worker-functions.removed.md, whose type is removed.Summary
#1142 made the API v2 app's simulation workers methods of Modal classes restored from memory snapshots, and kept plain functions of the same names for callers on older code. This PR removes those functions, and the callers' fallbacks to them.
src/modal/v2_app.pySimulationWorkerUS.run_single_simulation_us,SimulationWorkerUK.run_single_simulation_uk,SimulationSegmentWorkerUS.run_single_simulation_segment_us, plus plain@app.functions of the same three nameseconomy_workers.py_spawn_simulation_worker)NotFoundError, spawn the plain functionstage12_runtime/worker_lookup.pydeployed_worker)NotFoundError, use the plain functionworker_class_namereturns None) is still started as a plain function, as before.modal.Cls.from_namewhen its method first spawns (Modal 1.5.5 and 1.6.4,_Obj.__getattr__inmodal/cls.py). So the explicithydratestep existed only to catchNotFoundErrorfor the fallback, and goes with it, as it did in the gateway in Remove the plain worker functions and the gateway's fallback to them, and refuse rollbacks to apps without the worker class #1131. A missing class now raisesNotFoundErrorfrom the spawn. The entry service, the coordinator and the fan-out record that failure where they recorded other spawn failures.stage12_simulation_workerscontract module,v2_worker_resources.py,fanout.pyandeconomy_workers.pydocstrings, and the observability skill (the plain functions no longer reportcontainer_start=no_snapshot).Why removal is safe now (read-only checks, 30 Nov)
policyengine-simulation-entry-00369-dam(prod) andpolicyengine-simulation-entry-staging-00272-her(staging). Both were built by deploy run 46060714364 from0d455f4d, Restore the v2 simulation workers from Modal memory snapshots with their country's models loaded #1142's release commit, and spawn the workers through the classes. Run 46072959989 (6e4e2780) promoted00372-fosand00275-cid, and its revision cleanup job kept those two and deleted the last revisions from before Restore the v2 simulation workers from Modal memory snapshots with their country's models loaded #1142.stagingandmain. In both, the API v2 version manifest's default is 6.20.0, whose apppolicyengine-simulation-v2-py6-20-0has all three classes (v20 inmainfrom6e4e278; v22 instagingfromd95a520). The plain functions had no queued or running inputs (Function.get_current_stats()).mainat 21:07 UTC on 27 Nov, so every call running older code ended by 23:02 UTC that day.policyengine-apimaster) looks none of the three names up; it storessimulation_callableonly as comparison-run data. No workflow,.github/scriptsfile, smoke app or other PolicyEngine repository names them.What this gives up (the project owner's decision)
Without the fallbacks, an API v2 app deployed before #1142 can't run standalone simulation runs or cliff calculations, and a coordinator call running newer code can't start its children there. That applies to:
update_v2_version_manifest --restore-planor--force-default). Deploys move the default only to a newer version, andsimulation-rollback.ymlnever changes it;No new check refuses either case.
Environment variables
The change reads and declares no environment variable. The removed functions took their image, secrets and resources from the same option dictionaries the classes still use, so the classes' Modal secret attachments are unchanged.
Merge order
SEGMENT_WORKER_RESOURCESinv2_worker_resources.py. This PR changes only that module's docstring. Least rework: merge this PR first; 1.5 · 13 then sets the resources on the class alone. If 1.5 · 13 merges first, this PR's rebase also drops any assertion it adds on the plain segment function's options.Testing
Red-green:
df6be228adds and changes the tests, and they fail on the code before the removal, 6 in the executor and 2 in the entry service:e95b4b5emakes them pass.Tests that called the plain functions now call the class methods; the capacity, timeout and wait-window tests read the classes' Modal options.
Ran only the added and changed tests, by node ID: 92 in the executor and 8 in the entry service, all passing.
Ruff format and lint on every changed file, Pyright for the executor, the entry service and the contract library (
python3 -m scripts.rules pyright), andscripts/run_quality_guards.py(file length included): all pass.One round of adversarial review found no behaviour bugs. Its two smaller findings, an untested entry-service branch for a callable with no class and a stale fan-out docstring, are fixed in
b339e098.Not run: the full test suites, and anything against Modal or Cloud Run beyond the read-only checks above.
🤖 Generated with Claude Code