Skip to content

Harden Orbit payload integrity, multi-deployment TP seams, GB10 page-cache release, Unix flock drop, and multi-host peer exports - #667

Merged
lukealonso merged 1 commit into
mainfrom
orbit-payload-integrity-gb10-page-ca
Dec 1, 2026
Merged

lukealonso merged 1 commit into
mainfrom
orbit-payload-integrity-gb10-page-ca

Conversation

@lukealonso

Copy link
Copy Markdown
Collaborator

Why this change is needed

Five defects affect Orbit core distribution, integrated-GPU KV cache sizing (#630), Unix file locking across fork(), and multi-host peer exports:

  1. Silent stale-weights execution on single-host Payload cores: orbit/controller.rs derived single-host Core.export from the primary filename stem (model.safetensors -> "model"), Grant.core omitted the signed core envelope digest, and orbit/agent.rs (have, transfer, run) resolved and reused cached entries solely by directory name (model-<len>) and file byte length. Two different single-host checkpoints sharing the same architecture and fixed-width manifest/layer byte lengths collided on model-<len>, causing have() and transfer() to return cache hits (received: 0, verified: false) and launch stale weights without transferring or verifying the updated checkpoint.
  2. Broken Orbit seams for multi-deployment Payload cores (e.g., TP1+TP2+TP4): VerifiedCore::open(..., None) rejects cores containing more than one deployment (helios/src/runtime_core/protection.rs). That broke four Orbit paths: agent.rs verify_core failed and deleted staged transfers after copying; publish_orbit_entry swallowed VerifiedCore::open errors via .ok(), recording [0u8; 32] envelopes without .flare-verified.json; ServingOptions::rank_options dropped --tensor-parallel; and agent::run started rank zero without --tensor-parallel (where trust::load_with cannot infer TP size because args.hosts is empty and args.rank is Some(0)).
  3. Residual Linux page cache collapsing unified-memory KV capacity on GB10 (GB10 unified memory: KV budget and cuCtxCreate respond to page-cache-polluted MemFree, not MemAvailable — same core+reserve gives 2.08M vs 3.43M KV tokens and spurious CUDA_ERROR_OUT_OF_MEMORY #630): flare-cli/src/distribution.rs never called release_page_cache after hashing primaries in sha256_file or streaming peer shards (~95 GiB/peer) in serve_source. Because rank zero's model loader never opens peer shard files, model.rs's Files::release_page_cache could not evict those peer pages before CUDA initialization and KV sizing. Buffered writes in core_cache.rs, agent::fetch, and payload hashing in protection.rs also left verified bytes in Linux page cache, and model.rs did not re-release page cache immediately after load_payload on integrated GPUs.
  4. Unix flock retention across fork(): helios::core::cache::Lock, helios::core::conversion::CoreLock, and raw locked File guards in flare (hub.rs, download_cache.rs, trust.rs) relied solely on closing the file descriptor without calling flock(LOCK_UN) in Drop. When another thread forked a child process (agent::run) before execve closed O_CLOEXEC descriptors, the inherited open file description kept the advisory lock held after the parent dropped its guard.
  5. Multi-host --no-weights cold/GC'd peer failure and orphan peer blob leaks: Remote peers running ignition join (ignition/preparation/host_ranks.py) captured into their local ~/.cache/flare/cores even though only rank zero commits a model entry. Normal multi-host exports leaked 40-100+ GiB of unreferenced blobs into each peer's cache, and --no-weights failed on cold or GC'd peers because capture_group_into_cache required cached weight blobs locally on the peer instead of deferring cache validation to rank zero's coordinator cache.

What changed

  • Orbit envelope binding and multi-deployment TP selection (flare-cli/src/orbit/{grant,controller,agent}.rs, flare-cli/src/cli.rs, flare-cli/src/launch.rs):
    • Before: Grant.core carried only export, length, files, and source; single-host describe() set export to the sanitized primary stem; verify_core and publish_orbit_entry called VerifiedCore::open(..., None); ServingOptions::rank_options and agent::run omitted --tensor-parallel.
    • After: Added #[serde(default)] envelope_digest: [u8; 32] and #[serde(default)] tensor_parallel: Option<u32> to Grant.core (preserving compatibility with existing grants lacking these fields). Single-host describe() appends the first 8 bytes (16 hex chars) of authorized.envelope_digest() to export. Controller HAVE requests carry envelope_digest; agent.rs checks SourceRef::expected_envelope() across have(), transfer(), fetch(), and run(), refuses unverified staging hits in have() when an envelope is bound, and verifies signed core metadata envelopes before spawning flare run. Added open_verified_core to dispatch Payload cores with tensor_parallel to VerifiedCore::open_tensor_parallel, returned VerifiedCoreMeta directly from verify_core to publish_orbit_entry, forwarded --tensor-parallel in ServingOptions::rank_options, deduplicated saved vs. CLI --tensor-parallel in Controller::run (feeding saved values to resolve_core), and emitted --tensor-parallel <tp> once in agent::run.
  • Page-cache release (eos/src/{unix,windows}.rs, helios/src/lib.rs, helios/src/runtime_core/{model,protection}.rs, flare-cli/src/{distribution,core_cache}.rs, flare-cli/src/orbit/agent.rs):
    • Before: sha256_file, serve_source, Source teardown, store_parallel, store_partial, agent::fetch, and hash_payload did not release Linux page cache; model.rs released page cache only before GPU init and before allocate_caches.
    • After: Added release_page_cache_range in eos and re-exported release_page_cache and release_page_cache_range from helios. Added page-cache release in sha256_file, per transferred range in serve_source, across all deduplicated peer Arc<File> handles during Source teardown, after sync_all() in store_parallel and store_partial, after range reads in agent::fetch, after each hashed payload in protection.rs, and immediately after load_payload on integrated GPUs in model.rs.
  • Explicit Unix flock(LOCK_UN) on drop (helios/src/core/{cache,conversion}.rs, flare/src/{file_lock,lib,hub,download_cache,trust}.rs):
    • Before: helios::core::cache::Lock, CoreLock, and raw File locks in flare had no Unix Drop unlock.
    • After: Implemented Unix Drop calling libc::flock(fd, libc::LOCK_UN) on Lock and CoreLock, and added a shared cross-platform RAII flare::file_lock::FileLock replacing raw File locks in hub.rs, download_cache.rs, and trust.rs.
  • Multi-host peer export caching (heliopause/src/export/{mod,capture,transfer}.rs, ignition/preparation/{core_snapshot,runtime_core,host_ranks}.py):
    • Before: host_ranks.py exported remote peers into their local core_cache and enforced --no-weights locally on the peer.
    • After: Added ExportOptions.remote_cache (default false). Remote peers in host_ranks.py now capture into a transient peer-cache inside NativeExportStage with remote_cache=True and release core before native_stage.close(), reclaiming all transient peer blobs immediately after transfer. Under no_weights && remote_cache, capture_group_into_cache hashes weight groups in one pass and records them in WeightPayloadSources.cached without local cache lookup; rank zero's receive_rank validates their presence and length in the coordinator cache while keeping zero payload reads.
  • Compatibility: No model core wire format or Protobuf schema changes. Existing cores load without re-export, and legacy Orbit grants without envelope_digest or tensor_parallel continue to deserialize cleanly.

Claimed benefit and result

  • Distinct single-host Payload cores sharing model.safetensors and identical file lengths can no longer collide in Orbit caches or silently launch stale weights.
  • Multi-deployment Payload cores verify, publish with real non-zero envelopes and .flare-verified.json markers, and launch rank zero with --tensor-parallel across Orbit and --hosts.
  • Releasing page cache for peer shard reads, verification hashing, transfers, and integrated-GPU payload loading is expected to eliminate the residual GB10 KV collapse reported in GB10 unified memory: KV budget and cuCtxCreate respond to page-cache-polluted MemFree, not MemAvailable — same core+reserve gives 2.08M vs 3.43M KV tokens and spurious CUDA_ERROR_OUT_OF_MEMORY #630 (not yet re-measured on GB10 hardware).
  • Dropping cache, trust, and download-transport locks releases Unix flock immediately even while a concurrently forked child holds an inherited descriptor pre-execve.
  • Multi-host --no-weights exports work on cold or GC'd peers, and normal multi-host exports leave zero orphan weight blobs on peer hosts.

Supporting evidence and limitations

All Rust suites were run with --locked --release:

  • cargo test --locked --release --manifest-path eos/Cargo.toml --target-dir flare-cli/target: 12 passed, 0 failed.
  • cargo test --locked --release --manifest-path helios/Cargo.toml --features runtime-core,server --target-dir flare-cli/target --lib -- core:: runtime_core::: 507 passed, 0 failed, 12 ignored (GPU/hardware-gated), including lock_drop_releases_flock_even_with_duplicate_descriptor.
  • cargo test --locked --release --manifest-path flare/Cargo.toml --target-dir flare-cli/target: 246 unit + 8 integration passed, 0 failed, 4 ignored, including file_lock::tests::drop_releases_flock_even_when_duplicate_descriptor_stays_open.
  • cargo test --locked --release --manifest-path flare-cli/Cargo.toml: 219 unit + 26 integration passed, 0 failed, 3 ignored (4 consecutive full runs), including:
    • cli::cache_cli_tests::rank_options_forward_tensor_parallel
    • orbit::controller::tests::single_host_describe_derives_distinct_exports_from_envelope_digest
    • orbit::agent::tests::envelope_digest_blocks_stale_single_host_cache_hits_and_wrong_weights
    • orbit::agent::tests::multi_deployment_payload_core_verifies_publishes_and_launches_rank_zero_with_tp
  • cargo test --locked --release --manifest-path heliopause/Cargo.toml --target-dir flare-cli/target: 229 passed, 0 failed, 6 ignored (CUDA-gated), including capture_group_into_cache_reads_source_once_for_miss_hit_and_no_weights (with cold-peer remote_cache=true coverage) and remote_no_weights_peer_reuses_coordinator_cache_and_rejects_missing_or_corrupt.
  • Python CPU suites:
    • pytest tests/cli tests/preparation/test_core_boundary.py -q: 140 passed.
    • pytest tests/preparation -q -k "host_ranks or core_snapshot or export": 94 passed, 8 skipped (CUDA-gated).

Limitations and unrun checks:

Related: #630

Discord: lukealonso

…cache release, Unix flock drop, and multi-host peer exports

Why this change is needed:
Five operational defects remain in Orbit core distribution, integrated-GPU
memory reclamation (#630), Unix file locking across `fork()`, and multi-host
peer export caching:

1. Silent stale-weights execution on single-host Payload cores:
   `orbit/controller.rs` derived single-host `Core.export` from the primary
   filename stem (`model.safetensors` -> `"model"`), `Grant.core` omitted the
   signed envelope digest, and `orbit/agent.rs` (`have`, `transfer`, `run`)
   keyed and reused cached entries solely by directory name (`model-<len>`) and
   file byte length. Two different single-host checkpoints sharing the same
   architecture and fixed-width manifest/layer byte lengths collided on
   `model-<len>`, causing `have` and `transfer` to report cache hits and launch
   stale weights without transferring or verifying the updated checkpoint.
2. Broken Orbit seams on multi-deployment Payload cores (e.g., TP1+TP2+TP4):
   `VerifiedCore::open(..., None)` rejects cores with more than one deployment,
   causing `orbit/agent.rs` `verify_core` to fail and delete staged transfers,
   `publish_orbit_entry` to swallow metadata errors via `.ok()` and record a
   zeroed `[0u8; 32]` envelope without `.flare-verified.json`,
   `ServingOptions::rank_options` to omit `--tensor-parallel`, and rank zero
   launches under `agent::run` to start without `--tensor-parallel` (where
   `trust::load_with` cannot infer TP size because `args.hosts` is empty and
   `args.rank` is `Some(0)`).
3. Residual page-cache pressure on unified-memory GPUs such as GB10 (#630):
   `distribution.rs` never released Linux page cache after hashing primaries in
   `sha256_file` or streaming peer shard files (~95 GiB/peer) in `serve_source`.
   Because rank zero's model loader never opens peer shard files, `model.rs`
   could not evict those pages before CUDA context creation and KV sizing.
   Buffered writes in `core_cache.rs`, `agent::fetch`, and payload hashing in
   `protection.rs` likewise left verified bytes in page cache, and `model.rs`
   did not re-release page cache immediately after `load_payload` on integrated
   GPUs.
4. Unix `flock` retention across `fork()`:
   `helios::core::cache::Lock`, `helios::core::conversion::CoreLock`, and raw
   locked `File` guards in `flare` (`hub.rs`, `download_cache.rs`, `trust.rs`)
   had no `Drop` implementation calling `flock(LOCK_UN)`. When another thread
   forked a child process (`agent::run`) before `execve` closed `O_CLOEXEC`
   descriptors, the inherited open file description kept the advisory lock held
   after the parent dropped its guard.
5. Multi-host `--no-weights` peer failure and orphan peer blob leaks:
   Remote peers running `ignition join` (`host_ranks.py`) captured into their
   local `~/.cache/flare/cores` even though only rank zero commits a model
   entry. Normal multi-host exports leaked 40-100+ GiB of unreferenced blobs
   into each peer's cache, while `--no-weights` failed on cold or GC'd peers
   because `capture_group_into_cache` required cached weight blobs locally on
   the peer rather than deferring verification to rank zero's coordinator cache.

What changed:
- Orbit envelope binding and multi-deployment TP selection
  (`flare-cli/src/orbit/{grant,controller,agent}.rs`, `flare-cli/src/cli.rs`,
  `flare-cli/src/launch.rs`):
  - Before: `Grant.core` carried only `export`, `length`, `files`, and
    `source`; single-host `describe()` set `export` to the sanitized primary
    stem; `verify_core` and `publish_orbit_entry` called
    `VerifiedCore::open(..., None)`; `ServingOptions::rank_options` and
    `agent::run` omitted `--tensor-parallel`.
  - After: Added `#[serde(default)] envelope_digest: [u8; 32]` and
    `#[serde(default)] tensor_parallel: Option<u32>` to `Grant.core` (backward
    compatible with earlier grants). Single-host `describe()` appends the first
    8 bytes (16 hex chars) of `authorized.envelope_digest()` to `export`.
    Controller `HAVE` sends `envelope_digest`; `agent.rs` checks
    `SourceRef::expected_envelope()` in `have()`, `transfer()`, `fetch()`, and
    `run()`, ignores unverified staging hits in `have()` when an envelope is
    bound, and verifies metadata envelopes before spawning `flare run`.
    `open_verified_core` dispatches Payload cores with `tensor_parallel` to
    `VerifiedCore::open_tensor_parallel`; `verify_core` returns
    `VerifiedCoreMeta` directly to `publish_orbit_entry`; `rank_options`
    forwards `--tensor-parallel`; `Controller::run` deduplicates saved vs. CLI
    `--tensor-parallel`; and `agent::run` emits `--tensor-parallel <tp>` once.
- Page-cache release (`eos/src/{unix,windows}.rs`, `helios/src/lib.rs`,
  `helios/src/runtime_core/{model,protection}.rs`,
  `flare-cli/src/{distribution,core_cache}.rs`, `flare-cli/src/orbit/agent.rs`):
  - Before: `sha256_file`, `serve_source`, `Source` teardown, `store_parallel`,
    `store_partial`, `agent::fetch`, and `hash_payload` left buffered I/O in
    Linux page cache; `model.rs` released page cache at lines 618 and 917 only.
  - After: Added `release_page_cache_range` in `eos` (re-exported with
    `release_page_cache` from `helios`). Called `release_page_cache` /
    `release_page_cache_range` in `sha256_file`, `serve_source`, `Source`
    worker teardown (deduplicated across all peer file handles),
    `store_parallel` and `store_partial` after `sync_all()`, `agent::fetch`,
    `hash_payload`, and immediately after `load_payload` on integrated GPUs in
    `model.rs`.
- Explicit Unix `flock(LOCK_UN)` on drop (`helios/src/core/{cache,conversion}.rs`,
  `flare/src/{file_lock,lib,hub,download_cache,trust}.rs`):
  - Before: `Lock`, `CoreLock`, and raw `File` locks in `flare` relied solely on
    descriptor close.
  - After: Added Unix `Drop` calling `libc::flock(fd, libc::LOCK_UN)` on
    `helios::core::cache::Lock` and `CoreLock`, and introduced shared RAII
    `flare::file_lock::FileLock` used across `hub.rs`, `download_cache.rs`, and
    `trust.rs`.
- Multi-host peer export caching (`heliopause/src/export/{mod,capture,transfer}.rs`,
  `ignition/preparation/{core_snapshot,runtime_core,host_ranks}.py`):
  - Before: `host_ranks.py` exported peers into their persistent `core_cache`
    with local `--no-weights` cache checks.
  - After: Added `ExportOptions.remote_cache` (default `false`). Remote peers
    in `host_ranks.py` capture into a transient `peer-cache` inside
    `NativeExportStage` with `remote_cache=True` and drop `core` before
    `native_stage.close()`, reclaiming all transient peer blobs after transfer.
    Under `no_weights && remote_cache`, `capture_group_into_cache` hashes
    weight groups in a single pass and places them in
    `WeightPayloadSources.cached` without local cache lookup; rank zero's
    `receive_rank` checks existence and length in the coordinator cache while
    keeping zero payload reads.

Claimed benefit and result:
- Distinct single-host Payload cores with identical filenames and sizes no
  longer collide or launch stale weights in Orbit.
- Multi-deployment Payload cores verify, publish with real envelope digests and
  `.flare-verified.json` markers, and launch rank zero with the selected
  `--tensor-parallel` size across Orbit and `--hosts`.
- Peer shard distribution, verification hashing, and integrated-GPU weight
  loading are expected to keep Linux page cache reclaimed on unified-memory
  GPUs such as GB10 so KV cache sizing retains full available memory (#630).
- Dropping cache/trust/hub locks releases Unix `flock` immediately even across
  concurrent `fork()` calls.
- Multi-host `--no-weights` exports succeed on cold or GC'd peers, and normal
  multi-host exports leave zero orphan weight blobs on peer hosts.

Supporting evidence and limitations:
- Release CPU unit and integration tests (`--locked --release`):
  - `eos`: 12 passed, 0 failed.
  - `helios` (`--features runtime-core,server --lib -- core:: runtime_core::`):
    507 passed, 0 failed, 12 ignored (GPU/hardware-gated), including
    `lock_drop_releases_flock_even_with_duplicate_descriptor`.
  - `flare`: 246 unit + 8 integration passed, 0 failed, 4 ignored, including
    `file_lock::tests::drop_releases_flock_even_when_duplicate_descriptor_stays_open`.
  - `flare-cli`: 219 unit + 26 integration passed, 0 failed, 3 ignored (4
    consecutive full runs), including
    `rank_options_forward_tensor_parallel`,
    `single_host_describe_derives_distinct_exports_from_envelope_digest`,
    `envelope_digest_blocks_stale_single_host_cache_hits_and_wrong_weights`,
    and
    `multi_deployment_payload_core_verifies_publishes_and_launches_rank_zero_with_tp`.
  - `heliopause`: 229 passed, 0 failed, 6 ignored (CUDA-gated), including
    `capture_group_into_cache_reads_source_once_for_miss_hit_and_no_weights`
    and
    `remote_no_weights_peer_reuses_coordinator_cache_and_rejects_missing_or_corrupt`.
- Python tests: `tests/cli` and `tests/preparation/test_core_boundary.py` (140
  passed); `tests/preparation -k "host_ranks or core_snapshot or export"` (94
  passed, 8 CUDA-gated skipped).
- Limitations: Live multi-host GB10 KV sizing (#630), multi-host CUDA/RoCE
  exports (`FLARE_RUN_CUDA_TESTS=1` / `FLARE_RUN_TP_CUDA_TESTS=1`), and
  `helios` chat-template tests (`FLARE_TEST_TEMPLATE_DIR`) were not run on this
  host.

Design-Signed-Off-By: Antigravity (Gemini); design-review=2e5b
Signed-off-by: Luke Alonso <lalonso@gmail.com>
@flare-autobot

Copy link
Copy Markdown
Collaborator

A case file has been opened for 667.
Case File Intake Report

Future reviews will auto-run 90 minutes after code updates are pushed.

  • Re-review sooner: Call @flare-autobot after push.
  • Opt-out: Include #autobot:ignore in the PR or any comment.

@flare-autobot flare-autobot added area:caching Prefix/KV reuse, cache retention, and model or payload cache behavior. area:orbit Orbit host agents, orchestration, and package-cache management. area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. bug Something isn't working performance Performance, latency, throughput, or memory-efficiency investigation or improvement. priority:P2 Normal bug priority: workflow failure or diagnosis with narrower impact or an available workaround. triage:review Proposed change needs code review; this does not imply merge readiness. labels Dec 1, 2026
@flare-autobot

Copy link
Copy Markdown
Collaborator

Autobot Review

Full Review · Value Proposition · Case File

Recommendation: Changes Requested

All five fixes are sound — envelope binding closes the single-host cache collision, multi-deployment TP routing, flock(LOCK_UN) drop semantics, post-sync_all() page-cache release, and peer export capture all verify clean (several upstream candidate alarms were false positives). Before merging, fix the remaining .ok() identity swallow, remove the dead contextlib import plus add a Python test for the remote_cache plumbing, refresh the stale peer-cache docs, and clarify the single-host cache-miss upgrade impact and unmeasured #630 status.

  • Blockers: 0 · Should fix: 4 · Subtract/Simplify: 3 · Nits: 3
Walkthrough
  • Orbit envelope binding & multi-deployment TP seams (flare-cli/src/orbit/{grant,controller,agent}.rs, cli.rs, launch.rs): #[serde(default)] envelope_digest/tensor_parallel on Grant.core, 8-byte digest prefix in single-host export names, envelope matching enforced across HAVE/TRANSFER/FETCH/RUN, Payload cores dispatched to VerifiedCore::open_tensor_parallel, VerifiedCoreMeta returned from verify_core to publish_orbit_entry, --tensor-parallel forwarded/deduplicated for saved groups and rank launches.
  • Linux page-cache eviction (eos/src/{unix,windows}.rs, helios/src/{lib,runtime_core/{model,protection}}.rs, flare-cli/src/{distribution,core_cache,orbit/agent}.rs): New eos::release_page_cache_range (POSIX_FADV_DONTNEED, no-op on Windows) invoked after sha256_file, serve_source, Source teardown, store_parallel/store_partial (post-sync_all()), agent::fetch, protection.rs payload hashing, and post-load_payload on integrated GPUs.
  • Explicit Unix flock(LOCK_UN) on drop (flare/src/{file_lock,lib,hub,download_cache,trust}.rs, helios/src/core/{cache,conversion}.rs): Cross-platform RAII flare::file_lock::FileLock replaces ~200 lines of duplicated lock helpers; #[cfg(unix)] Drop calls libc::flock(fd, LOCK_UN) on helios::core::cache::Lock and CoreLock.
  • Multi-host transient peer cache & coordinator-side --no-weights (heliopause/src/export/{mod,capture,transfer}.rs, ignition/preparation/{core_snapshot,runtime_core,host_ranks}.py): ExportOptions.remote_cache added; peer exports moved into a transient native_stage.path / "peer-cache" reclaimed in finally after releasing core; remote --no-weights weight groups hashed in one pass without local cache lookup and validated against rank zero's coordinator cache.
Merge Risk: Medium · up to 7908ac3
Pre-merge checks: ✅ 2 passed · ⚠️ 2 warnings

Have your agent review the Full Review for complete verified findings, file:line citations, and suggested changes.

To opt out, include #autobot:ignore in your post or comment.

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

Labels

area:caching Prefix/KV reuse, cache retention, and model or payload cache behavior. area:orbit Orbit host agents, orchestration, and package-cache management. area:preparation Ignition checkpoint loading, tuning, compilation, capture, and export. bug Something isn't working performance Performance, latency, throughput, or memory-efficiency investigation or improvement. priority:P2 Normal bug priority: workflow failure or diagnosis with narrower impact or an available workaround. triage:review Proposed change needs code review; this does not imply merge readiness.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants