Skip to content

Commit e80b1f2

Browse files
authored
core,hub,heliopause,ignition: decouple signed bodies, single-pass export, slice synthesis, and HF LFS SHA-256 (#618)
Why: Four packaging, export, and download defects block shipping and updating large multi-rank model cores (such as TP8 and TP16 MoE models) and weaken download integrity: 1. Unverified Hugging Face tree-API LFS downloads and unsafe blob adoption: `fetch_tree_identities` in `flare/src/hub.rs` stores each Git-LFS entry's bare 64-hex `lfs.oid` SHA-256 digest in `FileIdentity.etag` without a `sha256:` prefix. Downstream verification (`content_digest`) requires a `sha256:` prefix so opaque HTTP ETags are not assumed to be digests, causing it to return `None` for every tree-API LFS entry and silently disabling SHA-256 verification on downloaded and cached LFS blobs. Separately, `Transport::adopt_complete` copies legacy blobs without locking `<key>.lock`, falls back to renaming over an existing complete blob on `AlreadyExists`, and writes `.adopt-*` temporary files that do not match the `.<key>.adopt-*` pattern reclaimed by `flare::download_cache`. 2. Monolithic 128 MiB `ProtectedCore` envelope limit: `helios/src/core/schema.rs` allows up to 1 GiB of reconstructed rank metadata across selected ranks (`MAX_SELECTED_RANK_METADATA`), yet `ProtectedCore` inlines every `SignedDeployment.body` and `SignedRank.body` into one `flare.manifest` tensor capped at `MAX_ENVELOPE = 128 MiB`, blocking publication of large multi-rank or multi-deployment cores. 3. Duplicate device-to-host weight reads, uncached staging collisions, and peak capture host RAM: `resolve_weight_payload` in `heliopause/src/export/capture.rs` reads every weight group from GPU memory twice (once in `scan_group_blocks` and again through `Root::insert_payload`), even on cache hits and `--no-weights` exports; `materialize_payload_spans` in `heliopause/src/export/core.rs` opens `rank-{rank}-{base}.payload` with `File::create`, truncating an already-pinned stable layer file in place when the same layer also has a `:tuned` group; and `ForwardCache.prepare_many` plus `capture_forwards` retain every compiled `BoundForward`, Dynamo guard tree, `StorageBackend` descriptor set, and loaded CUDA module across the entire catalog simultaneously. 4. Full weight re-downloads after minor layer-layout edits: removing, reordering, or renaming a weight tensor inside a layer payload changes that layer's `PayloadId` even when remaining tensor bytes are unchanged, causing `flare download` to re-download every shifted weight file over HTTP despite an earlier core for the same model being installed locally with its `PreparedWeightCatalog`. What changed: - Hugging Face LFS SHA-256 verification and adoption (`flare/src/hub.rs`): - Before: `FileIdentity` carried only `etag`; `content_digest` returned `None` for bare `lfs.oid` strings; `adopt_complete` wrote `.adopt-*` temporaries without locking `<key>.lock` and renamed over existing complete blobs. - After: Added `sha256: Option<[u8; 32]>` to `FileIdentity`, populated from `entry.lfs.oid` via `parse_sha256_hex` in `fetch_tree_identities` and from `content_digest(&etag)` in HTTP probes (keeping opaque HTTP ETags unassumed). Updated `pending_network_from_identities`, `fetch_file_with_identity_and_streams`, and `transfer_blob_with_streams` to verify against `metadata.sha256()`. Updated `Transport::adopt_complete` to take a non-blocking exclusive lock on `<key>.lock` and call `publish_copy(..., replace = false)` so existing complete blobs are never replaced, with collectible temporary names `.<key>.adopt-<pid>-<n>`. - External signed deployment and rank bodies (`helios/proto/core.proto`, `helios/src/core/{protection,reader,export,cache,conversion}.rs`, `helios/src/core/conversion/edit.rs`, `helios/src/runtime_core/{protection,metadata}.rs`, `heliopause/src/export/weight_reuse.rs`, `flare/src/{cache_support,trust,hub}.rs`, `flare-cli/src/orbit/controller.rs`, `docs/core-format-design.md`, `docs/runtime-core-design.md`): - Before: `SignedDeployment` and `SignedRank` always stored protobuf bytes inline inside `flare.manifest` (`<= 128 MiB`), and `export.rs` buffered `model.safetensors` in a single `Vec<u8>`. - After: Added `ExternalBody { sha256, stored_nbytes, decoded_nbytes }`, `SignedDeployment.external_body`, and `SignedRank.external_body` backed by deduplicated `flare.body.<sha256>` U8 tensors in `model.safetensors` (single-frame zstd level 3, window `<= 8 MiB`, stored and decoded lengths each `<= 128 MiB`, mutually exclusive with inline `body`). `EnvelopeBuilder::sign_envelope` keeps envelopes `<= 128 MiB` inline and spills deployment/rank bodies when inline serialization would exceed 128 MiB, preserving `flare-package-signature-v5` Ed25519 signatures and parent commitments over exact decoded bytes. `verify_metadata` and `verify_with_bodies` enforce the 1 GiB `MAX_SELECTED_RANK_METADATA` cap before decompressing external bodies or compressed weight catalogs and check compressed SHA-256 before decompression. `export.rs` streams `model.safetensors` directly to disk. Updated cache, conversion, edit, unverified inspection (enforcing the aggregate cap before decompressing selected ranks), `--reuse-weights`, Hub/trust verification, and Orbit `mirrored_ranges`. - Compatibility: Inline v2 cores load and verify unchanged without re-export or re-signing; cores whose inline envelope fits within 128 MiB continue to be emitted inline. - Single-pass weight capture, uncached staging fix, and streaming capture (`helios/src/core/cache.rs`, `heliopause/src/export/{capture,core}.rs`, `ignition/preparation/{aot,capture}.py`, `tests/preparation/test_preparation_reclamation.py`): - Before: Cached weight capture read GPU spans twice (`scan_group_blocks` plus `insert_payload`); uncached export used `File::create` on `rank-{rank}-{base}.payload`; `ForwardCache.prepare_many` and `capture_forwards` held all live `BoundForward` objects and full `StorageBackend` metadata simultaneously. - After: Added `Root::verified_payload` and `Root::capture_streaming_payload` (reserving a 4,096-byte prefix, hashing and streaming in one pass, discarding staging on verified hits, or backfilling the deterministic companion header at offset 0 on misses) and wired single-pass `capture_group_into_cache` in `heliopause/src/export/capture.rs`. Named uncached staging files `rank-{rank}-{stable|tuned}-{base}.payload` with `create_new(true)`. Added `DeferredCompiledForward`, `StorageBackend.retire_after_capture()` (stripping `_bound`, `inputs`, `signature`, `invocations`, `_serialized_artifact`, `artifact`, and `cubin_raw` while preserving `_cuda_allocation_sizes` and retaining loaded `StaticallyLaunchedTritonKernel` and native library owners), and `stream=True` in `ForwardCache.prepare_many` / `_prepare_many` / `_prepare_ranks`; `capture_forwards` holds the publication lock and materializes, captures, and retires one forward at a time when `retain_forwards=False`. - Local slice-level weight synthesis (`helios/src/core/synthesis.rs`, `helios/src/core/{mod,cache}.rs`, `flare/src/hub.rs`): - Before: `plan_acquisition_with` only reused exact cached `PayloadId`s and in-core derivations. - After: Added model-agnostic slice synthesis in `helios/src/core/synthesis.rs`, invoked by `Root::plan_acquisition_for_model`. For missing remote weight or tuned-weight payloads, planning leases installed donor entries for the same model (skipping conflicting non-empty `checkpoint_revision`s and preferring matching revisions and `(tensor_parallel, rank)`), matches target `PreparedWeightCatalog` views by exact layout or declared checkpoint `sources`, handles zero-elided donor subranges and bounded (`<= 64 KiB`) alignment gaps, coalesces contiguous copy/zero segments, probes 3 representative payloads early when `> 8` candidates exist, and streams 8 MiB chunks across up to 16 parallel workers with Linux `posix_fadvise` and `AcquisitionProgress` accounting and cancellation. Synthesized blobs are published and removed from `remote_files()` only on exact SHA-256 match against the target's signed `PayloadId`; any gap or mismatch falls back to HTTP download. Claimed benefit and observed result: - Expected impact on large-TP workflows: removes the 128 MiB envelope limit for multi-rank/multi-deployment cores up to the 1 GiB aggregate rank budget, cuts cached and `--no-weights` GPU weight D2H passes from two to one, bounds peak unretired compiled forwards during capture to one per rank, and avoids re-downloading shifted weight layers when a compatible prior core is installed locally. End-to-end multi-GPU export memory and download throughput on live checkpoints are not measured here. - Observed in CPU tests: tree-API LFS blobs are verified by `lfs.oid` SHA-256 and `adopt_complete` locks `<key>.lock`, preserves existing blobs, and writes reclaimable temp files; external-body envelopes spill and verify a 3-rank ~138 MiB core under the default 128 MiB limit while rejecting tampering, dual bodies, trailing zstd bytes, and >1 GiB declarations before decompression; `capture_group_into_cache` reads each source block once across cold misses, warm hits, and `--no-weights` hits (with zero staging transactions under `--no-weights`); mixed stable+tuned uncached groups publish distinct intact companions; streamed `prepare_many` and `capture_forwards` collect each warmed forward before loading the next and maintain peak live unretired forwards at 1; and end-to-end Hub downloads synthesize shifted weight layers with zero HTTP requests for the shifted layer and fall back to HTTP on weight mutations. Evidence and limitations: Validated on Linux x86_64 (CPU fixtures, `ulimit -l unlimited`): - `helios --lib -- core:: runtime_core::`: 496 passed, 0 failed, 12 ignored. - `helios --lib` (full): 1,724 passed, 45 ignored, 6 failed (all 6 require `FLARE_TEST_TEMPLATE_DIR`). - `helios --test unverified_empty`: 1 passed, 0 failed. - `flare` (lib + `packed_canonical_download` + `reference_workflows`): 245 passed, 0 failed, 4 ignored. - `heliopause --lib`: 213 passed, 0 failed, 6 ignored. - `flare-cli` (`cache_commands`, `cli`, `inspect`, `unverified_payload`, release build): 24 passed, 0 failed; release binary built cleanly. - `flare-cli --bin flare`: 201 passed, 3 ignored, 1 failed (unrelated pre-existing failure in untouched `distribution::tests::source_waits_for_receiver_file_verification`). - `eos` (2 passed), `selene` (548 passed), `selene-manager` (187 lib + 3 builder + 82 client passed; 3 unrelated pre-existing failures in untouched `selene-manager/tests/client.rs` TCP/TLS loopback relay tests). - Python: `tests/cli` (133 passed), `tests/test_design_review_hook.py` (18 passed), targeted `tests/preparation` (56 passed), `tests/preparation/test_runtime_static_triton.py` standalone (28 passed), full `tests/preparation` (1,148 passed, 74 CUDA-gated skipped; 2 environment failures from shared-process CUDA init and preinstalled `.venv` wheel mismatch), `tests/test_compilation.py` (43 CUDA-gated skipped). Limitations: CUDA-gated GPU capture/export tests (`FLARE_RUN_CUDA_TESTS=1`, `FLARE_RUN_TP_CUDA_TESTS=1`), `FLARE_TEST_TEMPLATE_DIR` frontend template tests, rebuilt `flare_heliopause` wheel tests, and Windows builds were not run. Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b Signed-off-by: Luke Alonso <lalonso@gmail.com>
1 parent 968ca41 commit e80b1f2

23 files changed

Lines changed: 4784 additions & 399 deletions

File tree

‎docs/core-format-design.md‎

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ writer fills the gaps with tensors whose names carry the reserved prefix
178178

179179
| File | Tensor | Contents |
180180
| --- | --- | --- |
181-
| `model.safetensors` | `flare.manifest` | U8-encoded core envelope, signed shared body, deployment bodies, and rank bodies. |
181+
| `model.safetensors` | `flare.manifest` | U8-encoded core envelope (`ProtectedCore`), signed shared body, and inline or external references to deployment and rank bodies. |
182+
| `model.safetensors` | `flare.body.<sha256>` | Optional single-frame zstd-compressed `DeploymentBody` or `RankBody` records spilled from `flare.manifest`, keyed by lowercase hex SHA-256 of the compressed frame. |
182183
| `model.safetensors` | `flare.locations` | U8-encoded unsigned physical locations and locally available deployment selections. |
183184
| `model.safetensors` | `flare.derivations` | Optional U8-encoded bounded byte-copy/fill recipes for reconstructing signed payloads. |
184185
| `model.safetensors` | `frontend.tokenizer`, `frontend.chat-template` | Referenced frontend payloads; format and interpretation come from signed frontend metadata. |
@@ -251,13 +252,21 @@ form includes its decoded byte length; both forms together are invalid.
251252
Exporters use compression when it reduces the encoded size. Readers accept
252253
both forms. Rank signatures authenticate compressed bytes
253254
before catalog decoding. Decoding requires an exact length, a window no larger
254-
than 8 MiB, and one complete frame without trailing bytes. Reconstructing a
255-
rank's inline metadata must fit within 128 MiB; selected ranks together must
256-
fit within 1 GiB. The signed envelope limit is 128 MiB. Keyless
257-
container conversion preserves compressed catalogs without decoding them.
258-
Verification checks the size bounds for all selected ranks before decoding
259-
any catalog. Consumers decode one catalog at a time; verified rank records
260-
retain the compressed form.
255+
than 8 MiB, and one complete frame without trailing bytes. Reconstructing a rank's inline metadata must fit within 128 MiB; selected ranks
256+
together must fit within 1 GiB. The `flare.manifest` envelope limit is 128 MiB.
257+
When inlining all deployment and rank bodies would exceed 128 MiB,
258+
`SignedDeployment.external_body` and `SignedRank.external_body` store those
259+
bodies in deduplicated `flare.body.<sha256>` tensors inside `model.safetensors`
260+
as single zstd level-3 frames (window no larger than 8 MiB, stored and decoded
261+
lengths each bounded by 128 MiB, no trailing bytes). Inline `body` and
262+
`external_body` are mutually exclusive on a given record. Verification checks
263+
the 1 GiB aggregate limit across selected ranks before decompressing external
264+
bodies or compressed weight catalogs, verifies each external body's compressed
265+
SHA-256 before decompression, and verifies the Ed25519 signature and parent
266+
commitment over the exact decoded protobuf bytes. Keyless container conversion
267+
preserves external bodies and compressed catalogs without decoding them.
268+
Consumers decode one catalog at a time; verified rank records retain the
269+
compressed form.
261270

262271
An unchanged checkpoint tensor may contribute several affine byte pieces to a
263272
retained owner, including expert concatenation and scale swizzles:
@@ -432,7 +441,10 @@ not allocator placement. Elided bytes reconstruct as zero through allocation
432441
initialization. Stable group ordering, overlap resolution, and elision rules are
433442
part of the packing contract. State bytes and their elision are independent of
434443
stable weight ordering. Disk payload grouping does not require separate GPU
435-
allocations for each group.
444+
allocations for each group. Cached weight capture reads each group's device
445+
bytes in a single pass, streaming non-zero blocks directly into the cache's
446+
deterministic 4,096-byte-prefixed companion wrapper (and validating installed
447+
blobs on disk in a single scan without staging writes under `--no-weights`).
436448

437449
## Tensor-parallel deployments and materialization
438450

@@ -591,10 +603,13 @@ content-addressed complete blobs, resumable `.part` files, quarantined suspect
591603
bytes, transient adoption copies, per-content transfer locks, and repository
592604
refs and snapshot hardlinks.
593605
Blob content is scoped by endpoint and repository so Hub ETags are never shared
594-
across repositories; revisions of one repository share content. An acquisition
595-
lease excludes reclamation for the lifetime of every acquisition. The tree is
596-
separate from the model cache and survives across acquisitions for
597-
cross-revision reuse.
606+
across repositories; revisions of one repository share content. Tree-API LFS
607+
transfers carry each entry's `lfs.oid` SHA-256 digest explicitly so complete
608+
cached and downloaded LFS blobs are verified by SHA-256; blob adoption locks
609+
the content key exclusively, never replaces an existing complete blob, and uses
610+
collectible temporary names. An acquisition lease excludes reclamation for the
611+
lifetime of every acquisition. The tree is separate from the model cache and
612+
survives across acquisitions for cross-revision reuse.
598613
A successful installation reclaims its resolved commit's snapshot entries and
599614
the consumed complete blobs whose last hardlink they held. Failed partials,
600615
quarantined suspect bytes, and content referenced by another commit remain.
@@ -623,6 +638,18 @@ strides, not asserted by an untrusted flag. Only injective copied regions can be
623638
inverted; fills cannot recover a source. Composed mappings must cover every
624639
requested source byte and remain within the same operation and depth bounds.
625640

641+
When required weight or tuned-weight payloads are missing from the cache and
642+
not satisfied by in-core derivations, acquisition planning also checks
643+
installed cores for the same model whose `PreparedWeightCatalog` views match
644+
the target payload's views (by exact view layout or declared checkpoint
645+
`sources`, prioritizing matching `checkpoint_revision` and skipping conflicting
646+
non-empty revisions). When installed donor views cover a target weight payload
647+
completely, workers coalesce contiguous donor byte ranges and zero-elided
648+
spans, stream them into a deterministic payload wrapper, and publish the
649+
synthesized blob into `blobs/` only if its SHA-256 equals the target's signed
650+
`PayloadId`. Incomplete coverage, probe failure on large batches, or any digest
651+
mismatch falls back to normal remote download without failing acquisition.
652+
626653
Progress reports network bytes, local source reads, materialized bytes,
627654
verification work, and elapsed acquisition time separately. Performance targets
628655
apply to the complete acquire-and-ready path, including verification and writes.

‎docs/runtime-core-design.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,11 @@ controllers must speak the same agent protocol version (`PROTOCOL_VERSION` in
501501
before files are sent.
502502
Resource classification follows actual consumers in the signed index. Missing,
503503
overlapping, unclassified, or incorrectly classified spans fail loading. The
504-
128 MiB metadata limit applies to the complete signed envelope and to each reconstructed rank body.
505-
The verifier accepts up to 1 GiB of reconstructed metadata across the selected ranks and checks
506-
the aggregate before decoding compressed weight catalogs. The core
504+
128 MiB metadata limit applies to `flare.manifest`, to each spilled
505+
`flare.body.<sha256>` external body record (stored and decoded), and to each
506+
reconstructed rank body. The verifier accepts up to 1 GiB of reconstructed
507+
metadata across the selected ranks and checks that aggregate bound before
508+
decompressing external bodies or compressed weight catalogs. The core
507509
contains the signing-key fingerprint, not the verification key. Keys come from
508510
Helios's embedded publisher profiles or explicitly supplied profile files.
509511

‎flare-cli/src/orbit/controller.rs‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2140,6 +2140,25 @@ fn mirrored_ranges(header: &Value, size: u64, start: u64) -> Result<Vec<(u64, u6
21402140
if ranges.is_empty() {
21412141
return Err("not a Flare core".into());
21422142
}
2143+
if let Some(map) = header.as_object() {
2144+
let mut external_total = 0u64;
2145+
for name in map.keys() {
2146+
if name.starts_with(flare_helios::core::reader::EXTERNAL_BODY_PREFIX)
2147+
&& let Some(range) = bounded(name)?
2148+
{
2149+
if range.1 > flare_helios::core::schema::MAX_BODY as u64 {
2150+
return Err(format!("{name} external body exceeds its limit"));
2151+
}
2152+
external_total = external_total
2153+
.checked_add(range.1)
2154+
.ok_or("external metadata body length overflow")?;
2155+
if external_total > flare_helios::core::schema::MAX_SELECTED_RANK_METADATA {
2156+
return Err("external metadata bodies exceed budget".into());
2157+
}
2158+
ranges.push(range);
2159+
}
2160+
}
2161+
}
21432162
Ok(ranges)
21442163
}
21452164
_ => Err("not a Flare core".into()),
@@ -3264,10 +3283,14 @@ mod tests {
32643283
"flare.manifest": {"dtype": "U8", "shape": [10], "data_offsets": [0, 10]},
32653284
"flare.locations": {"dtype": "U8", "shape": [20], "data_offsets": [10, 30]},
32663285
"flare.derivations": {"dtype": "U8", "shape": [5], "data_offsets": [30, 35]},
3286+
"flare.body.0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef": {
3287+
"dtype": "U8", "shape": [15], "data_offsets": [35, 50]
3288+
},
3289+
"weights.layer-000": {"dtype": "U8", "shape": [100], "data_offsets": [50, 150]},
32673290
});
32683291
assert_eq!(
32693292
mirrored_ranges(&payload, 1000, 8).unwrap(),
3270-
vec![(8, 10), (18, 20), (38, 5)]
3293+
vec![(8, 10), (18, 20), (38, 5), (43, 15)]
32713294
);
32723295

32733296
let packed = json!({

‎flare/src/cache_support.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ fn select_verified_deployments(
166166
> {
167167
use flare_helios::core::protection;
168168

169-
let catalog = protection::verify(
170-
&metadata.envelope,
169+
let catalog = protection::verify_metadata(
170+
metadata,
171171
publishers,
172172
protection::Selection::Catalog,
173173
)?;

0 commit comments

Comments
 (0)