Repository navigation
fix: warm the first session before the server accepts connections - #92
Merged
tabedzki merged 2 commits intoNov 11, 2026
Merged
Conversation
panel serve runs app.py per session on the event loop that serves every session and /liveness, so the first visit after each start paid for the imports, the wiring pickle and the default atlas's metadata on that loop. Run one throwaway ChannelmapGUI through panel serve --setup instead, before the port is bound. It has no document, so it leaves no session behind. A failed warmup logs a warning and the server still starts. Assisted-by: ClaudeCode:claude-opus-5-5
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #92 +/- ##
======================================
Coverage ? 85.71%
======================================
Files ? 21
Lines ? 3445
Branches ? 0
======================================
Hits ? 2953
Misses ? 492
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The script swallows every exception, so tests must also assert no failure was logged, or they pass when the constructor raises. Cover opening the default atlas when it is on disk, and share the run-and-collect-failures helper. Say that the warmup only runs before the port is bound with NUM_PROCS=1, and drop the bytecode and "exactly what a session needs" claims. Assisted-by: ClaudeCode:claude-opus-5-5
This was referenced Nov 7, 2026
This was referenced Nov 16, 2026
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.
🤖 AI text below 🤖
Removes the extra stall on the first visit after each server start. This is the separate
create_app → … → is_downloaded → get_atlasstall noted in #91.Summary
panel serverunsapp.pyper session on the event loop that also serves every other session and/liveness. The imports, wiring pickle and default atlas metadata are one-time costs, and the first visitor paid them on that loop. They now run before the port is bound, at the image's defaultNUM_PROCS=1.entrypoint.sh exec panel serve ./app.py + --setup ./scripts/warm_first_session.py # builds one throwaway ChannelmapGUI --liveness ...The throwaway GUI has no document, so it leaves no session behind, and analytics and session hooks don't run. A warmup failure logs a warning and the server still starts, because Panel aborts startup if a setup script raises.
Evidence
Real image, 4500M memory cap, headless browser loading three sessions while polling
/liveness. "Before" is the same image with the--setupline removed. The 0.25 CPU rows show both runs of each./liveness, 8 CPUs/liveness, 0.25 CPU/livenessreturned 200 and the container kept running.--setupflag.tests/test_startup_warmup.pycovers the entrypoint flag, a fresh-process warmup, no leftover session state, failed warmups and imports, and the default atlas with and without a copy on disk. Against a mutant whose constructor raises, 4 of its 7 tests fail.ruff check .is clean.Not fixed: every session, including the first, is still built on the event loop; this removes only the one-time costs. Later sessions block
/livenessfor about 0.8–0.9 s at 8 CPUs and 3.9–7.2 s at 0.25 CPU, so the watchdog can still fire under heavy contention, and it did at 0.25 CPU in both runs with this change. Those alerts will have the samecreate_appstack. Fixing that means making session construction cheaper, which is left for a separate PR.Known limits:
NUM_PROCSabove 1, Panel runs the warmup on each process's event loop after the server starts, so it stalls about as much as a first session does today (from reading Panel's code, not run). Production uses 1.Merge Danger
Door: two-way
Revert, or remove the one
--setupline. No data or format changes.Blast Radius: startup
The port opens later, by about 2 s at 8 CPUs and 9 s at 0.25 CPU, so
/livenessfails during that window and a reverse proxy may return errors. Idle memory is about 185 MiB higher until the first visit. The deployment's compose file needs no change as long as it keeps using the image's entrypoint.Assisted-by: ClaudeCode:claude-opus-5-5