Skip to content

feat(fetch): {path} mirror template + FBUILD_DOWNLOAD_MIRROR_FIRST for the fbuild package mirror - #1797

Merged
zackees merged 3 commits into
mainfrom
feat/download-mirror-path-template
Oct 30, 2026
Merged

zackees merged 3 commits into
mainfrom
feat/download-mirror-path-template

Conversation

@zackees

@zackees zackees commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

What

Teach the download mirror fallback about our own public mirror of the PlatformIO
registry catalog (DigitalOcean Spaces, bucket fbuild, region sfo3, public read),
whose object keys preserve the registry download path after /download/.

Two additions to crates/fbuild-packages-fetch/src/downloader_mirrors.rs:

  1. {path} template placeholder for FBUILD_DOWNLOAD_MIRRORS entries. It expands
    to the registry-relative path of the primary URL — everything after /download/ on
    dl.registry.platformio.org. Off the registry (including a /download/ segment on
    some other host, e.g. a GitHub release asset) there is no such path and {path}
    degrades to the last path segment, the same value {filename} produces. So the
    whole mirror is one variable:

    export FBUILD_DOWNLOAD_MIRRORS='https://fbuild.sfo3.digitaloceanspaces.com/{path}'

    {filename} and bare-base-URL entries are byte-identical to before; {path} is
    checked first only because a template can contain just one of them.

  2. FBUILD_DOWNLOAD_MIRROR_FIRST — truthy (anything but unset, empty, 0, or a
    case-fold of false) moves every configured mirror ahead of the primary URL.
    Unset/empty keeps today's mirrors-after-primary order.

Exact semantics

Variable Semantics
FBUILD_DOWNLOAD_MIRRORS unchanged, plus each entry may now use {path}
FBUILD_DOWNLOAD_MIRROR_FIRST truthy → attempt order is mirror₁ … mirrorₙ, primary; unset/empty/0/false → primary, mirror₁ … mirrorₙ

Under mirror-first the primary stays in the candidate list as the last resort, so a
mirror that is missing the file (the bucket is still filling) falls through to the
vendor rather than failing the build. Unchanged in both orders: the per-candidate retry
policy, the SHA-256 check on whatever bytes arrive, the file name every candidate lands
under (always the primary's), and the final all_candidates_failed message — it still
reports the primary URL's own error plus also tried N mirror(s): …. That last part
needed the loop to track the primary's error by index instead of "first error seen",
since under mirror-first the first failure can be a mirror's.

Tests (RED → GREEN)

New in downloader_mirror_tests.rs (no network for the pure ones; the two ordering
end-to-end tests use the file's existing loopback servers):

  • candidate_urls_expand_path_for_a_registry_download_url
  • candidate_urls_path_falls_back_to_the_file_name_off_registry
  • candidate_urls_keep_every_template_form_in_the_configured_order
  • attempt_order_tries_the_primary_first_by_default
  • attempt_order_tries_mirrors_first_when_requested
  • mirror_first_env_follows_the_truthy_convention
  • mirror_first_serves_from_the_mirror_without_touching_the_primary
  • mirror_first_still_reports_the_primary_error_when_everything_is_down

RED, first commit (fa8c859e), before any production change — the API does not exist:

error[E0425]: cannot find function `attempt_order` in this scope
error[E0425]: cannot find function `mirror_first_requested` in this scope
error[E0425]: cannot find value `MIRROR_FIRST_ENV` in this scope
error: could not compile `fbuild-packages-fetch` (lib test) due to 13 previous errors

RED again behaviourally, with only the mirror-first half implemented (the three
{path} tests fail on the assertion, the five ordering/flag tests already pass):

left:  "https://mirror.example/{path}/ClearCore-1.7.4.zip"
right: "https://mirror.example/ClearCore-1.7.4.zip"
...
test result: FAILED. 12 passed; 3 failed

GREEN after the {path} change: 15 passed; 0 failed for the mirror tests and
203 passed; 0 failed for the whole crate (soldr cargo test -p fbuild-packages-fetch).

Gates run locally

  • soldr cargo fmt --all (clean)
  • soldr cargo clippy -p fbuild-packages-fetch --all-targets -- -D warnings (clean)
  • soldr cargo test -p fbuild-packages-fetch → 203 passed, 1 ignored
  • RUSTDOCFLAGS="-D warnings" soldr cargo doc -p fbuild-packages-fetch --no-deps (clean)

Live mirror check

{path} for …/download/platformio/platform/espressif32/6.5.0/espressif32-6.5.0.tar.gz
resolves to the bucket key that serves HTTP/2 200, content-length: 1417547,
anonymously. A key the filler job has not reached yet (platformio/tool/ framework-arduino-avr/5.4.0/…) answers 403 — which is exactly the case the
primary-as-last-resort ordering covers.

Notes

  • Scope kept to the mirrors module: no downloader refactor, no registry-client change,
    no error-plumbing change beyond tracking the primary's error by index.
  • Truthy env parsing is implemented locally rather than reused: the repo has three
    divergent copies of the concept and no shared helper —
    fbuild-cli's private is_truthy_env (empty/0/false falsy),
    fbuild-paths' private env_flag_is_one (== "1"), and
    fbuild-daemon's refresh_emu_cache_requested (1|true|TRUE|yes|YES).
    This flag follows the broadest of the three (is_truthy_env), documented at the
    function. Unifying them is a refactor for its own PR, not this behaviour change.

🤖 Generated with Claude Code


Review follow-up (3bf3630)

A mirror entry naming both {path} and {filename} previously had only
{path} substituted and shipped the literal {filename} in the request URL.
Both are now substituted; single-placeholder and bare-base entries are
unaffected (replacing an absent placeholder is a no-op), and
candidate_urls_keep_every_template_form_in_the_configured_order gained a
https://d.example/{path}?name={filename} case.

zackees and others added 2 commits October 30, 2026 01:45
Covers `{path}` expansion for a registry download URL, its fall back to the
file name off the registry, the existing `{filename}` / bare-base forms in
configured order, the attempt order with and without
`FBUILD_DOWNLOAD_MIRROR_FIRST`, the flag's truthy parsing, a mirror-first
download that never touches the primary, and the unchanged
all-candidates-failed error naming the primary plus the mirrors tried.

Co-Authored-By: Claude Opus 5 <[email protected]>
`{path}` in an `FBUILD_DOWNLOAD_MIRRORS` entry expands to the registry-relative
path of the primary URL — everything after `/download/` on
`dl.registry.platformio.org` — so fbuild's public mirror of the PlatformIO
catalog, which preserves that layout, is reachable with one variable:

    FBUILD_DOWNLOAD_MIRRORS='https://fbuild.sfo3.digitaloceanspaces.com/{path}'

Off the registry there is no such path and `{path}` degrades to the file name,
the same value `{filename}` produces. `{filename}` and bare-base entries are
untouched.

`FBUILD_DOWNLOAD_MIRROR_FIRST` (truthy: anything but unset, empty, `0`,
`false`) moves the mirrors ahead of the primary URL. The primary stays in the
list as the last resort, each candidate keeps the full retry policy, every
candidate still lands under the primary's file name, and the
all-candidates-failed error still reports the primary URL's own failure plus
the mirrors tried.

Co-Authored-By: Claude Opus 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 6150964 and 3bf3630.

Files selected for processing: 3
  • crates/fbuild-packages-fetch/README.md
  • crates/fbuild-packages-fetch/src/downloader_mirror_tests.rs
  • crates/fbuild-packages-fetch/src/downloader_mirrors.rs
  • 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

Comment @coderabbitai help to get the list of available commands.

@zackees

zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

Filed #1798 for the three divergent truthy-env implementations noted in the PR body (per CLAUDE.md: "conflicting implementations get a research issue, not an inline winner"). This PR's mirror_first_requested follows the broadest of the three and should move to whatever #1798 picks.

@zackees

zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@zackees

zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@zackees

zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Review follow-up: a mirror entry naming both `{path}` and `{filename}` had
only `{path}` substituted and shipped the literal `{filename}` in the
request URL. Substitute both; a template naming one is unchanged, because
replacing the absent placeholder is a no-op, and a bare base URL still gets
the file name appended.

Co-Authored-By: Claude Opus 5 <[email protected]>
@zackees

zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@zackees

zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

CodeRabbit status: auto-review is disabled on this repository, and four manual @coderabbitai review triggers (08:57, 09:20, 09:22, 09:32 UTC) each came back "Review rate limited" — a CodeRabbit-side quota, not something this PR can resolve. No CodeRabbit review has been produced, so there are no CodeRabbit findings addressed here. Please re-trigger when the quota resets.

In its place I ran the repo's own /code-review checklist over the diff. Checks 1–5 (hardcoded board/MCU values, core-vs-platform placement, board JSON, MCU config JSON, orchestrator completeness) do not apply — this touches only fbuild-packages-fetch's mirror module, no board/MCU data and no platform code. Check 6 (bug scan) produced one finding, fixed in 3bf3630: a mirror template naming both {path} and {filename} expanded only {path} and shipped the literal {filename} in the request URL.

Two things I deliberately did not change, for the record:

  • download_file_with_progress_named unlinks the .part file on entry, so reordering candidates cannot mix bytes from two hosts into one archive — no new hazard from mirror-first.
  • primary_error.expect(...) keeps the pre-existing invariant (the candidate list is never empty, and index 0 is always attempted in both orders); turning that into a typed error is error-plumbing work outside this PR's scope.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026

Copy link
Copy Markdown

@zackees Understood. The four recorded attempts produced no CodeRabbit review, so there are no CodeRabbit findings to mark as addressed.

The fix in 3bf36300 and the two unchanged behaviors are your self-review results. I have not independently verified them.

I’ll request the current quota and reset time. I cannot schedule a review retry for later.


🧠 Learnings used
Learnt from: zackees
Repo: FastLED/fbuild PR: 1745
File: CLAUDE.md:0-0
Timestamp: 2026-10-26T06:55:05.188Z
Learning: Within repository "FastLED/fbuild": When reviewing duplicate implementations in FastLED/fbuild, distinguish conflicting behavior from identical behavior. Under CLAUDE.md Principles 2 and 7, treat behaviorally identical copies as a refactor, not a conflicting-implementation finding, whether documented or not. Exempt documented deliberate copies from that finding. For undocumented copies with observably different behavior whose correction requires a design decision, request a research issue that lists every copy with file and line references and explains the differences on real input, rather than choosing an implementation inline.

Your plan includes PR reviews subject to rate limits. More reviews will be available in 7 minutes.

@zackees
zackees added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit 194b78c Oct 30, 2026
28 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Oct 31, 2026
@zackees
zackees deleted the feat/download-mirror-path-template branch November 5, 2026 05:51
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