Skip to content

fix: never splice a resumed download across a republished bundle - #243

Merged
quickbeard merged 2 commits into
mainfrom
fix/download-resume-splice
Aug 5, 2026
Merged

fix: never splice a resumed download across a republished bundle#243
quickbeard merged 2 commits into
mainfrom
fix/download-resume-splice

Conversation

@quickbeard

Copy link
Copy Markdown
Owner

Summary

Fixes the corrupt-bundle failure seen in the field: codevhub skill office downloaded 1193.3 MB, then extraction failed with bad zipfile offset (local header sig) a few KB in. Root cause: a leftover .partial from the previously published (642 MB) bundle was resumed via HTTP Range against the newly published (1.2 GB) object, splicing the two together.

downloadFile already guards resumes with If-Range, but two holes remained:

  1. ETag-less partial → bare Range. When a .partial exists with no .etag record (a pre-ETag-era download, or a cleared record), the resume sent a bare Range and 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.)
  2. 206 despite a mismatching If-Range. A middlebox that honors Range while ignoring If-Range semantics can answer 206 for a republished entity. A 206 whose ETag differs 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 brokenIfRange mode to simulate the misbehaving hop; two new regression tests assert a clean full refetch (correct bytes, no Range on 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 fresh codevhub skill office also 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)
  • Full suite via the pre-commit hook

🤖 Generated with Claude Code

Quickbeard and others added 2 commits August 5, 2026 11:23
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>
@quickbeard
quickbeard merged commit 4a392fb into main Aug 5, 2026
2 of 4 checks passed
@quickbeard
quickbeard deleted the fix/download-resume-splice branch August 5, 2026 04:31
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