Repository navigation
Remove the cold-start install by trimming packages a calculation never imports - #46
Conversation
Vercel's runtime installs public packages into /tmp when an instance starts. The platform stops an init at about 10 seconds and starts it again on the same instance with /tmp intact, and a stopped install leaves its files behind. main's install peaks at 406 MiB of about 513, so after most stops no retry fits and every request on that instance fails with "No space left on device" until the platform replaces it. That matches the /api/series 500s on 5 November. Remove packages a household calculation never imports, and add a test that fails when a complete install stops fitting on top of a stopped one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
With the unused packages gone, the function totals 188.74 MiB by the builder's count, inside the 225 MiB it bundles, so the runtime installs nothing at cold start. The README, the pyproject comment and the changelog still described a smaller install. A new test fails when the function passes 225 MiB, and the install-fits-twice test stays as the guard for that case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An independent review of this PR found no blocking problem and a set of smaller gaps, which this addresses: - The size test now reads the repo's tracked files, so a large committed file counts as it does for the builder, and counts cliff_watch/ twice, as the builder did on a padded preview. - Both size tests fail if their walk finds implausibly little, and CI's job summary shows what they measure. - The pyproject comment names the right path for tables and says what leaves with it. The README says what happens to the public packages, what losing the bytecode fill costs (measured on a preview), and that main requires no checks. - The changelog fragment goes: nothing in this repo reads changelog.d. No dependency or runtime file changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A second fresh deployment with the fill took 30.75 to 41.26 seconds on first requests, so the gap to the preview without it runs from 3 to 5 seconds on average. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n overturn A third fresh deployment with the fill took 31.60 to 34.26 seconds on first requests, which took the average gap to 7 seconds on that set. The gap varies with each set of readings, so the README states its size in words. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Review record: an independent Opus 5.5 agent approved |
|
Production's logs for
Traffic stayed light in that window, so heavier load remains untested. |
Main now carries #40, whose files match this branch's base, and #46, which removes the cold-start install on main's engine. This branch's engine takes the function past Vercel's 225 MiB bundle again, so the port keeps its install-fits-twice test and README section, adding #46's 4 KiB block wording, its note that main requires no checks, the size walk's sanity floor and the CI summary line. The pyproject comment now names policyengine-us as the package that brings in tables, as uv.lock shows. The cold-start changelog entry becomes a change from main rather than a fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
README.md conflicted: keep main's Cold-start install section and this branch's County from ZIP section, in that order. Everything else merged cleanly. The next commit adapts this branch to #40's Vitest tests, payload invariants and variable-graph snapshot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Production's
/api/seriesreturned 500 on every request for 28 minutes on 5 November, after two shorter bursts, with "No space left on device". A cold-start install that stops partway leaves too little room in/tmpfor its retry. This PR removes the packages a household calculation never imports. The function then fits inside Vercel's bundle, so no install runs at cold start and/tmpstays empty.No engine version and no displayed number changes: 48 requests to previews of
mainand of this PR returned identical responses.The 5 November failures
What the logs show
Production's
/api/seriesreturned 500 in these windows on deploymentdpl_H3rLyUj95jxUFREHUS66FH7GDFDE, which went live on 29 October, so no deploy caused them./api/seriesAll 30 failing rows log the same error before any CliffWatch code runs. The failing package varies (pandas, blosc2, plotly, tables, h5py, numpy, pydantic-core), and each attempt writes to a new temporary directory:
Why an instance gets stuck
The runtime's source and preview deployments of
main's tree show each step.main's functions at 307 to 343 MiB. Past 225 MiB, Vercel's Python runtime installs the public packages into/tmpwhen an instance starts, before any app code runs (vc_init.py). A failed install exits the process, and the request returns 500.dpl_fBK2zhv7sdoyGi2D3D81eJKSc6cs: the first process logged four ticks and stopped between 9.75 and 10.75 seconds after it started, and a second process then started on the same instance and finished the import./tmpsurvives the restart, and nothing removes a stopped install's files. The runtime only checks for its own completion marker, and each attempt creates a new temporary directory./tmphas room for one install, not one and a half. It holds about 513 MiB, and each file takes whole 4 KiB blocks.main's install peaks at 406 MiB and takes 31,436 files and directories, so block rounding costs it far more than its 308 MiB of apparent size suggests.So a stop that leaves about 186 MiB behind, 1.5 seconds into this test's install, leaves too little room for any retry, and every later request on that instance fails until the platform replaces it. A probe route stopped
main's install at each of these times, then ran it again twice:/tmpwhen the retry startsReproducing production's failure
Slowing
main's install in the platform's own init path reproduces production's error and its per-function pattern. Adding[tool.uv] concurrent-downloads = 1tomain's tree (dpl_DcSE4aRRtTVfmj9H5TLNXGRJwm39) made/api/probereturn 500FUNCTION_INVOCATION_FAILEDin 3.2 to 4.1 seconds on all three rounds and/api/calculatereturn 500 in 3.88 seconds. The probe's log rows carry production's error text:On the same deployment
/api/series,/api/metadataand/api/householdsreturned 200, and a later/api/proberequest returned 200 too. Some functions stick and others don't, as in production.What nobody has observed
No log shows a production install crossing the limit. A stopped init with no request attached writes no request log row, so the logs can't show it. uv's figures on 12 successful production cold starts come to 3.6 to 4.3 seconds, and
main's tree reached app code after about 5.75 seconds on a preview, so an install needs to take roughly twice as long to cross. The same install took 8.2 to 8.8 seconds when a probe route ran it inside a request on an unslowed preview, so that much spread has precedent, though a request differs from an init. The logs don't show what slowed those installs or why the third window ended. The explanation above rests on the matching error text, the measured table of stops and the reproduction.The fix
override-dependenciesinpyproject.tomlremoves four packages and whatever only they require, 23 in all. The runtime set goes from 84 packages to 61, with nothing added and no version changed:plotly, withtenacitytables, withpy-cpuinfoandblosc2, and throughblosc2:httpx(withhttpcore,h2,hpackandhyperframe),pydantic(withpydantic-core,annotated-typesandtyping-inspection),rich(withmarkdown-it-pyandmdurl),msgpack,ndindexandthreadpoolctlhf-xetjedi, withparsoA household calculation needs none of them. A trace of the code behind all four routes saw two import attempts,
h2andjedi, each inside anexcept ImportError, and none of the 23 loaded.plotlyandtableskeep importers in the engine, on chart and dataset paths: onlypolicyengine_us/tools/documentation.pyimports the charts module, nothing imports that file, andpd.HDFStoreappears on dataset paths, while the app builds onlySimulation(situation=...). The full suite and every preview route pass without them.That takes every function from 307 to 343 MiB down to 188.74 MiB by the builder's own count (
VERCEL_BUILDER_DEBUG=1,dpl_9DvwGdF4wLSeZkocADfCVoz3ZxTJ), which leaves 36 MiB under the 225 MiB limit. At or under that limit,shouldEnableRuntimeInstall()in the Python builder returns false, every dependency ships in the zip, and the builder fills the zip's remaining room up to 220 MiB with bytecode for the modules it ranks highest.main(dpl_fBK2zhv7sdoyGi2D3D81eJKSc6cs)dpl_BKG12Jgi9r3zn8jvjVsAwXEs3xhV)/tmpafter a cold start/var/task, apparent size/api/seriesafter about 8 idle hours/api/metadataafter about 8 idle hoursThe preview GitHub built from this head (
dpl_8BUGTmPVJepLwSbxVFSyUuhwKmnR) returned 200 on every route on all three rounds, and its logs show no install. Production's deployments come from the same GitHub integration, onmain, and the project sets no environment variables for any target.The two settings that break
main's tree do nothing here, because nothing installs:concurrent-downloads = 1(dpl_CNmrak8rMMWxA1gMuEcZH3hvU81a) andcompile-bytecode = true(dpl_3A1dSwiBiMEx97wuXLf53h6S2dca) both leave/tmpat 0.0 MiB and every route at 200 on all three rounds.What it costs
The zip holds 31.3 MiB of bytecode instead of 150.1 MiB, so loading the engine takes longer: a probe route that imports the engine and runs two series took 26.1 and 28.49 seconds on
main, and 33.33 and 37.92 seconds here. Skipping the install saves about 5.6 seconds of that, and first requests come out about even: a mean of 36.6 seconds over 5 readings onmain, against 34.6 and 36.3 seconds over 5 and 6 readings on the two builds here./api/metadata, which doesn't load the engine, gets faster.main/api/series/api/calculate/api/households/api/metadataThe probe column comes from
dpl_BKG12Jgi9r3zn8jvjVsAwXEs3xhV, built from07521ecwith probe routes, and the GitHub column fromdpl_DJ9a7qURtDSLUoxzV31gRUo19Lvnatcb14ce5. Commits since07521ecchanged only the README, the tests and comments, and dropped the changelog fragment.After 45 idle minutes, the first
/api/seriestook 39.6 seconds onmainand 38.38 here, and/api/calculate36.05 and 33.21. Single readings like these vary by several seconds, as the two columns for this PR show.The slowest of these readings, 42.47 seconds, leaves 17.5 seconds under the 60-second limit in
vercel.json. A slowdown that outran that margin would time out the request in hand, and with nothing in/tmpthe next request would start clean. That follows from the design; no preview has tested it.If the function grows
Growth costs a little first-request time before it brings the install back. The builder compiles bytecode only into the room under 220 MiB, so the fill shrinks one for one as the function grows. With no room left (
dpl_FSq4JGwxTPEq85VQXarQh9ZNBtYz, padded to 220.32 MiB by the builder's count, and "skipping bytecode precompilation" in its log), first requests took 38.39 to 41.53 seconds and every route returned 200. Fresh deployments with the fill took 33.36 to 35.29 seconds (dpl_DJ9a7qURtDSLUoxzV31gRUo19Lvn), 30.75 to 41.26 seconds (dpl_4pxD99DgedJsHkyf8qkeMWXvogCj) and 31.60 to 34.26 seconds (dpl_H9dbad3MWgmAaRCZ2kybebDoeztm). So losing the fill adds about 5 seconds on average, 3 to 7 across these three, and leaves those requests inside the 60-second limit. No preview without the fill has sat idle. Padding adds no code to load, so a bump that grows the engine would add its own load time too.Past 225 MiB the install comes back.
tests/test_deploy_footprint.pyfails at that point, so the bump's author decides whether to trim again or accept the install. The trimmed set would install at 173.0 MiB in 4 KiB blocks, so a complete install fits on top of a stopped one (364 of 513.4 MiB, with peak overhead), and a second test holds that line.mainhas no required checks, so a red run warns the author and can't block a merge. Makingpythona required check would close that gap; this PR leaves repo settings alone.cliff-watch#45 keeps a smaller install. Its engine's dependencies come to 262 MiB even with this trim, and that PR holds its measurements.
No number moves
compare_deployed.pysent the same 48 requests tomain's preview and this PR's: 4 households across 6 states, on/api/seriesand/api/calculate. Every response matched, and/api/metadatamatched too. The same 48 requests matched again ondpl_H9dbad3MWgmAaRCZ2kybebDoeztm, the preview GitHub built from5bcb048, which differs from this head by one README line. One of them needed a retry:main's preview logged a 200 for it, but no answer reached the client within 320 seconds.main's exactly.pyteston CI at this head: 20 passed, on the same engine versions, with all 5 footprint tests running on Linux wheels.Invariants
These hold for the locked dependency set, and
tests/test_deploy_footprint.pytests each one:uv.lockagrees withuv exporton what the function contains.The size tests skip on a Mac, whose wheels differ, and run on CI's manylinux wheels, and CI's job summary shows what they measure. They read the packages and the repo's tracked files fresh on each run.
BUILDER_EXTRA_MIBstands for the rest of the builder's count, chiefly the built frontend, and comes from one comparison with its debug log, so the 188.8 MiB in CI's summary sits within 0.1 MiB of the builder's 188.74 MiB by construction. Each test also fails if its size walk finds implausibly little.Landing
maindeploys production.vercel rollback dpl_H3rLyUj95jxUFREHUS66FH7GDFDErestores the previous build.axiom: n/a: cliff-watch deployment packaging; no policy encoding change
🤖 Generated with Claude Code