fix: harden checkpoint downloader for startup-critical fetches#29
Open
JasonWildMe wants to merge 1 commit into
Open
fix: harden checkpoint downloader for startup-critical fetches#29JasonWildMe wants to merge 1 commit into
JasonWildMe wants to merge 1 commit into
Conversation
download_checkpoint runs during service startup (and is the mechanism behind URL-based model weights), so: - add a (connect, read) socket timeout plus a wall-clock deadline for the whole download, so neither a stalled connection nor a drip-feeding server can block readiness forever - stream to a temp file and os.replace() into the cache path so a concurrent reader or mid-download crash never sees a partial file - serialize concurrent downloaders with a per-key flock so multiple workers sharing a cache volume fetch once and reuse the result - key the cache by sha256(url) + basename so two stores serving the same filename (e.g. .../model.pt) cannot collide Written test-first: tests/test_checkpoint_utils.py. Co-Authored-By: Claude Fable 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.
What
Hardens
checkpoint_utils.download_checkpoint— the mechanism behind every URL-configured model weight, which runs during service startup:(10, 60)connect/read timeout backs it up. On expiry, the response is closed and a cancellation flag (checked after header receipt, per chunk, and under a commit lock before the final rename) guarantees no checkpoint is ever installed after the caller has raisedTimeoutError.os.replace()into place — a concurrent reader or mid-download crash never sees a partial file at the cache path.flockso multiple workers/replicas sharing a cache volume download once and the rest reuse the result.sha256(url)_basenameinstead of basename alone — two stores serving.../model.ptno longer collide. (Existing old-format cache entries in/tmp/checkpointsare simply ignored and re-fetched once.)Why
#26 makes
MODEL_BASE=https://...a first-class deployment mode, which turns this downloader into the critical path for every cold start on serverless GPU platforms. These failure modes (unbounded startup hang, partial-file reads, duplicate concurrent downloads) go from theoretical to routine in that world. The hardening is equally valid for the URL weights prod already uses.Testing
Written test-first (TDD):
tests/test_checkpoint_utils.py, 11 tests — each hardening behavior had a failing test before the code. Includes a genuinely stalling fake server for the deadline path, a threaded flock contention test for the lock path, and a late-header race test. Full suite: 53 passed.Provenance
Carved out of #26 as an atomic change. Adversarially reviewed by Codex 5.6 (gpt-5.6-terra) over 5 rounds; it drove the wall-clock deadline (vs naive between-chunk checks), the cross-process lock, the cancellation flag, and the commit lock, and explicitly confirmed convergence: no interleaving permits an install after cancellation.
🤖 Generated with Claude Code