fix: never splice a resumed download across a republished bundle - #243
Merged
Conversation
A user's `codevhub skill office` run produced a corrupt bundle zip
("bad zipfile offset" a few KB in): a leftover .partial from the old
publish was resumed with Range and the new object's bytes were appended
onto stale ones. Two holes closed in downloadFile:
- A partial with no stored ETag (pre-ETag download or cleared record)
used to resume with a bare Range and trust the 206. Without an
expected sha256 nothing downstream catches the splice, so such a
partial is now scrapped and the download starts clean.
- Even with If-Range, a hop that mishandles it can answer 206 for a
republished entity. A 206 whose ETag differs from the partial's is
now treated like the 416 case: scrap the partial and ETag record and
refetch from scratch.
Test server gains a brokenIfRange mode (honors Range while ignoring
If-Range) to cover the second case.
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.
Summary
Fixes the corrupt-bundle failure seen in the field:
codevhub skill officedownloaded 1193.3 MB, then extraction failed withbad zipfile offset (local header sig)a few KB in. Root cause: a leftover.partialfrom the previously published (642 MB) bundle was resumed via HTTP Range against the newly published (1.2 GB) object, splicing the two together.downloadFilealready guards resumes withIf-Range, but two holes remained:.partialexists with no.etagrecord (a pre-ETag-era download, or a cleared record), the resume sent a bareRangeand trusted the 206. For downloads without an expected sha256 — the office bundles — nothing downstream catches the splice. Such a partial is now scrapped and the download starts clean. (Downloads with a sha256 keep the bare-Range resume: the final hash check catches any mismatch.)Rangewhile ignoringIf-Rangesemantics can answer 206 for a republished entity. A 206 whoseETagdiffers from the partial's stored one is now handled like the existing 416 case: scrap the partial + ETag record and refetch from scratch.The test server gains a
brokenIfRangemode to simulate the misbehaving hop; two new regression tests assert a clean full refetch (correct bytes, noRangeon the retry) in both scenarios.Recovery for already-affected machines: delete the corrupt zip in
~/.codev-hub/office(or the whole folder) and re-run — with this fix, a freshcodevhub skill officealso self-heals since the stale partial can no longer be spliced.Test plan
pnpm typecheck,pnpm check(biome)tests/lib/download.test.ts: 31 passed (29 existing + 2 new regression tests)🤖 Generated with Claude Code