Skip to content

feat(prebuilt): wire the #1882 serving ladder into the ESP32 framework-libs stage (consumer + policy plumbing) #2196

Backlog

Description

@zackees

Why

#1882 delivered the prebuilt serving ladder — identity/fingerprint, prebuilt::obtain/tree_root, prebuilt::serve (decision enum + one retry), prebuilt::lru pruning, staging GC, deterministic prebuilt::pack behind the hidden fbuild __prebuilt-pack. All of it is verified in-tree and none of it is reachable from a build: nothing calls obtain/serve, so no artifact can ever be served, and --no-prebuilt-libs has no effect on what gets fetched.

Verified on origin/main a7394a52 (2026-11-27):

  • git grep -n "fetches_prebuilt_libs()" -- '*.rs' → only crates/fbuild-build-engine/src/prebuilt.rs lines 126/134, i.e. that function's own unit tests. Nothing in the build path consumes the policy.
  • git grep -n "prebuilt::" -- 'crates/' → exactly one production hit, crates/fbuild-cli/src/cli/prebuilt_notice.rs:25 (the PrebuiltPolicy type for the notice line).
  • The only production constructor of variants::FetchRequest is crates/fbuild-library/src/library/esp32_framework/libs.rs:253, and it carries {name, version, url, variant} only. Decision 1 requires "an explicit PrebuiltLibsPolicy field on FetchRequest"; that field does not exist, so the opt-out cannot change selection — the per-chip slice in the @esp-libs shard is still what every ESP32 build downloads.

Consequence: the last plan cell of #1882 (the cold/warm benchmark hook, decision 6) is unmeasurable today — with no consumer, the "prebuilt" and "control" arms are the same code, and a published ratio would be unfalsifiable. That is why the hook is not being written before this issue.

Scope (additive; no workflow files, no new crate)

  1. Carry the decision explicitly. Add the prebuilt policy to the build request on both sides (crates/fbuild-cli/src/daemon_client/types.rs and crates/fbuild-daemon/src/models.rs, #[serde(default)] so old clients keep working) and forward it into the ESP32 packages stage. The daemon must never read its own environment for this — decision 1's rationale is that it does not inherit the caller's env.
  2. Honour it in the fetch layer. Add the PrebuiltLibsPolicy field to variants::FetchRequest and skip the slice branch in select() when prebuilt libs are disabled, so the opt-out selects the mirrored whole bundle (or the request URL) instead of the chip slice. This is decision 1's named mechanism and makes the flag's help text true.
  3. Consult the ladder before compiling framework libs. In the ESP32 packages stage, resolve the framework term/fingerprint (esp32_framework::prebuilt_core) and ask prebuilt::serve. Served::Prebuilt → use that tree; Served::Source → compile from source exactly as today. A ladder failure must never fail a build.
  4. Record the decision in build_info.json as prebuilt_libs: {used, source, key, sha256} per decision 1, so any firmware can be traced to the archive or tree it linked against.
  5. One honest line. Reuse Served::Source(reason)'s notice so a fallback is reported once, and make --no-prebuilt-libs's line describe what now actually happens.

Acceptance criteria

  • RED → GREEN: with a local HTTP fixture serving a published slice and a published prebuilt tree, a build with the ladder consulted uses the served tree and issues no compile of the covered units; remove the call and the same test fails.
  • With prebuilt libs disabled, the fetch layer selects the whole bundle and never the slice (assert the selected URL and that no @esp-libs slice key is used).
  • Any ladder error (transport, integrity, foreign marker, unsafe entry) falls back to source with exactly one notice line and a successful build.
  • A served-tree build and a from-source build of the same cell produce byte-identical framework archives (the #2192 rule: assert reused == fresh, not just entry names).
  • build_info.json carries the four prebuilt_libs fields, and a source build records used: false.
  • Existing gates: prebuilt:: unit suite, fbuild-packages-fetch lib suite, boundary rows=0; dylint_rows=0, fmt/dylint clean.

Unblocks

#1882's remaining plan cell (the cold/warm benchmark hook, decision 6). That hook needs this consumer: it measures cold_first_compile_wall_s with prebuilt libs against the source arm in the same job, and a ratio without a real control arm is unfalsifiable.

Activity

  1. added
    enhancement
    on Nov 27, 2026
  2. zackees commented on Nov 27, 2026

    @zackees
    MemberAuthor

    Cells 1, 2 and 5 are shipped as PR #2197 (agent/2196-prebuilt-consumer, head a4500186, unmerged). Cells 3 and 4 are untouched — this is the plumbing the ladder needs before it can be consulted, not the consultation itself. #2196 stays open.

    What #2197 changes, per cell:

    1. Carry the decision explicitly — BuildParams::prebuilt_libs (fbuild_build::prebuilt::PrebuiltPolicy); CLI BuildRequest::prebuilt_libs and daemon models::BuildRequest::prebuilt_libs are Option<String> with #[serde(default)] and the policy's stable spelling (disabled/libs/core). The daemon parses the request, never its own environment. dispatch now resolves the policy once and both reports it and forwards the same value (before, it was reported and dropped).
    2. Honour it in the fetch layer — variants::PrebuiltLibsPolicy { Slices, WholeBundle } is a field on FetchRequest; select() refuses the slice branch under WholeBundle, so the request resolves to the mirrored whole bundle (entry.urls[0]) or, with no entry, the vendor URL. fbuild-packages-fetch re-exports the type. The verdict reaches it via ensure_sdk_libs → Esp32Framework::ensure_libs → install_sdk_archive → FetchRequest.
    3. Consult the ladder before compiling framework libs — NOT in feat(prebuilt): make --no-prebuilt-libs change what is fetched (decision 1) #2197. prebuilt::serve still has no caller (git grep on the branch tip: only prebuilt/serve.rs and its tests).
    4. build_info.json prebuilt_libs {used, source, key, sha256} — NOT in feat(prebuilt): make --no-prebuilt-libs change what is fetched (decision 1) #2197; lands with 3, because used/key/sha256 are only meaningful once something can be served.
    5. One honest line — the --no-prebuilt-libs notice now reads "compiling framework libraries from source; the SDK download takes the whole published bundle instead of a pre-built per-chip slice", which is what the code does after this PR. Served::Source(reason)'s notice path is unchanged and still unused (blocked on 3).

    Acceptance evidence in #2197:

    • Cell 2 criterion — disabled_prebuilt_libs_select_the_whole_bundle_never_a_slice asserts the selected URL and that no slice/chip is selected, with the default-policy arm as its own control (https://bucket.example/slices/s3.tar.zst vs https://mirror.example/whole.tar.xz). RED-proven: removing the gate fails the test (assertion left == right failed), restoring it passes.
    • Cell 1 criterion — fbuild-daemon models tests cover an old-client body with no prebuilt_libs (→ None → default Libs) and the "disabled" spelling parsing to Disabled.
    • Suites: fetch lib 407 passed, daemon models 36 passed, cli prebuilt 7 passed, library esp32_framework::libs 17 passed, workspace cargo check --all-targets clean, boundary rows=0; dylint_rows=0.

    Still open for a later tick (unchanged by this comment): the fixture-served end-to-end acceptance test the issue asks for — select() is the decision point fetch() delegates to and is unit-tested both ways, but downloader_mirror_manifest::current() returns None under cfg!(test), so a manifest-driven fetch() test has to live in tests/it with FBUILD_MIRROR_MANIFEST_URL pointed at a local fixture. That belongs with cell 3, where a real Served::Prebuilt tree exists to compare against a from-source build.

  3. zackees commented on Nov 27, 2026

    @zackees
    MemberAuthor

    Cells 1, 2 and 5 landed.

    #2197 merged 2026-11-27T16:32:13Z -> main = 62e46674 (agent/2196-prebuilt-consumer):

    • cell 1: BuildRequest/BuildParams carry prebuilt_libs (#[serde(default)] on the wire), the daemon parses the request rather than its own env;
    • cell 2: variants::PrebuiltLibsPolicy { Slices, WholeBundle } on FetchRequest and the select() gate, so --no-prebuilt-libs selects the whole bundle and never the @esp-libs chip slice;
    • cell 5: the notice line now describes what actually happens.

    Remaining: cell 3 (consult prebuilt::serve in the ESP32 packages stage) and cell 4 (prebuilt_libs in build_info.json). Cell 3 is the one that makes the ladder reachable from a build and unblocks #1882's cold/warm hook; taking it next.

  4. zackees commented on Nov 27, 2026

    @zackees
    MemberAuthor

    Cell 3 shipped as PR #2199 (agent/2196-serve-consult, head 889a7267) — unmerged, awaiting review.

    What is now wired, on the request's own terms:

    • Fingerprint: Esp32Framework::prebuilt_core_plan gets its first production caller. CoreBuildInputs is built from the stamped framework term, one canonical argv per core unit (cache root / toolchain path replaced by placeholders, object path deliberately excluded — it carries the source's absolute path), and a pinned config-digest set: cores/<core>/Arduino.h, variants/<variant>/pins_arduino.h, <sdks>/<sdk_variant>/include/sdkconfig.h when the install ships one.
    • Query: framework = arduino-esp32, version = <core version>, arch = <mcu>, abi = <sdk variant>, fp = <fingerprint> — documented in the module so the packer can publish something a build will actually ask for.
    • Ladder: Reader::from_environment(cache_root).resolve then prebuilt::serve; Served::Prebuilt hydrates, everything else is one notice line and a source build.
    • Consumption: the tree carries objects.json mapping canonical unit ids (source path relative to the framework root) to the publisher's object file names, because this host's object names come from CompilerBase::object_path — which hashes the source's ABSOLUTE path, so ~/.fbuild under a different home directory yields a different name. Hydration resolves each id to the local source, computes this host's object path, and copies only manifest-named regular files there. A tree with no manifest, a newer schema, or one covering none of this build's units is refused.
    • Gate: PrebuiltPolicy::serves_core_objects() only (hidden --prebuilt-core); --no-prebuilt-libs/default never reach the network path.

    Evidence: 278 crate lib tests pass (6 new); the_ladder_serves_a_published_tree_and_it_is_hydrated runs a real loopback Index → Catalog → tar.zst and asserts both units hydrate to the paths the compiler derives with needs_rebuild == false. RED: neutering the copy step fails a_served_tree_hydrates_every_unit_it_covers. cargo fmt --check clean, boundary rows=0; dylint_rows=0.

    Remaining gap, stated plainly (cell 3b, publisher side): fbuild __prebuilt-pack packs an arbitrary objects tree and takes --fingerprint as an input; it does not write objects.json, nor the config/argv contract this client pins. Until the packer emits them (reusing the same helpers), no published artifact can be consumed — the ladder is reachable and proven end to end, but there is nothing in the bucket to serve. Cell 4 (prebuilt_libs: {used, source, key, sha256} in build_info.json) is unchanged and stays open, as does #1882's cold/warm hook.

  5. zackees commented on Nov 27, 2026

    @zackees
    MemberAuthor

    Receipt — cell 3 merged

    PR #2199 (agent/2196-serve-consult, 889a726) is on origin/main as 08e82b0 (merge-group 46053528374 SUCCESS, linux / Check 12039-line log with 0 soldr#3377, 0 test result: FAILED, retry never fired).

    The #1882 serving ladder now has its first production caller: the ESP32 packages stage builds a stamped fingerprint from the installed framework (component term + canonical per-unit argv + pinned config digests), queries the catalog (arduino-esp32/core version/mcu/sdk-variant/fp), calls prebuilt::serve, and on Served::Prebuilt hydrates the tree's compiled objects into the core build dir via an objects.json manifest (canonical unit id -> publisher object name). Every non-serve outcome — no identity, miss, transfer error, foreign marker, non-covering tree — is one log line and a source build, never a build error. Gated by hidden --prebuilt-core.

    Cells left on this issue:

    #2196 stays open; no close keyword.

  6. zackees commented on Nov 27, 2026

    @zackees
    MemberAuthor

    Cell 4 shipped as PR #2200 (agent/2196-build-info, 846a4f5, unmerged)

    build_info_<env>.json now carries the ladder decision per decision 1:

    "prebuilt_libs": {
      "used": true,
      "source": "https://…/core.tar.zst",
      "key": "arduino-esp32/3.3.12/esp32c3/fp-0123456789abcdef",
      "sha256": "…",
      "reason": null
    }
    • used: false for a source build, with the ladder's own reason (null when the hidden opt-in was off, so "never asked" and "asked and declined" stay distinguishable).
    • key is the identity the publisher uploads under — the same {framework}/{version}/{arch}/fp-<sha16> relative path prebuilt::tree_root extracts into.
    • Option<PrebuiltLibsRecord> with skip_serializing_if, following the shrink precedent: non-ESP32 platforms' JSON stays byte-identical; ESP32 always emits the block because shrink_link::emit_build_info's only caller always passes the record.

    Evidence: fbuild-build-engine lib 607 passed / 0 failed / 6 ignored; fbuild-build-esp lib 282 passed / 0 failed / 7 ignored (4 new prebuilt_core record tests); fmt clean; boundary rows=0; dylint_rows=0; RED proven by neutering with_prebuilt_libs (assertion left == right failed). All 43 checks on #2200 pass, mergeStateStatus: CLEAN (Dylint Full, LOC gate, Build fbuild included) — left unmerged for the owner.

    Cells left on #2196

    • 3b (publisher): fbuild __prebuilt-pack writes neither objects.json nor the pinned fingerprint inputs — still the one producer-side gap; no published tree is consumable until it lands.
    • Then #1882's cold/warm hook (decision 6) becomes measurable, since the arms are now distinguishable from build_info.json alone.

    #2196 stays open; no close keyword.

  7. zackees commented on Nov 27, 2026

    @zackees
    MemberAuthor

    Cell 3b shipped as PR #2201 (agent/2196-pack-manifest, 73eddd2, unmerged).

    Cell 3 left the ladder with no servable output: prebuilt_core::hydrate reads objects.json out of the served tree, and fbuild __prebuilt-pack wrote neither that manifest nor anything about the unit set — so any archive the builder could mint was unhydratable at the client, the exact gap named in the previous receipt.

    Now: prebuilt::pack requires and writes objects.json (schema: 1, units: {unit-id: object-file}, OBJECTS_MANIFEST/MANIFEST_SCHEMA exported), and refuses, before writing a byte, a unit naming an object the tree does not hold, a unit id/object name that could address a path outside the tree (.., absolute, C:, empty segment, control char), a duplicate unit id, and a tree that already carries a manifest. --units takes <unit-id><TAB><source-path> lines and the object name is derived with the same CompilerBase::object_path the client hydrates to — the names are not portable (they fold the source's own path in), which is why the id → name relation has to travel in the archive.

    Evidence: prebuilt:: 89/0 (manifest content, determinism, all refusal cases), prebuilt_core:: 11/0 including a new cross-crate test that packs with the real pack, extracts with the real extract and hydrates, fbuild-cli prebuilt 9/0 (manifest proven from the archive on disk), fmt clean, boundary rows=0; dylint_rows=0. RED-proven by neutering append_manifest → served tree has no objects.json.

    Remaining on this track: the fingerprint is still an input (--fingerprint), so a published artifact is not self-verifying — no producer emits the pinned fingerprint inputs; and the cold/warm bench hook #1882 still wants its last cell. Neither is in #2201.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions