Repository navigation
Conversation
The v2 workers need the restore detection and call counter the run_simulation app's workers have. These tests cover that logic as a module both apps can import: each container_start value, the call counter, and a failure to set the attributes raising nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ContainerCalls holds the restore detection and call counter that src/modal/app.py's workers use today: the snapshot hook records the container's MODAL_TASK_ID and whether MODAL_ENABLE_SNAP_RESTORE is 1, and each call compares the recorded ID with the current one. Its set_call_attributes sets container_start and container_call_number on the call's operation and never raises, so the v2 workers can call it once per call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each call of SimulationWorkerUS, SimulationWorkerUK and SimulationSegmentWorkerUS, and of the plain functions kept for callers on older code, should carry container_start and container_call_number on its operation record and span, as the run_simulation app's workers do. The tests cover the three values, the call counter, failed and preempted calls, and failures to read or set the attributes leaving the result unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The v2 workers' snapshot hook records whether Modal snapshots the container and its MODAL_TASK_ID, and each call of SimulationWorkerUS, SimulationWorkerUK and SimulationSegmentWorkerUS, and of the plain functions kept for callers on older code, sets container_start and container_call_number on its operation as it opens. The run_simulation app's workers now use the same shared module, with no change in what they report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The observability skill's section now covers the v2 app's simulation workers and their plain functions, the services their records come from, and the shared ContainerCalls module, and says the v2 workers' attribute hasn't been checked on Modal yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each call of the three v2 simulation workers, through its class method or its plain function, should configure its telemetry with the .py version as service version and name the Modal app in its operation's modal_app_name, as the run_simulation app's workers do, while keeping the service names existing queries select by. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each call of the three v2 simulation workers configures its telemetry with the bundle's policyengine.py version as service version, in place of the observability package's fallback 0.1.0, and its operation's modal_app_name names the v2 app, as the run_simulation app's workers do. The service names stay the workers', which existing queries select by. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 2 found the test compared the version with the same expression the code passes. It now compares it with the installed policyengine distribution's version. The service.version change gets its own "changed" changelog fragment, since it alters a value existing records already carry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
force-pushed
the
v2-restore-telemetry
branch
from
November 27, 2026 19:34
2ac87ff to
5eb3cba
Compare
This branch has not been deployed
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 #1139
Same-Repository Draft PR Check
PolicyEngine/policyengine-sim-api, not a personal fork.Changelog
changelog.d/1139.added.md(type added) andchangelog.d/1139.changed.md(type changed).Builds on #1142
#1142 made the v2 simulation workers Modal classes with memory snapshots (
SimulationWorkerUS,SimulationWorkerUK,SimulationSegmentWorkerUS) and kept plain functions of the same names. This PR was stacked on it; #1142 has merged, so this PR now targetsmain, withmainmerged in.Summary
Each call of the three v2 simulation workers now reports, as the run_simulation app's workers already do:
container_startoperation.completedrecord and the operation's spanrestored_from_snapshot,took_snapshot(Modal took the snapshot from this container) orno_snapshot(plain functions, and class containers Modal started without snapshots)container_call_numbermodal_app_namepolicyengine-simulation-v2-py6-20-0service.version0.1.0This covers the class methods and the plain functions, since both run the same
_run_single_*body. The service names (policyengine-stage12-us-worker,-uk-worker,-us-segment-worker) are unchanged, so existing queries still select these records. The coordinator and household functions are unchanged.Shared with the run_simulation app
The restore detection and call counter move from
src/modal/app.pyintosrc/modal/container_calls.py(ContainerStart,ContainerCalls), which both apps import. Each app module keeps oneContainerCalls, since each Modal container serves one worker.ContainerCalls.set_call_attributes(runtime)sets both attributes on the open operation and never raises.app.py's workers report exactly what they did before.How a call tells the container starts apart (Modal 1.6.4)
@modal.enter(snap=True)hook,load_country_models, now records the container'sMODAL_TASK_IDand whetherMODAL_ENABLE_SNAP_RESTOREis1before it loads the models. Modal takes a snapshot only when that flag is1(maybe_snapshotinmodal/_runtime/user_code_imports.py).memory_restore(modal/_runtime/task_lifecycle_manager.py) sets itsMODAL_TASK_IDto its own task ID.restored_from_snapshot; they match,took_snapshot; the flag wasn't1or the hook never ran,no_snapshot. The recorded ID is never reported.Environment variables
MODAL_TASK_IDenvor secret sets it. On restore, Modal 1.6.4'smemory_restorerewrites it from the restore state'stask_id.service.instance.idalready reads it per call.MODAL_ENABLE_SNAP_RESTOREenvor secret sets it.service.versionreads no environment variable: it isRESOLVED_BUNDLE.bundle.policyengine_version, read when the module is imported, from the installed policyengine.py package's bundle manifest.Unverified until this deploys: Modal documents neither variable. The run_simulation app's worker classes were checked on Modal
testingon 2026-11-25 (every restored container reported its ownMODAL_TASK_ID), but the v2 classes haven't been. After deploy, comparecontainer_startwith Modal's container logs: "Restoring Function from memory snapshot." and "Creating CPU memory snapshot for Function.", matching a log line's container ID with the task ID at the start of a record'sservice.instance.id.Metrics: neither new attribute reaches metric attributes.
service.versionis a resource attribute, so it now changes with each .py release, as it already does for the run_simulation app. Whether the collector, outside this repository, turns resource attributes into metric labels is unverified.Size
src/modal/v2_app.pyis at 800 lines, the mostsim.quality.python-file-lengthallows. Any further line added to it in this stack needs the file split first.Testing
Tests were committed failing before each change.
tests/test_container_calls.py(12),tests/test_v2_container_start.py(36),tests/test_v2_worker_app_and_version.py(9).tests/test_stage12_modal_app.py::test_stage12_functions_propagate_identifier_and_close_runtime(4), which asserted that the v2 workers set no attributes.format --check,check) and Pyright (python -m scripts.rules pyright projects/policyengine-simulation-executor) pass.tests/test_modal_container_start.py(22, the run_simulation app's workers) and three snapshot warm-up and job progress tests by node ID; they pass.tests/test_v2_worker_classes.py. They run in CI.🤖 Generated with Claude Code