Skip to content

feat(prebuilt): verified fetch ladder with Range resume (#1882) - #2172

Merged
zackees merged 3 commits into
mainfrom
agent/1882-fetch
Nov 24, 2026
Merged

zackees merged 3 commits into
mainfrom
agent/1882-fetch

Conversation

@zackees

@zackees zackees commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Implements the next cell of #1882: the verified fetch ladder that turns a
Catalog hit into a file on disk.

What it does

Fetcher::fetch(&Asset) → Artifact { path, size_bytes, sha256 }:

  • Integrity while streaming. The declared exact size_bytes and SHA-256 are
    enforced as the body arrives: a body that exceeds the declared size is
    refused before it writes past it, a short body is kept as a resumable
    partial, and nothing is renamed into place unless the digest matches.
  • Range/If-Range resume. The attempt that writes a partial records the
    asset digest plus the response ETag (else Last-Modified) in a sidecar; the
    next attempt asks for bytes=<len>- guarded by If-Range, restarts at 0 when
    the server answers 200, and discards the partial on 416.
  • URL ladder. Each URL is tried in order, twice — resume, then from
    scratch — because a poisoned partial can only be cured by starting over.
  • Process-local single-flight. Concurrent fetches of one digest collapse to
    one download; the second caller re-verifies the committed file.
  • Path safety. The destination name is fp-digits + sanitized basename, so
    a bucket filename (../../evil) cannot escape the staging directory.

Tests (real output)

prebuilt module: 18 passed, 0 failed (12 new). Crate lib suite:
335 passed, 0 failed, 2 ignored in 4.68 s.

Fixtures are local axum servers that assert on the wire: the resume test
requires Range: bytes=3000- and the matching If-Range; a refused range
must rewrite the body rather than append; a 416 must lead to a clean restart;
a corrupt source must fall through to the next URL and, alone, exhaust without
leaving a partial.

Two RED proofs by mutation: removing the If-Range header fails the resume
test; disabling the exact-size check fails the short-body test.

cargo fmt --check exit 0; ci/enforce_platform_boundary.py --print-totals
exit 0 and ci.test_enforce_platform_boundary 14 tests OK.

soldr cargo clippy -p fbuild-packages-fetch --lib --tests -- -D warnings
→ exit 0 (the first push did fail CI Clippy: attempt was 130 lines and the
fixture log tripped type_complexity; the second commit splits attempt into
open + stream and adds a Wire alias, no behaviour change).

#1882 stays open (remaining cells: streaming extraction, staging/partial GC,
disk-cache LRU, the BuildRequest field, the bucket key, and a daemon-wide
single-flight).

Authored by the fbuild steward agent; ~/dev/fbuild untouched.

Turn a `Resolution::Hit` asset into a file on disk without trusting any
single URL:

- exact `size_bytes` and SHA-256 are enforced while the body streams: an
  over-long body is refused before it writes past the declared size, and a
  short body is kept as a resumable partial instead of being committed;
- a partial resumes with `Range` + `If-Range` against the validator (ETag,
  else Last-Modified) that the writing attempt recorded in a sidecar, and
  restarts from byte 0 when the server answers 200 instead of 206; a 416
  discards the partial so the fresh attempt can run;
- the URL ladder is tried in order, each URL twice (resume, then from
  scratch), because a poisoned partial can only be cured by starting over;
- concurrent fetches of one digest in this process collapse to a single
  download (process-local single-flight);
- the destination name is derived from the digest plus a sanitized
  basename, so a bucket filename can never escape the staging directory.

Tests are local axum fixtures (resume headers asserted on the wire,
refused range, 416, corrupt source fall-through, over-long and short
bodies, single-flight, invalid assets, size limit, traversal filename).
12 new tests; `prebuilt` 18/18 and the crate lib suite 335 passed.
Two RED proofs by mutation: dropping the If-Range header fails the resume
test, disabling the exact-size check fails the short-body test.

#1882 stays open (remaining cells: streaming extraction, staging/partial
GC, disk-cache LRU, BuildRequest field, bucket key, daemon-wide
single-flight).
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

Parsing warnings: 1

Validation error: Unrecognized key: "enabled" at "reviews.pre_merge_checks"
Configuration instructions

  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Clippy (`-D warnings`) refused the first cut: `Fetcher::attempt` was
130 lines (cap 100) and the fixture's `(Range, If-Range)` log tripped
`type_complexity`.

Split the attempt into `open` (request, status/Content-Range decision,
sidecar write) and `stream` (hash + exact-size enforcement), share the
sidecar reader, and give the fixture log a `Wire` alias. Behaviour is
unchanged except that an over-long body now also drops the sidecar, which
the corrupt-source test already required of a poisoned partial.

Proven locally: `soldr cargo clippy -p fbuild-packages-fetch --lib
--tests -- -D warnings` exit 0; prebuilt 18/18; crate lib 335 passed.
`Dylint Full` on the previous head failed `ban_poison_panic`:
`self.gates.lock().expect("gate map poisoned")` cascades the original
panic across every other digest's lock holder.

The map only hands out `Arc`s and a poisoned map still holds valid gates,
so recover the guard with `.unwrap_or_else(|error| error.into_inner())`
instead of panicking, per the lint's documented cure.

Verified: `soldr cargo clippy -p fbuild-packages-fetch --lib --tests -- -D
warnings` exit 0; crate lib suite 335 passed / 0 failed / 2 ignored.
@zackees
zackees added this pull request to the merge queue Nov 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 24, 2026
@zackees
zackees added this pull request to the merge queue Nov 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 24, 2026
@zackees
zackees added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit 1a8623e Nov 24, 2026
33 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant