Repository navigation
Report in worker telemetry whether each call's container was restored from a memory snapshot - #1124
Merged
Merged
Conversation
Each run_simulation and run_simulation_segment call's operation should carry container_start (restored_from_snapshot, took_snapshot or no_snapshot) and container_call_number. These tests fail until the workers set both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The workers' snapshot hook records the loading container's MODAL_TASK_ID before Modal takes the snapshot. Each call compares it with the current MODAL_TASK_ID, which Modal 1.6.4 sets to the restored container's own task ID, and sets container_start (restored_from_snapshot, took_snapshot or no_snapshot) and container_call_number on its operation. Each attribute set is suppressed on its own, so a failure leaves the call's result and its function_call_id unchanged. The failure test now checks only the attributes it is about: with a Modal call ID, the annual worker also sets its job stage attributes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Modal 1.6.4 runs the snapshot hook in every worker container that doesn't restore, and takes a snapshot only when its worker sets MODAL_ENABLE_SNAP_RESTORE to 1. A container started without snapshots should report no_snapshot, not took_snapshot; that test fails until the hook records the flag. Also test that both attributes are set before the job runs, and that a failed or preempted call's operation record still carries them. Those pass already: they cover a gap in the tests, not a bug. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Modal 1.6.4 runs the snapshot hook in every worker container that isn't restored, but takes a snapshot only when its worker sets MODAL_ENABLE_SNAP_RESTORE to 1. The hook now records that flag with the task ID, so a container started without snapshots reports no_snapshot instead of took_snapshot. The observability skill now says which spans hold the setup left in a call: a took_snapshot container's hook also loads the models before its first call, and only the operation's span carries the two attributes. The changelog no longer says the attributes measure setup time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A call whose container start can't be read should still use up its call number, and a failure to record the snapshot hook should still load the models and leave the container reporting no_snapshot. Both tests fail until the counter advances first and the hook's record is suppressed. Also test that the plain functions, run_budget_window_batch included, set both attributes before their job runs, and check the attributes the operation hands to its metrics before the package filters them. Those pass already. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A call now takes its number before its container start is read, so it counts even if that read fails, and a failure to record the snapshot hook no longer stops the preload: the container then reports no_snapshot. The worker base class's docstring now says that Modal runs the snapshot hook in every container that isn't restored. The observability skill no longer says Modal's container records hold the restore's duration (they give queued and ready times, which include scheduling), and it names the plain functions that load models in a call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tests' restore now also runs the snap=False hook, as Modal does after each restore, so a change that reset the container record there would fail. The observability skill says which calls the call number counts, names the Modal call that holds container times, and notes that a segmented national run's parent call opens no country_module_load span. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The preload module's docstring said Modal runs the snap=True hook once, in the container that takes the snapshot. Modal 1.6.4 runs it in every container that isn't restored, and takes a snapshot only from a container it starts with snapshots enabled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
1.5 · 3 found that Modal's TaskGetInfo returned snapshot_behavior UNSPECIFIED for every production container on 2026-11-25, restored ones included, while each restore and snapshot showed in the container's log lines. The skill now points to those log lines, and records that restored containers on Modal testing reported their own MODAL_TASK_ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
marked this pull request as ready for review
November 26, 2026 12:58
anth-volk
added a commit
that referenced
this pull request
Nov 26, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
anth-volk
added a commit
that referenced
this pull request
Nov 26, 2026
#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>
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 #1123
Same-Repository Draft PR Check
PolicyEngine/policyengine-sim-api, not a personal fork.Changelog
changelog.d/container-start-telemetry.added.md, whose type is added.Summary
Since #1118, the simulation workers run in containers restored from Modal memory snapshots. Until now, their telemetry couldn't show which calls ran in such a container. This PR adds two attributes to the operation of each
run_simulation,run_simulation_segmentandrun_budget_window_batchcall. The attributes reach the call'soperation.completedlog record and its span.container_startrestored_from_snapshot,took_snapshot(Modal took the snapshot from this container) orno_snapshot(plain functions, and worker class containers Modal started without snapshots)container_call_numberHow a call tells them apart (Modal 1.6.4)
MODAL_TASK_ID;MODAL_ENABLE_SNAP_RESTOREis1. Modal takes a snapshot only when it is (maybe_snapshotinmodal/_runtime/user_code_imports.py).memory_restoresets itsMODAL_TASK_IDto the restored container's own ID._set_modal_call_attributescompares the recorded ID with the current one:restored_from_snapshot;took_snapshot;1, or the hook never ran:no_snapshot.What the change keeps
function_call_idand the model preload unchanged.Setup times
No new span. The restore and the snapshot hook both run outside any call, so no span measures them. With these attributes, the existing spans of a restored container's first call show the setup left after the restore, such as the time before and inside
country_module_load.docs/engineering/skills/observability.mdhas a new section on both attributes and on how to read setup times with them.Environment variables
MODAL_TASK_IDenv. On restore, Modal 1.6.4'smemory_restorerewrites it from the restore state.MODAL_ENABLE_SNAP_RESTORE_container_entrypoint.py: set to1for snapshot and restore tasks, unset otherwise.Production records already carry
service.instance.idbuilt fromMODAL_TASK_ID, so it is set at call time.Checked on Modal: on 2026-11-25, a measurement on Modal
testingwith Modal 1.6.4 storedMODAL_TASK_IDin the snapshot hook, as this PR does. Every restored container then reported a differentMODAL_TASK_IDfrom the one its hook recorded, and the hook saw a set ID.Not verified until this deploys: that
took_snapshotandno_snapshotmatch Modal's own logs. In production, Modal logs "Restoring Function from memory snapshot." for a restored container and "Creating CPU memory snapshot for Function." for a snapshotting one;modal app logs <app> --search "memory snapshot" --show-container-idlists them. Neither variable's behaviour is documented by Modal, so check again after a Modal upgrade. Modal'sTaskGetInfocan't be used for this: itssnapshot_behaviorwasUNSPECIFIEDfor every production container on 2026-11-25, restored ones included.Tests
The new file is
tests/test_modal_container_start.py. Its tests were committed failing, before each change.container_startvalue, including a worker class container started without snapshots.Run by node ID:
tests/test_modal_bundle_image.py::test_both_simulation_workers_load_the_country_models_before_the_snapshot.Also run:
python -m scripts.rules pyrightfor the executor;scripts/run_quality_guards.py.The rest of the executor's unit tests weren't run locally; CI runs them.
Review
Three rounds of adversarial review by separate reviewers.
cc849328: a worker class container that Modal starts without snapshots runs the hook too, and reportedtook_snapshot.Not in this PR
Docstrings corrected
app.pyandsrc/modal/country_model_preload.pysaid Modal runs the snapshot hook "once, in the container that takes the snapshot". Both now say it runs in every container that isn't restored.🤖 Generated with Claude Code