Repository navigation
Remove the plain worker functions and the gateway's fallback to them, and refuse rollbacks to apps without the worker class - #1131
Merged
Conversation
The versioned app still defines plain run_simulation and run_simulation_segment functions beside the worker classes, so this test fails until they are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#1118 kept them beside the SimulationWorker and SimulationSegmentWorker classes for callers on the code from before the classes: the old gateway while a deploy replaced the routed app in place, and runs started before it. In Modal main and staging, the routed app and the gateway now both run code from 544ff62, which contains #1118, and no container from before those deploys is left. The gateway keeps its fallback to the run_simulation function of apps deployed before the classes. The tests that called the plain functions go with them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Removing the plain run_simulation_segment function took with it the only test that a segment call returns its result and records a successful operation. That code still runs as SimulationSegmentWorker.run_simulation_segment, so the test now calls the class method. It fails when the method drops its result. Also check only that the two worker names are not plain functions, so an unrelated new function doesn't fail the test, and say in the changelog that only apps deployed from this release lose the functions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Apps deployed after the worker classes but before this change define the plain run_simulation function too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
…orker-functions-c67982 # Conflicts: # projects/policyengine-simulation-executor/src/modal/app.py # projects/policyengine-simulation-executor/tests/test_modal_bundle_image.py
#1124 tested that the plain run_simulation and run_simulation_segment functions report no_snapshot, and its observability skill section named them. With both functions removed, those four test cases fail with AttributeError. The two tests now check run_budget_window_batch, the app's only plain function, and the skill names the worker class methods instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r class The gateway falls back to the plain run_simulation function of an app that has no SimulationWorker class, so this test fails until the fallback is removed. The test fixture now raises the class lookup error when a method of a missing class is spawned, where Modal resolves the lazy handle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The gateway no longer falls back to the plain run_simulation function of apps deployed before the worker classes. API v1 pins .py 6.20.0, whose app has the class, and no older app has logged a call since API v1 moved to it on 16 Nov. A request routed to an older app, pinned or after a rollback of latest, now fails with Modal's NotFoundError, as one routed to an app that isn't deployed does. FUNCTION_FORM_SIMULATION_WORKER, the test fixture's spawn_error option, and the hydrate methods of the test class handles go with the fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…orker-functions-c67982
The gateway still spawns a budget-window batch on an app from before the worker classes, and that app spawns its yearly simulations itself. The rollback workflow and the executor README now say that a rollback of latest to a release before 6.20.0 fails every unpinned comparison request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er class The gateway now runs comparison requests only through an app's SimulationWorker class, which apps deployed before .py 6.20.0 don't define. Restoring latest to such an app, undoing a deployment's plans back to one, or recovering a pending publication onto one would fail every unpinned comparison request. These tests fail until the routing publisher checks the restored app first. The routing tests' fake Modal gains a Cls lookup in which every app defines the class unless a test says otherwise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The gateway runs comparison requests only through an app's SimulationWorker class, which apps deployed before .py 6.20.0 don't define. Restoring latest with --restore-latest, and undoing plans with --restore-plan or --finalize-publication, now look the class up in the app each restored state routes latest to, and refuse before writing anything when Modal finds none. That covers all three ways of the rollback workflow and the deploy workflow's own restores. The plan restore now works out every state it would write before writing the first, so a refusal never leaves routing half restored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…orker-functions-c67982
…he class Undoing an unfinished publication (the deploy workflow's restore after a failed check, or resolve_pending_publication) must put back what it replaced: refusing leaves the publication pending, and every later routing write refuses while one is. A restore that leaves latest on the app it is on changes no request's routing, so it needs no class either. These tests fail until the check is narrowed. A test also checks that a Modal error other than NotFoundError stops the rollback unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Undoing an unfinished publication now always puts back what it replaced. Refusing it left the publication pending, and every later routing write, rollbacks included, refuses while one is. A restore is checked only when it moves latest.policyengine to a different app: one that leaves latest where it is changes where no request goes. The refusal message now says to roll back to a release from .py 6.20.0 on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A deployment-run rollback can pass a run's finished plans together with its rerun's pending one. Only the pending plan's own undo may skip the worker class check, so this test fails until the exemption is limited to it. A test also checks that a failed class lookup stops a plan restore unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A deployment-run rollback can pass a run's finished plans together with its rerun's pending one, and the check was skipped for all of them. Now only the pending plan's own undo skips it, and the finished plans are checked. Refusing them leaves nothing stuck: resolve_pending_publication still undoes the pending plan alone. The README, the rollback workflow's header and the changelog now say which restores are checked, and that undoing a pending plan can put latest back on an app from before 6.20.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In the usual deployment-run layout, a completed routes plan is followed by a pending latest plan. Undoing the routes plan leaves latest where undoing the latest plan put it, so the rollback must not look the class up; the check compared it with the live state instead, and refused. The test of finished plans among a pending one now also expects the refusal to name resolve_pending_publication. Both fail until the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A plan's undo writes its starting state over its published state, so that is what decides whether it moves latest. Comparing with the live state from before the restore refused the usual deployment-run rollback: a finished routes plan, then a pending latest plan whose undo is exempt, where the routes plan's undo leaves latest where it is. The refusal now also says to undo a pending publication first with resolve_pending_publication. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
marked this pull request as ready for review
November 26, 2026 19:51
anth-volk
added a commit
that referenced
this pull request
Nov 26, 2026
…anch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
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 #1130
What changes
#1118 made the simulation workers the Modal classes
SimulationWorkerandSimulationSegmentWorker, restored from memory snapshots. It also kept plainrun_simulationandrun_simulation_segmentfunctions, with no snapshots and running the same code, for callers still on the code from before the classes. Those callers were the old gateway, while a deploy replaced the routed app in place, and runs started before the deploy. The gateway also fell back to the plainrun_simulationfunction of apps deployed before #1118.This PR removes all of that.
Versioned app (
projects/policyengine-simulation-executor/src/modal/app.py):_run_simulationand_run_simulation_segmentdocstrings;test_modal_bundle_image.py, and the test of the plainrun_simulation's job records intest_job_progress.py, which a class test already repeats;run_simulationandrun_simulation_segmentcases of the two plain-function tests intest_modal_container_start.py, and the three passages ofdocs/engineering/skills/observability.mdthat named the plain functions. The tests now checkrun_budget_window_batch, the app's only plain function.The plain
run_simulation_segment's test was the only test that a segment call returns its result and records a successful operation. That code still runs asSimulationSegmentWorker.run_simulation_segment, sotest_a_segment_returns_its_result_and_records_successnow calls the class method.Gateway:
_spawn_annual_simulationinjob_creation_routes.pyspawns only through theSimulationWorkerclass. It no longer hydrates the class first or falls back to an app's plainrun_simulationfunction.FUNCTION_FORM_SIMULATION_WORKERis removed from the contract library'ssimulation_workers.py.function_form_appsis nowapps_without_worker_class. A method of a missing class raisesNotFoundErrorwhen spawned, where Modal resolves the lazy handle. The fixture'sspawn_erroroption and itshydratemethod, used only by the fallback and its tests, are removed.test__given_an_app_with_no_worker_class__then_no_function_is_spawned.Routing restores (
projects/policyengine-simulation-executor/src/modal/routing_publisher/):require_latest_app_defines_worker_class(stores.py) looks up theSimulationWorkerclass in the app that a restored state'slatest.policyengineroutes to, in the same Modal environment.--restore-latest, and the plan's own published state for each plan undone.NotFoundError(for a missing class or a missing app), it raisesLatestAppWithoutWorkerClassError, aValueErrorsubclass, and routing is unchanged. The message says to roll back to a release from .py 6.20.0 on, after undoing any pending publication withresolve_pending_publication.restore_routing_state(--restore-latest, the rollback'spolicyengine_versionway) checks before writing.restore_routing_plans(--restore-plan, the rollback'sdeploy_run_idway) checks every state it would write back._restore_live_plansnow works out every plan it will undo first, checks, and only then writes, so a refusal never leaves routing half restored. When nothing is refused, it writes the same states in the same order as before.resolve_pending_publication, the deploy workflow's restores of its own unfinished publication, and the pending plan among adeploy_run_id's plans.latestback on an app from before 6.20.0, iflatestwas on one before that deployment.Unchanged: the stage names
run_simulationandrun_simulation_segmentand themodal_function_nameattribute, which the class methods use; and what #1124 and #1126 added.What the gateway change gives up: running comparison requests on apps deployed before #1118, which is every .py release before 6.20.0.
NotFoundError, and the client gets a 500. That's how a request routed to an app that isn't deployed fails today.latestto one, and an API v1 deploy of a commit from before 16 Nov, which pins an older .py version.run_budget_window_batchfunction, which spawns its own yearly simulations.policyengine_versionordeploy_run_idrollback that would movelatestto one of them is now refused before routing changes (see routing restores above). The rollback's own checks (/health,/ready,/versions) wouldn't have caught it.Why this is safe now
Checked read-only on 2026-11-25 from about 21:30 UTC, and again on 2026-11-26 from about 14:10 UTC:
latest= .py 6.20.0)mainpolicyengine-simulation-py6-20-0v9, deployed 13:48 UTC on 26 Nov from44dd610; v8 15:10 UTC on 25 Nov from544ff62544ff62stagingpolicyengine-simulation-py6-20-0v9, deployed 13:02 UTC on 26 Nov from44dd610; v8 14:24 UTC on 25 Nov from544ff62544ff62544ff62and44dd610contain Restore the simulation workers from Modal memory snapshots with the country models loaded #1118's merge. The deploy workflow deploys only to these two environments.py6-20-0, which has the classes.main(py6-17-1,py6-16-0,py6-12-1,py6-12-0,py6-11-1,py6-10-0andpy6-7-5) has written a log line in the 7 days before 14:11 UTC on 26 Nov (modal app logs <app> --env main --since 7d; the same query onpy6-20-0returned 5,783 lines).py6-17-1's last log lines are from 16:01 UTC on 16 Nov, about 20 minutes before API v1's pin moved to 6.20.0.Cls.from_name.v2_app.pyfunctions..github/scriptslook up neither name.run_simulation_segmentonly in this repository.simulation-rollback.ymlrewrites the routing state and Cloud Run traffic, and never deploys a gateway. A rollback oflatestto 6.20.0 still works.Environment variables
This change reads and declares none. The deleted functions attached the
gcp_secretandhf_secretModal secrets, which stay attached to both worker classes andrun_budget_window_batch.The routing restores' new class lookup uses the Modal client's credentials,
MODAL_TOKEN_IDandMODAL_TOKEN_SECRET(GitHub Actions secrets), and the--environmentargument fromMODAL_ENVIRONMENT. Every step that reaches it already passes all three, because it already reads the routing Modal Dict:simulation-rollback.yml: "Restore Modal routing" and "Resolve the unfinished routing publication";simulation-deploy.reusable.yml: "Put latest back after a failed step" and "Finalize the routing publication".Checks run
tests/test_modal_bundle_image.py::test_the_simulation_workers_are_not_also_plain_functionsfailed on8fcb443cand passes after the removal.AttributeErrorafter the merge ofmain. The two tests pass onrun_budget_window_batch.test__given_an_app_with_no_worker_class__then_no_function_is_spawnedfailed on13101fef: the request returned 200 after spawning the old app's function. It passes afterfed9421b.3a76c06d, either with no class lookup made or with no refusal raised, and pass after91cd1d81:tests/version_registry/test_routing_rollback.py::test_restoring_latest_checks_that_its_app_defines_the_worker_class::test_restoring_latest_refuses_an_app_without_the_worker_class::test_undoing_plans_checks_the_app_each_restored_state_routes_latest_to::test_undoing_plans_writes_nothing_if_any_restored_state_has_no_worker_class5eda3860, because the first version refused them, and pass after525c04f8, which narrows the rule:test_routing_rollback.py::test_restoring_latest_to_the_release_it_is_on_needs_no_worker_class::test_undoing_a_plan_that_leaves_latest_where_it_is_needs_no_worker_class::test_undoing_an_unfinished_publication_puts_back_what_it_replacedtest_routing_finalization.py::test_operator_recovery_puts_back_what_the_publication_replaced_without_the_class, which replaces the first version's test of the oppositetest_routing_rollback.py::test_finished_plans_among_kept_plans_are_still_checkedfailed on9c7218c6, because the check was skipped for every plan, and passes after39397277. It was renamed fromtest_only_the_unfinished_publication_among_kept_plans_skips_the_checkin8203cc3f, which also made it require the refusal to nameresolve_pending_publication.test_routing_rollback.py::test_the_pending_plan_among_kept_plans_is_undone_without_the_checkfailed on8203cc3f: the routes plan's undo was refused. It passes after60f0c1ec.test_routing_rollback.py::test_a_failed_worker_class_lookup_stops_the_rollback_and_writes_nothingand::test_a_failed_worker_class_lookup_stops_undoing_plans_and_writes_nothingpass. They check that a Modal error other thanNotFoundErrorpropagates.::test_undoing_a_plan_checks_the_app_its_starting_state_routes_latest_towas renamed fromtest_undoing_plans_checks_the_app_each_restored_state_routes_latest_to.test_routing_rollback.py::test_publish_then_restore_returns_exactly_the_previous_state, whose fake Modal gained the class lookup, passes.tests/test_modal_bundle_image.py::test_the_simulation_workers_are_not_also_plain_functions,::test_simulation_workers_are_classes_restored_from_memory_snapshotsand::test_simulation_workers_use_the_contract_namestests/test_job_progress.py::test_a_segment_returns_its_result_and_records_success, which fails ifSimulationSegmentWorker.run_simulation_segmentdrops its result (checked by deleting thatreturnlocally, without committing)tests/test_modal_container_start.py::test_a_plain_function_call_reports_a_container_started_without_a_snapshotand::test_a_plain_function_sets_both_attributes_before_its_job_runstests/test_canonical_spm.py::test_gateway_submission_uses_registry_capability_before_spawntests/test_simulation_submission.py::TestSubmitSimulationEndpoint::test__given_an_app_with_no_worker_class__then_no_function_is_spawnedmainwith Report in worker telemetry whether each call's container was restored from a memory snapshot #1124 and Request 1 CPU and 10 GiB for the segment workers #1126.latestwere refused. Both are fixed by the narrower rule above. The narrowed rule's round found that a pending plan among adeploy_run_id's plans exempted every plan from the check; now only the pending plan's own undo is exempt. The last round found that each plan's undo was compared with the live state from before the restore, rather than with the plan's own published state. That refused the usual layout: a completed routes plan, then a pending latest plan. Each undo is now compared with the state it writes over. No further round ran; three is the limit.NotFoundErrorwhenspawnresolves the handle, before any job metadata is written. Its wording findings are fixed: the changelog and the contract docstring now limit the failure to comparison requests, and the rollback documentation describes it.python -m scripts.rules guardand.github/scripts/check-changelog-fragment.shall pass.run_simulationofpy6-20-0before 15:21 UTC on 25 Nov, once the functions are removed. Those calls ended within an hour of being made.🤖 Generated with Claude Code