Skip to content

Build the Modal image from uv.lock and let Dependabot propose model bumps - #101

Draft
MaxGhenis wants to merge 9 commits into
mainfrom
image-from-uv-lock
Draft

MaxGhenis wants to merge 9 commits into
mainfrom
image-from-uv-lock

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Main merged in on November 30 at a3e27b3, after #108 moved policyengine-us to 2.156.4 (911a039). This PR's own diff is unchanged apart from that version: the uv image now installs policyengine-us 2.156.4, with policyengine-uk 2.134.6, policyengine-core 3.38.0 and numpy 2.1.3 as before. The November 29 readings below were taken at 2.154.3.

Rebased onto main after #100 merged (87edfe4) and was checked live on November 29. It will not merge before December 2, so that the change to how the live image is built does not land during Giving Tuesday.

What this changes

  • The Modal image installs uv.lock. modal_app.py builds the image with Image.uv_sync(uv_version="0.11.7") instead of ten hand-copied pip_install pins. With Modal 1.3.0.post1 and 1.6.4 alike, that runs uv sync --frozen --no-install-workspace --compile-bytecode on pyproject.toml and uv.lock when the image is built. What each place installs:

    • The image: the project's dependencies and its default dev group (httpx, isort), at uv.lock's versions. Not the project itself (its code is added as files) and not the dev extra.
    • CI's test job (uv sync --locked --extra dev): the same, plus the dev extra and the project.
    • The FAQ numbers job (uv sync --locked): the same packages as the image, plus the project.
    • The deploy job: pip install "modal>=1.1" (1.6.4 on November 29). That client builds the image, and Modal mounts it into the container at run time.
  • modal moves to the dev extra. With modal in the image, the mounted client imported protobuf, grpclib and aiohttp from the lock's copies. Without it, the client uses Modal's own copies (/__modal/deps), as production does today. tests/test_giving_season.py imports modal_app, so CI's test job still installs modal.

  • uv.lock is relocked. The old image resolved its unpinned packages afresh at each build, so production ran newer versions than uv.lock's. At e726832 the image would have installed 18 packages with GitHub advisories. Twelve came with the API's dependencies: certifi and anyio (critical); urllib3, fsspec, msgpack, wheel and starlette (high); and filelock, idna, requests, pytest and python-dotenv (medium). Six came with modal: aiohttp, protobuf and cbor2 (high), and multidict, h2 and hpack (medium). Production's pip layer has none of those versions except starlette 0.50.0. The relock (uv 0.11.7) passed --upgrade-package for every package in the API's dependency tree except the ten old pins (the PolicyEngine models, spm-calculator, numpy, pandas, scipy, fastapi, pydantic and pyyaml). In uv.lock, 57 packages moved, five were added and one (six) was removed. The other packages kept their versions: the ten pins; 24 more of the image's packages, among them census, openpyxl, pydantic-core and starlette; the Windows-only colorama; and, apart from platformdirs, the 26 packages only CI's test job installs from the lock (the dev extra's black, hypothesis, pytest-cov and modal, and what they need). Five of those 26 have advisories: aiohttp, black, cbor2, multidict and protobuf. The image's packages now include all 85 in production's pip layer (deploy run 46221122775) at the same versions, plus nine: uvicorn and its standard extras, isort, packaging and wheel. (Production also has packaging 26.0 and wheel 0.46.3 in the base image's site-packages; the image's venv has 26.4 and 0.48.0.) Of the image's packages (not counting the copies Modal mounts for its client, as in production), only starlette 0.50.0 has an advisory; fastapi 0.124.2 requires starlette below 0.51, and Deploy, CI and dependency gaps around the Modal image (from #101's reviews) #102 tracks it.

  • Dependabot proposes model bumps. .github/dependabot.yml checks weekly on Mondays, with lockfile-only, and allows policyengine-us, policyengine-uk and policyengine-core in one group, so a bump comes as one PR (limit 1). Only the models depend on core. A comment in dependabot-core's Job#allowed_update? says GitHub's service defaults a rule's type to direct, which that method then excludes indirect dependencies from, so core's entry sets dependency-type: "all"; that matches core whether or not pyproject.toml names it. Dependabot picks only releases that uv can resolve within pyproject.toml's ranges (for core, the models' requirements). The docs say it waits 3 days after a release by default; in dependabot-core that cooldown chooses the three packages' versions, and the relock command it then runs takes no cooldown option. It targets those three packages, but its relock (uv lock --upgrade-package in its uv updater) can also move packages a new release needs. Untested here:

    • its first run, and whether it proposes a core release without a model release (with "all" or the earlier "indirect");
    • what it does to its PR after someone pushes the FAQ commit, or when a newer release supersedes the PR;
    • whether the image's uv 0.11.7 reads a lock that Dependabot's uv writes.

    Nothing relocks the other packages on a schedule. Dependabot alerts are on from 2026-11-29; security updates stay off, since GitHub's options reference says the allow list applies to them too, which would limit them to the three PolicyEngine packages.

  • Tests.

    • tests/test_modal_pins.py follows the image that fastapi_app is decorated with. fastapi_app must be defined once, and that image must be:

      • bound once: in the module's scope, counting assignments of any form, imports, definitions, del, except ... as, match captures and walruses in annotations, or in a function or class that declares it global. Names local to a function, class, lambda or comprehension don't count;
      • built from modal.Image.debian_slim, for the Python version the test evaluates markers with, by a chain that only syncs the lock, sets the environment (no UV_ variables, PATH, VIRTUAL_ENV or PYTHONHOME) and the working directory, and adds local files;
      • synced by exactly one uv_sync, frozen, with uv pinned to a release and no extras or groups.

      Every .function or .cls call that the module's scope evaluates, whatever its receiver, and any made on a modal.App or a name for one, must be at the top level, and if it names an image it must name that one. None may take ** options, which could pass another image, or a name= other than a literal that isn't "fastapi_app". The app may not set a default image, and app.function may not be used without being called. None of the installer methods it lists may appear.

      The packages the image's sync installs, worked out from uv.lock for CPython 3.13 on x86-64 Linux (following environment markers and extras), must include what the API imports and must not include modal. For this lock that set is the 94 packages the scratch deploy installed. A marker on a variable the test doesn't model (the patch version, the kernel, an extra) fails the test rather than taking the value of the machine running it. Today's lock uses only sys_platform, platform_machine and platform_python_implementation. x86-64 is inferred (Modal's source says images it pulls from a registry must be built for linux/amd64; the scratch logs don't print the machine), and both platform_machine markers in the lock give the same answer on aarch64. [tool.uv] default-groups must be unset or ["dev"], and uv.lock must lock each package once.

      Its docstring says it catches mistakes, not code written to get around it. Across rounds 2 to 4 it fails on 64 mutants of modal_app.py and 11 of uv.lock or pyproject.toml, and passes 20 harmless edits and the unchanged files.

    • tests/test_faq_numbers.py and frontend/scripts/write-faq-numbers.ts read the model versions from uv.lock as TOML. faqNumbers.json records policyengine-core as well as the two models, and the test requires exactly those three.

Review

Rounds 1 and 2 reviewed the whole change; rounds 3 and 4 were scoped to the earlier findings. Round 4 found every P1 closed. Its verdict line said REQUEST_CHANGES because of three new P2s: an alias of app, a walrus in an annotation, and marker variables the test filled in from the host. Under the review rule the levels decide, and P2s from a scoped round are fixed or filed without another round. b2397d8 and 72dd80b fix those P2s and most P3s from round 4 and an in-session check; 96c237c updates the README for the alerts setting. No independent reviewer has read those three commits. They were checked in-session with the mutants above, an in-session harness of about 60 more cases, the local tests and CI. #102 lists the P3s left open.

How a model bump lands

  1. Dependabot opens a PR that relocks uv.lock, for a release of one of the three packages that is at least 3 days old (its default cooldown) and that uv can resolve within pyproject.toml's ranges. A package the relock moves along with it isn't held to the cooldown.
  2. CI's FAQ numbers job uploads faqNumbers.json at the new versions. The FAQ test fails until that file is committed.
  3. Someone commits the artifact from the FAQ job's run on the PR's latest commit, rereads any FAQ sentence whose figure moved, gets the review a model change needs, and merges on green CI. A merge deploys whether or not CI passed. Untested: whether Dependabot rebases or replaces its PR after that commit, or when a newer release supersedes it. If it does, repeat this step on its new commit.

Who does step 3, and who refreshes the other locked packages, is queued for Max as decision d3552.

Risks

  • The first deploy uses the new image definition. Modal may reuse the layers the scratch deploy below built. The interpreter stays CPython 3.13.3, and the 85 packages production's pip layer installed keep their versions. The container's Python moves to /.uv/.venv, which uv_sync puts first on PATH. PYTHONPATH=/root and the added source directories stay as they were. After the deploy I will check:

    • /api/health and its simulation_workers count;
    • a US and a UK calculation against the recorded FAQ answers;
    • container memory.

    The comparison is the current pip_install image, read on November 29 after Update policyengine-us to 2.154.3 #100 deployed. It showed simulation_workers 4. Three bursts of eight /api/calculate requests at once took 70.0, 24.2 and 23.2 s. The first followed checks in which HI and MN still returned pre-Update policyengine-us to 2.154.3 #100 answers. It answered 204 requests (four for every state and DC) with no failures. Container memory (cgroup memory.usage_in_bytes) was 5,449 MiB after 102 requests and 5,498 MiB after 204. The app process and forkserver were at 1,376 and 1,386 MiB resident.

  • A scratch deploy of c6d6a41 worked. Since then, dff23e9, b2397d8, 72dd80b and 96c237c change only the tests, README and Dependabot config; modal_app.py, pyproject.toml and uv.lock are the same, so the image is too. It was deployed as givecalc-uvsync-scratch with Modal 1.6.4, with no warm container and without the hourly job that writes to production's autoscaler, then stopped.

    • The build copied uv 0.11.7 and ran uv sync --frozen (94 packages, no modal).
    • The container ran /.uv/.venv/bin/python 3.13.3. It imported modal 1.6.4 and synchronicity from /pkg; protobuf 6.31.1, grpclib 0.4.8 and aiohttp 3.12.7 from /__modal/deps; and policyengine-us 2.154.3, core 3.38.0 and uk 2.134.6 from the venv.
    • It reached four workers and answered all nine FAQ requests to the cent.
    • Warm bursts of eight requests at once, with four workers each: 23.1, 23.4 and 22.6 s. Production, alternating with the last two: 26.8 and 27.6 s.
    • Container memory was 3,179 MiB idle and 5,004 MiB after 36 requests (12 to /api/savings or /api/uk/savings, 24 to /api/calculate).
  • A revert restores the pip_install definition. A fresh build of it resolves the unpinned packages afresh, so it may not match today's image exactly. Untested here: modal app rollback givecalc, which Modal's CLI help says redeploys the previous version and resets the app to its state at that deployment. The next push to main deploys over either.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
givecalc Ready Ready Preview Nov 30, 2026 6:41pm UTC

Request Review

…umps

The image now installs uv.lock as it is (Image.uv_sync, uv sync --frozen)
instead of nine hand-copied pins, so it is the environment CI tests by
construction. tests/test_modal_pins.py checks that the image is built by
one uv_sync with no extras and that nothing else installs packages; the
FAQ test and the faq-numbers script read the model versions from uv.lock.

.github/dependabot.yml relocks the PolicyEngine packages each Monday, in
one PR for policyengine-us with core and one for policyengine-uk. The FAQ
numbers job on that PR uploads the FAQ's answers at the new versions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes from the first review of the uv.lock image:

- faqNumbers.json records policyengine-core as well as the two models,
  and test_faq_numbers requires exactly those three, so a core release
  alone makes CI ask for a new file. The writer parses uv.lock as TOML
  (Bun's parser) instead of matching lines.
- test_modal_pins follows the image fastapi_app is decorated with: one
  name, assigned once, built from debian_slim by a chain that only runs
  one pinned uv_sync on the repository root, sets the environment and
  adds local files. It catches a sync on an unused image, a different
  decorator image, dockerfile_commands, a reassignment and a missing
  uv_version.
- The README, modal_app.py, dependabot.yml and the workflow comments no
  longer promise more than the code does: Dependabot checks weekly and
  opens a PR only when a release is out, relocking can move other
  packages, the image skips the dev extra, and the deploy job's Modal
  client is not the one uv.lock pins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- test_modal_pins requires uv_sync's uv_version to name a release and
  refuses UV_ variables in the image's env, which could change what the
  sync installs.
- The FAQ writer reads uv.lock before calling the API, so a lock missing
  a model fails at once.
- The README, dependabot.yml and modal_app.py say Dependabot opens one PR
  per group with a new release unless that group's PR is open, and the
  README notes the image skips the dev extra.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Round 2 found that the first uv_sync deploy would move production from a
fresh 2026-11-29 resolve to uv.lock's year-old transitive packages, 11 of
them inside published advisories (certifi, anyio, urllib3, fsspec, msgpack
and others), and that the image would put the lock's modal closure ahead of
the dependencies Modal pins for its mounted client.

- pyproject: modal moves to the dev extra (modal>=1.1). The image skips it;
  tests/test_giving_season.py still gets it from CI's --extra dev.
- uv.lock: every package in the project's runtime closure except the ten
  old pip_install pins relocked with uv 0.11.7. The image's packages now
  match all 85 in production's pip layer (deploy run 46221122775) at the
  same versions; the PolicyEngine models, numpy, pandas, scipy, fastapi,
  pydantic, pyyaml and spm-calculator are unchanged, and so are black,
  isort, hypothesis and pytest-cov.
- test_modal_pins: counts every binding of the image name, rejects **
  options on app.function and app.cls, rejects PATH, VIRTUAL_ENV and
  PYTHONHOME in env steps, and checks that the image's closure installs
  what the API imports and not modal. The docstring says it catches
  mistakes, not evasion.
- Dependabot: one group for policyengine-us, -uk and -core, so one PR
  and one faqNumbers.json carry a bump. README, the dependabot.yml header
  and modal_app.py now say only what the config does and what GitHub's
  docs state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 3:
- test_modal_pins.py counts bindings of the image in the module's scope
  only (adding except-as, match captures, del and global), checks only
  calls on the module's modal.App, and rejects name= there, which could
  register a second fastapi_app. It also requires one fastapi_app.
- image_packages() follows environment markers for the image's platform
  (CPython 3.13, x86-64 Linux), so it matches the 94 packages the scratch
  deploy installed. It handles extras that name themselves, requires each
  package locked once, and a new test requires no extra default groups.
- dependabot.yml: core's allow rule sets dependency-type "indirect",
  since only the models depend on it (untested).
- README: Dependabot targets the three packages, but its relock can move
  what a new release needs; eligibility and the post-FAQ-commit and
  supersede behaviour, which are untested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- bindings() follows each scope: a function or class that declares the
  name global counts, a read-only global doesn't, and argument and
  return annotations (evaluated at def time before Python 3.14) count.
- fastapi_app must be bound once, so a second def inside an if or try
  fails.
- Every .function/.cls call the module's scope evaluates is checked,
  whatever its receiver, so an alias of app is covered; a call on the
  app or an alias elsewhere, a bare app.function, and a default image on
  the App fail. A literal name= other than "fastapi_app" is allowed, as
  are an annotated app or image and uv_sync(frozen=True).
- debian_slim's python_version must match IMAGE_PLATFORM, and a lock
  marker on any variable the test doesn't model (patch version, kernel,
  extra) fails instead of taking the host's value.
- dependabot.yml: core's rule uses dependency-type "all", which matches
  whether or not pyproject.toml names core (untested).
- README: core's range, the cooldown's scope, the untested list, and the
  85 packages of production's pip layer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Alerts were turned on for the repository on 2026-11-29 (decision d3556).
Security updates stay off because the allow list would limit them to the
three PolicyEngine packages; an alert on another package is fixed by
relocking that package in its own PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts: modal_app.py keeps this branch's uv_sync image (main only moved
the pip pin it removes); faqNumbers.json takes main's figures with this
branch's three-model version block at policyengine-us 2.156.4. uv.lock and
pyproject.toml merged cleanly, and `uv lock --check` passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Merged main into this branch at a3e27b3, after #108 (policyengine-us 2.156.4) landed as 911a039.

  • Conflicts: modal_app.py keeps this branch's uv_sync image (main had only moved the pip_install pin this PR removes); frontend/src/lib/faqNumbers.json takes main's figures with this branch's three-model version block at 2.156.4. uv.lock and pyproject.toml merged cleanly, and uv lock --check passes.
  • This PR's diff against main is line for line the reviewed diff from 87edfe4 to 96c237c, apart from the policyengine-us version (2.154.3 to 2.156.4, in faqNumbers.json and the removed pip pin) and the FAQ file's generated date. Both show 11 files, 988 insertions and 391 deletions.
  • The image will install policyengine-us 2.156.4, policyengine-uk 2.134.6, policyengine-core 3.38.0 and numpy 2.1.3: what production's pip image has run since Update policyengine-us to 2.156.4, with Wisconsin's 2026 ceiling #108's deploy (46485626260).
  • Production at 18:42Z replays main's FAQ file at 15 cases, 0 differ.
  • The December 2 merge job is repinned to this head; CI on it decides as before.

This branch was successfully deployed

1 active deployment
Preview – givecalc — a3e27b3f Deployed Nov 30, 2026 by vercel[bot]
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.

1 participant