Skip to content

Remove the API v2 app's plain worker functions and the callers' fallbacks to them - #1159

Merged
anth-volk merged 4 commits into
mainfrom
claude/v2-remove-plain-worker-functions-df5609
Dec 1, 2026
Merged

anth-volk merged 4 commits into
mainfrom
claude/v2-remove-plain-worker-functions-df5609

Conversation

@anth-volk

Copy link
Copy Markdown
Contributor

Fixes #1158

Same-Repository Draft PR Check

  • This PR is a draft.
  • This PR is from a branch in PolicyEngine/policyengine-sim-api, not a personal fork.

Changelog

  • This PR adds a changelog fragment, 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.

Where Before After
src/modal/v2_app.py SimulationWorkerUS.run_single_simulation_us, SimulationWorkerUK.run_single_simulation_uk, SimulationSegmentWorkerUS.run_single_simulation_segment_us, plus plain @app.functions of the same three names the class methods only; the file goes from 797 to 751 lines
Entry service, standalone simulation runs and cliff calculations (economy_workers.py _spawn_simulation_worker) hydrate the class; on NotFoundError, spawn the plain function spawn the class method; an app without the class fails the spawn
Coordinator child spawns and segment fan-out (stage12_runtime/worker_lookup.py deployed_worker) hydrate the class; on NotFoundError, use the plain function return the class method; an app without the class fails the first spawn
  • A name the contract maps to no class (worker_class_name returns None) is still started as a plain function, as before.
  • Modal looks up a class from modal.Cls.from_name when its method first spawns (Modal 1.5.5 and 1.6.4, _Obj.__getattr__ in modal/cls.py). So the explicit hydrate step existed only to catch NotFoundError for 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 raises NotFoundError from the spawn. The entry service, the coordinator and the fan-out record that failure where they recorded other spawn failures.
  • Text updated: the stage12_simulation_workers contract module, v2_worker_resources.py, fanout.py and economy_workers.py docstrings, and the observability skill (the plain functions no longer report container_start=no_snapshot).

Why removal is safe now (read-only checks, 30 Nov)

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:

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

  • 1.5 · 12's Run one warm-up calculation in the v2 US workers' snapshot hook #1147 has merged, and this branch is rebased on it.
  • 1.5 · 13 (segment worker resources, no PR yet) changes SEGMENT_WORKER_RESOURCES in v2_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: df6be228 adds and changes the tests, and they fail on the code before the removal, 6 in the executor and 2 in the entry service:

    • the API v2 app declares no plain worker function;
    • the coordinator and the fan-out fail the spawn, with no function lookup, when the app has no class;
    • the entry service does the same for standalone runs and cliff calculations;
    • the wait window covers only the classes.

    e95b4b5e makes 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), and scripts/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

anth-volk and others added 4 commits December 1, 2026 01:56
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>
@anth-volk
anth-volk marked this pull request as ready for review December 1, 2026 00:22
@anth-volk
anth-volk merged commit 0665a1f into main Dec 1, 2026
28 checks passed
@anth-volk
anth-volk deleted the claude/v2-remove-plain-worker-functions-df5609 branch December 1, 2026 01:01
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.

Remove the API v2 app's plain worker functions and the callers' fallbacks to them

1 participant