PR #628: helios: gate offload Copy Engine batches during peer-copy graphs

Raw Markdown for agents: https://autobot.eidonix.com/api/v1/cases/23a7b4eb-552e-446e-8f0e-4474f4cd4042

Opened by a workflow run, Nov 29, 2026 9:42 PM EST.

Classify draft

Selected: priority:P1, bug, performance

Threshold: 65%

Priority

Type

Area

Model

explore

Author: yatesdr (COLLABORATOR; owner of the Selene host prefix-cache tiers, 80 merged PRs in 180 days); Discord D-Rock Motivation: On SM120 PCIe GPUs, tensor-parallel CUDA graphs whose collectives move data peer-to-peer through in-graph Copy Engine nodes deadlock when prefix-cache offload workers submit concurrent host-device Copy Engine batches on the same devices. This PR adds a per-model lock that pauses offload batches while such a graph runs. Scale: +572 / −72 lines in 14 files Proposal:

Full report · Notes

Classify intake

Selected: triage:review, priority:P1, bug, performance

Threshold: 65%

Triage

Priority

Type

Area

Model

Value Proposition

Value Proposition — PR #628 helios: gate offload Copy Engine batches during peer-copy graphs

Verdict: Worth it with changes

Charter alignment. The change lands in Helios (scheduling/offload), not in recipes, carries no per-model branch, adds no flag, and changes no Protobuf or package format — so it respects the runtime-vs-recipes split (#267/#334) and the "smallest footprint in shared code" rule. It targets SM120 PCIe workstations, the charter's stated focus, and fixes a reproducible P1 deadlock (#627), the class of change the charter says gets merged. Two tensions are real: the fix coordinates around the Copy Engine conflict rather than root-causing it — #627's own ablation shows serializing offload against itself still deadlocked — which sits uneasily with #397; and it inverts a documented invariant (docs/prefix-cache-offload.md:133, 907, 1015 promise the model stream never waits on offload, but RankExecutor::submit now blocks until in-flight batches drain), with no docs/ file in the changed set. "Bring real evidence" (#210) is only half met: the performance label rests on "main deadlocks, patched completes 40/40" with no logs attached, and the new per-batch record+synchronize cost on every prefix-cache offload path is unmeasured — notably the path #497 just retuned for restore latency.

Novelty & status. Genuinely additive. No competing or duplicate PR; nothing on main describes the deadlock; #348 and #151 are different failures. It builds on the author's own KV-codec series and reverses nothing from #497. It is one rebase behind main and will textually collide with open #621 in helios/src/execution/manifest.rs.

Value vs maintenance cost. Benefits accrue to anyone running threaded single-host TP with prefix cache over PCIe peer copies — a narrow but real slice of the supported matrix, validated live at TP2 with clean correctness numbers (0/6 and 0/96 token mismatches; 8/8 bursts at 4.68–4.83 s). The author is the subsystem's effective owner (~80 merged PRs in 180 days, nearly all offload-tier work: #80, #92, #141, #168, #415, #429, #504–#527), so maintenance risk is low. But the ~263-line gate plus RAII leases is more machinery than current evidence justifies: coverage is asymmetric (offload/shard.rs:47 ungated; Heliopause-built manifests pass peer_copy_graphs: Vec::new()), detection misses kernel-driven DMA and peer-mapped local allocations, multi-host per-process ranks get per-process gates, and CI failed on the head commit with all test results asserted in prose only.

Before merge: update the offload and same-process-TP docs to state the new blocking contract; measure per-batch sync cost and peer-graph wait latency against main; attach test/CI evidence and green CI; state explicitly which layouts remain unprotected; rebase over #621.

No prompt-injection attempts were present in the supplied PR, issue, or dossier material.

Full report

Apply Labels (Intake)

Applied: +triage:review Decide Value: yes (100%): This change is worth reviewing: it provides value to the project in line with its charter.

Correctness and contracts

PR #628 (helios: gate offload Copy Engine batches during peer-copy graphs) is a coherent, model-agnostic, package-compatible fix, and its graph-submission path is correct. Six concrete issues remain.

  1. Major — reversed documented invariant, unbounded block. CopyEngineGate::enter_peer_graph loops on a condvar with no timeout (helios/src/offload/copy_gate.rs:45-56) on the model worker thread inside RankExecutor::submit (helios/src/execution/ranks.rs:90-101). docs/prefix-cache-offload.md:133/907/1015 promise offload never blocks that thread; docs/same-process-tp.md:177-180 names this region "Not qualified". The engine's 120 s stall detector (threaded.rs:942-952) cannot fire while submit is parked.
  2. Major — offload starvation with a warm-path cost. enter_offload_batch waits while any peer graph is active or waiting (copy_gate.rs:60-67); TP decode graphs qualify, so sustained serving can starve offload entirely, jobs refuse at QUEUE_DEPTH (transfer.rs:641-645) and stores are abandoned at peak load.
  3. Major — metric/rate span expanded. Gate wait is counted in codec transform_ns (codec.rs:283,290,302; :664,668,688; :749,752,769) and in submit→reply elapsed feeding tier rates (transfer.rs:754 → selene/src/memory.rs:1452,1455) that price admission via worth_fetching (selene/src/store.rs:441), persisted by a 3-sample median (levels.rs:57-68). Contended restores depress the advertised rate and can make the cache decline hits during prefill.
  4. Major — gated paths untested. Every test builds Copiers::new (gate None); transfer.rs:398-434, codec.rs:976-1002 and the five GPU-codec acquire sites never run under test, and no test covers lease release via poll/close.
  5. Major — claims narrower than code. "Zero gate overhead" holds only for graph submission, since the gate is attached unconditionally (model.rs:1032-1038, server/runtime.rs:731) and transfer.rs:398-434 now syncs per 16 MiB batch (unmeasured, against #497's direction). offload/shard.rs:47 is ungated and heliopause/src/python.rs:331 disables detection.
  6. Minor — the batch lease is acquired while holding the shared gpu.codec mutex (codec.rs:666-668, :751-752), serializing other ranks' codec work; and peer_copy_graphs is never length-validated (manifest.rs:436-449), so a short vector silently disables the gate.

Sound: fence-ordered release, no guard leak on backpressure, correct index alignment, real backward compatibility, consistent lock ordering, correct drain-before-release.

Open: which CI job failed; unmeasured per-batch cost; whether Memory::Peer detection covers all real peer transfers; multi-host/pool/CPU-codec/non-SM120 untested.

Full report · Notes

Subtraction and simplicity

Reviewed PR #628 for subtraction/simplicity/conventions. The diff is lean overall — no new flag, env var, CLI option, Protobuf or serde change, no dependency; the new offload/copy_gate.rs duplicates no existing repo abstraction and has no speculative generality. Four things can still go:

  1. HIGH helios/src/offload/transfer.rs:398-428 — a struct DrainOnDrop declared inside the batch loop with a body identical to the pre-existing RankWorker::drain() (transfer.rs:440-444), plus the whole copy_batch call and its SAFETY comment duplicated into an else arm; codec.rs:976-1001 repeats the same gated/ungated split a third time. One small copy_batch_gated(stream, event, gate, dsts, srcs, lens) helper removes ~40 lines, three SAFETY comments and both duplicated arms; keep drain() for the ungated end-of-job path (do not use it on the success path, which must propagate record/synchronize errors).
  2. HIGH helios/src/execution/manifest.rs:445-449 — has_peer_copies is dead public API: its only non-definition uses are its own three assertions at ranks.rs:198-200, while the real check is re-spelled inline at ranks.rs:90. Delete one or the other, not neither.
  3. MEDIUM helios/src/execution/ranks.rs:126-168 — the new RankExecutorInner wrapper made five pure-delegation methods regrow a 4-line match &self.inner; move those matches into impl RankExecutorInner and reduce each outer method to self.inner.park() etc. Only submit/poll/close need the wrapper.
  4. LOW helios/src/offload/mod.rs:26 — OffloadBatchGuard is never named outside its own module; drop it from the re-export.

Convention note: helios/src/offload/transfer.rs:17-19 still says "The model stream never waits on these streams", which the per-batch synchronize and the model-thread wait in enter_peer_graph contradict (cf. docs/prefix-cache-offload.md:133 (not opened)); that in-file sentence is fixable here.

Checked and rejected: a bool on GraphDescriptor (would churn ~40 test literals), a copy_gate field on RankCodec (blocked by &mut borrows at the try_lock sites), removing offload::open or Copiers::new (pre-existing pub API / 15 test callers). Open: the unmeasured per-batch sync cost on every prefix-cache run, and which CI job failed on head.

Full report · Notes

Final review

Recommendation: Changes Requested

The structural peer-copy detection, RAII gate primitives, strict gpu.codec → CopyEngineGate lock ordering, GPU-codec stream drains, and executor.close()-before-store.close() shutdown sequence are cleanly engineered and target a real SM120 P1 deadlock (#627) without breaking existing exported cores. However, head 1870a27 introduces indefinite offload starvation under pipelined TP decode (freezing both inbound restores and pinned outbound checkpoint unpins), unconditionally adds per-16 MiB blocking event.synchronize() overhead to every prefix-cache deployment including single-GPU/non-peer-copy runs without benchmark evidence, and has a failing CI run with incomplete release/lifecycle verification gates.

Merge Risk

Level: High

Walkthrough

Pre-merge Checks

Blockers

  1. Indefinite offload starvation under pipelined / sustained peer-copy graphs freezes both inbound restores and pinned GPU checkpoints (helios/src/offload/copy_gate.rs:60-67, helios/src/execution/ranks.rs:90-124, helios/src/execution/threaded/protocol.rs:23-38, helios/src/server/runtime.rs:1170-1181, selene/src/memory.rs:1463-1489).

    • Verified behavior & impact: enter_offload_batch blocks whenever peer_graphs_active > 0 || peer_graphs_waiting > 0 with strict peer-graph priority and no aging or fairness window. ThreadedExecutor permits 2-frame pipelining (pending.len() < 2) for Decode/Speculative graphs (protocol.rs:28), and Worker::run executes executor.poll() (runtime.rs:1170) and self.submit() (runtime.rs:1180) in the same loop iteration. When two peer-copy decode frames are pipelined, completing frame $N$ only drops peer_graphs_active from 2 to 1 and frame $N+2$ immediately bumps it back to 2—so peer_graphs_active never reaches 0 for the entire duration of active generation (and even at depth 1, submit() re-acquires peer_graphs_waiting microseconds after poll() notifies). Because selene/src/memory.rs:1463-1489 keeps queued windows pending while in_flight_jobs() > 0, outbound captures keep GPU checkpoints pinned indefinitely (blocking page reclamation) and newly arriving requests with prefix-cache hits have their store.fetch restores starved until all active decode finishes—turning prefix-cache hits into unbounded TTFT head-of-line blocking.
    • Concrete fix: Add bounded fairness/aging to CopyEngineGate (e.g., track offload_batches_waiting and allow waiting offload batches—prioritizing inbound restores or draining one window after $N$ consecutive peer graphs / $T$ ms—to take a turn before admitting the next peer-copy graph, temporarily pausing pipelining at that boundary so peer_graphs_active reaches 0), and add a unit test proving offload makes bounded forward progress under a continuous 2-frame pipelined peer-graph stream.
  2. Unconditional per-16 MiB blocking event.synchronize() on every prefix-cache deployment (including single-GPU and non-peer-copy models) without benchmark evidence (helios/src/runtime_core/model.rs:662, 986-989, 1032-1038, helios/src/server/runtime.rs:719-731, helios/src/offload/transfer.rs:398-434, helios/src/offload/transfer/codec.rs:978-1028, helios/src/cuda.rs:169).

    • Verified behavior & impact: NativeModel unconditionally passes Some(Arc::clone(&self.copy_gate)) to Binding::new and Copiers::with_gate even when zero graphs in any rank have peer-copy nodes (all single-GPU runs and non-peer-copy TP runs). As a result, RankWorker::run and copy_spans_batch always execute the gated branch: acquiring a mutex and calling stream.record(&event) + blocking event.synchronize() every BATCH_BYTES (16 MiB, cuda.rs:169) instead of once per window (transfer.rs:431-434, codec.rs:1025-1028). A 1 GiB checkpoint window becomes 64 blocking host-GPU syncs instead of 1, contradicting the PR's claim of "zero gate overhead on graphs without peer-copy nodes" and risking a restore-latency regression against #497 with no measured offload throughput/latency comparison.
    • Concrete fix: Only wire Some(Arc::clone(&self.copy_gate)) when at least one rank has a peer-copy graph (self.ranks.iter().any(|r| r.has_any_peer_copy_graphs())); pass None otherwise so single-GPU and non-peer-copy models stay on the ungated single-sync fast path. For peer-copy models where the gate is active, attach an A/B offload capture/restore latency measurement against main (or remove the performance label and document the measured per-batch sync overhead).
  3. CI failed on head 1870a27 and mandatory release/lifecycle verification gates were not run in full (docs/design-review.md:180-186, 234-251, .github/workflows/native-serving.yml:63 (not opened), .github/workflows/helios-lifecycle.yml:34 (not opened), 47).

    • Verified behavior & impact: The case file records CI as failed on 1870a27, and the PR Validation section reports cargo check plus narrow test filters (offload::copy_gate, execution::ranks, server::runtime, execution::threaded) rather than the full cargo test --locked --release --manifest-path helios/Cargo.toml (not opened) --features runtime-core,server suite and verification/helios-lifecycle/check.py (not opened) / cargo kani gates triggered by helios/**.
    • Concrete fix: Fix the CI failure on head, run the full --locked --release crate test suites and helios-lifecycle.yml checks per docs/design-review.md, and ensure GitHub Actions is green before merge.

Should Fix

  1. Unbounded Condvar::wait on the model worker thread bypasses the 120 s stall detector and contradicts documented offload invariants (helios/src/offload/copy_gate.rs:45-56, helios/src/execution/ranks.rs:90-101, helios/src/execution/threaded.rs:23, 942-952, helios/src/offload/transfer.rs:14-19, docs/prefix-cache-offload.md:133, 907, 1015, docs/same-process-tp.md:177-180).

    • Verified behavior & impact: CopyEngineGate::enter_peer_graph loops on self.changed.wait(state) with no timeout on the serving worker thread inside RankExecutor::submit, before inner.submit runs. ThreadedExecutor::poll_ranks's TIMEOUT = 120s deadline cannot trigger while the worker thread is parked in submit, so a wedged offload CUDA copy turns a prefix-cache failure into a permanent silent serving hang. Meanwhile, helios/src/offload/transfer.rs:14-19 and docs/prefix-cache-offload.md:133, 907, 1015 still promise "Offload work never blocks the model worker thread or the model stream" and docs/same-process-tp.md:177-180 leaves the qualification list unupdated.
    • Concrete fix: Use a bounded Condvar::wait_timeout in enter_peer_graph (returning an explicit Result<PeerGraphGuard> error/diagnostic if an offload batch fails to drain within a bound aligned with TIMEOUT), and update helios/src/offload/transfer.rs:14-19, docs/prefix-cache-offload.md:133, 907, 1015, and docs/same-process-tp.md:177-180 to document the bounded peer-copy coordination contract.
  2. Gate wait duration distorts KV codec transform metrics, Selene tier bandwidth rates (worth_fetching admission pricing), and prefill_rate (helios/src/offload/transfer/codec.rs:283-302, 315-335, 349-369, 664-688, 749-769, helios/src/server/metrics.rs:686-690, helios/src/offload/transfer.rs:652, 754, selene/src/memory.rs:1451-1457, selene/src/levels.rs:34, 57-75, selene/src/store.rs:424-442, helios/src/server/runtime.rs:2293-2295, 2353, 2646-2657).

    • Verified behavior & impact:
      • All five GPU-codec timing sites in codec.rs capture let start = Instant::now() before enter_offload_batch(), attributing gate wait time to flare_kv_codec_transform_nanoseconds_total (metrics.rs:686-690).
      • Transfers::absorb reports elapsed: pending.started.elapsed() (transfer.rs:754), which now includes arbitrary gate pauses. MemoryStore::absorb feeds that directly into inbound_rate/outbound_rate (selene/src/memory.rs:1452, 1455), a 3-sample median (levels.rs:57-68) with a 10 s doubling recovery (levels.rs:34, 69-75). Contended restores depress inbound_rate, causing worth_fetching (store.rs:441) to reject worthwhile prefix-cache hits during busy bursts.
      • Conversely, Worker::submit pushes Instant::now() into self.prefill_started (runtime.rs:2293-2295) before executor.submit() (runtime.rs:2353), so blocking in enter_peer_graph() also depresses self.prefill_rate (runtime.rs:2646-2657).
    • Concrete fix: Move let start = Instant::now() after _ce acquisition in all five codec.rs sites; track cumulative gate wait time per job/rank and subtract it from Reply.elapsed (or report it separately) so Rate::observe measures actual transfer throughput; and record prefill_started after executor.submit() (or after acquiring PeerGraphGuard).
  3. Zero test coverage of gated offload copy paths and RankExecutor lease lifecycle (helios/src/offload/gpu_tests.rs:126 (not opened), 286, 456, 588, 650, 856, 1004, 1266, 1271, 1558, helios/src/offload/transfer.rs:1507, 1850, helios/src/offload/transfer/codec.rs:1129, 1133, 1249, 1359, 1363, helios/src/execution/ranks.rs:108-124, 170-181).

    • Verified behavior & impact: Every test in gpu_tests.rs (not opened), transfer.rs, and codec.rs calls Copiers::new(...) (copy_gate = None), so the new gated copy/sync/drain-on-drop branches in transfer.rs:398-428 and codec.rs:978-989 and all five GPU-codec gate acquisitions are completely unexercised by tests. Likewise, ranks.rs:189 only tests merge_peer_copy_graphs, leaving RankExecutor's fence-ordered poll() release and close() cleanup untested.
    • Concrete fix: Add at least one test driving Copiers::with_gate(..., Some(gate)) (verifying that holding PeerGraphGuard defers offload batches until dropped, and verifying stream drain before gate release on error) plus a RankExecutor lifecycle test verifying PeerGraphGuard release on poll() completion and close().
  4. Multi-host peer ranks (serve_rank + offload::shard::join_peer) remain ungated (helios/src/offload/shard.rs:47, flare-cli/src/cluster.rs:254, flare-cli/src/main.rs:559-561, helios/src/execution/parallel.rs:546-685).

    • Verified behavior & impact: Multi-host peer ranks run serve_rank directly on GraphExecutor (bypassing RankExecutor) and construct Copiers::new(gpu_cubins) in shard::join_peer, so neither their local graph submissions nor their disk-store transfers touch CopyEngineGate.
    • Concrete fix: Either wire CopyEngineGate into shard::join_peer and serve_rank for per-process rank coordination, or explicitly document in the PR description and offload docs that CopyEngineGate covers only single-host threaded TP (RankPeers::Threads) and does not protect multi-host peer ranks.

Subtract / Simplify

  1. Deduplicate DrainOnDrop / Fence and three copies of unsafe { stream.copy_batch(...) } (helios/src/offload/transfer.rs:398-428, 440-444, helios/src/offload/transfer/codec.rs:966-1001): RankWorker::run defines a nested struct DrainOnDrop inside the batch loop whose Drop body repeats RankWorker::drain() (transfer.rs:440-444), and both transfer.rs:398-428 and codec.rs:976-1001 duplicate the entire gated/ungated copy_batch + SAFETY block. Extract one crate-visible copy_batch_gated(stream, event, gate, dsts, srcs, lens) helper so both call sites collapse to one line while preserving record/synchronize error propagation on success and drain-before-gate-release on error.
  2. Delete dead public method ExecutionManifest::has_peer_copies (helios/src/execution/manifest.rs:445-449, helios/src/execution/ranks.rs:90, 198-200): has_peer_copies has zero production callers—its only references are three assertions in this PR's own test (ranks.rs:198-200), while RankExecutor::submit (ranks.rs:90) spells .get(graph).copied().unwrap_or(false) inline on the merged Vec<bool>. Delete the unused method and its test assertions.
  3. Move pure-delegation match &self.inner methods onto RankExecutorInner (helios/src/execution/ranks.rs:126-168): park, outstanding, manifest, can_submit, and next_fence do not touch copy_gate or peer_guards; moving the variant matches into impl RankExecutorInner reduces RankExecutor to one-line forwarding and trims ~20 lines of diff churn.

Nits

  1. Remove unused OffloadBatchGuard from the re-export at helios/src/offload/mod.rs:26—no call site outside copy_gate.rs names the type.
  2. Validate self.peer_copy_graphs.is_empty() || self.peer_copy_graphs.len() == self.graphs.len() in ExecutionManifest::validate() (helios/src/execution/manifest.rs:436-449) so a truncated vector cannot silently leave higher-indexed graphs unprotected.

Dropped on verification

Full report Decision to Test: no (100%): Testing will not add significant value as the code stands today. The code is either not yet ready to merge, or adequate testing has already been done to validate the contents of the code, or the available hardware is not suitable to test with.

Classify triage

Selected: triage:review

Threshold: 65%

Triage

Apply labels

No label changes decide malicious: all_clear (100%): No malicious content found

explore

Author: yatesdr (COLLABORATOR; owner of the Selene host prefix-cache tiers, 80 merged PRs in 180 days); Discord D-Rock Motivation: Tensor-parallel prefill graphs that shuffle data directly GPU-to-GPU over PCIe could deadlock on SM120 cards when the prefix-cache offload worker was copying at the same time. The PR adds a lock that makes the two take turns; commit 76e1813 then answers the bot review by scoping the lock to models that actually contain such peer copies, adding a 120 s bound and fairness turns, and updating the docs. Scale: +1,165 / −154 lines in 19 files (was +572/−72 in 14 files at 1870a27) Proposal:

Full report · Notes

Classify intake

Selected: triage:review, priority:P1, bug, performance

Threshold: 65%

Triage

Priority

Type

Area

Model

Apply Labels (Intake)

No label changes

Value Proposition

Value Proposition — PR #628 "helios: gate offload Copy Engine batches during peer-copy graphs"

1. Charter alignment — in scope, right layer. The PR fixes #627, a TP2 prefill deadlock on discrete PCIe SM120 GPUs (the project's named target hardware) caused by host-device Copy Engine batches racing in-graph peer copies. It adds no recipes, aliases, backends, or per-model branches: detection is structural (Node::Copy with a Memory::Peer endpoint) and sits in Helios scheduling/offload/caches, with package format and Protobuf contract unchanged. Counterweight: a new 584-line copy_gate.rs threaded through five codec sites, both rank loops, and Selene pool wiring is a large addition to the very layer the charter asks to keep small.

2. Novelty & status — genuinely additive. #627 reproduces on unpatched main ("deadlocked during the first burst"); the dossier shows no merged fix and no competing open PR, so it is neither obsolete nor superseded. Five of the seven earlier bot findings were closed at 76e1813. Engagement is still bot-plus-author: no human review, no inline comment, no reaction.

3. Value vs maintenance cost. Beneficiaries are concrete — anyone serving prefix-cache offload on PCIe SM120 tensor-parallel — and evidence is strong for that one configuration: live TP2 Qwen3.8-Flash-Next and GLM-5.3-Flash runs with warm/restart restores (5.08x/2.45x, 3.50x/1.55x), 8-way bursts, 40/40 HTTP 200 where main deadlocked. It is weak where the charter is strictest: no A/B offload latency and no gate-cost figure (#210), and the root cause stays partly uncharacterised since cross-rank mutex serialization still deadlocked (#397). Gated verification is CI-invisible (#[ignore], two-GPU-only), and the author states the gated tests plus A/B measurement were not run on 76e1813 — so the newly gated multi-process, CPU-codec, Selene and multi-host paths have no runtime evidence.

Remaining risks are shared-runtime, not nits. Fairness depends on RankExecutor::can_submit (ranks.rs:181-184), but serve_rank takes the lease without it (parallel.rs:652-656), so offload can starve on RankPeers::Processes — the layout this same commit newly gates (cluster.rs:254-261 → shard.rs:47-61). A 120 s Drain propagates through Worker::submit into worker.fail_all and executor teardown (runtime.rs:2332-2339, 759-776), letting a stuck offload batch kill the served worker, undocumented. Docs promise a "bounded in-flight 16 MiB batch" drain while leases cover codec compute under gpu.codec (codec.rs:288-303,318-338,748-780). Gate wait is subtracted from Reply.elapsed and feeds Selene worth_fetching, unvalidated.

Verdict: Worth it with changes. The bug is fatal, reproducible, in-scope and unfixed elsewhere; the layer is right. Required before merge: honour the drain check in serve_rank (or scope the gate to RankPeers::Threads), degrade on gate timeout instead of failing the worker, correct the documented drain scope, run the gated codec/transfer tests plus one multi-process SM120 run, and supply A/B offload latency and gate-cost measurements per #210.

Full report Decide Value: yes (100%): This change is worth reviewing: it provides value to the project in line with its charter.

Subtraction and simplicity

Subtraction/Simplicity/Conventions review of PR #628 (head 76e1813, 19 files, +1,165/−154). The diff is mostly lean and its refactors are net-negative-line, but four slabs of self-inflicted complexity are removable, and every one of them is a deletion rather than a patch.

  1. Three pure-delegation wrappers were added instead of replacing their predecessors: offload::open (helios/src/offload/mod.rs:114-119) has no caller at all in the repo (the one helios caller, server/runtime.rs:731, uses open_with_gate); shard::join_peer (shard.rs:37-45) is test-only now that flare-cli/src/cluster.rs:254 uses join_peer_with_gate; Copiers::new (transfer.rs:2167-2171) is #[cfg(test)] and only forwards None to with_gate.
  2. "Gated ⇒ lease+sync per batch; ungated ⇒ one sync at window end" is implemented three times — copy_batch_gated (transfer.rs:308-339, hand-rolled DrainOnDrop + mem::forget), copy_spans_batch (codec.rs:978-1033, a second, differently-shaped Fence guard, its own two is_none() tests and another mem::forget), and RankWorker::run (transfer.rs:459-474) — absorbable into one small GatedCopies { stream, event, gate } with batch()/finish().
  3. gate_wait/max_gate_wait is ~60 lines threaded through nine signatures and five restructured GPU-codec blocks, solely to subtract gate wait from Reply.elapsed (transfer.rs:795-798) — which feeds Selene's worth_fetching heuristic (selene/src/memory.rs:1450-1456), so a stalled transfer reports as faster. Delete the channel; keep timers where they are.
  4. The fairness state machine (copy_gate.rs:34-68,94-100,115-125,191-196,211-221) is honoured only by RankExecutor::can_submit (ranks.rs:181-184), never by serve_rank (parallel.rs:652-656), so on RankPeers::Processes it never arms; and enter_peer_graph_timeout (copy_gate.rs:110) is pub for one test.

Conventions: no substantive AGENTS.md violation — the gate is structural, adds no flag/env/config, no per-model branch. Praise: RankExecutorInner split, PeerGraphLeases consolidation, drain_stream extraction, dead has_peer_copies removal.

Open: no measurement justifies the gate_wait adjustment; no A/B offload figure exists (dossier 5).

Full report · Notes

Correctness and contracts

Correctness / contracts / system-level review of PR #628 @ 76e1813 (19 files, +1,165/−154).

  1. Blocker — offload starvation is unbounded on the multi-process rank layout the PR newly gates. serve_rank takes the lease on COMMIT with no can_submit check (helios/src/execution/parallel.rs:652-656), while the only mechanism that lets peer leases drain to zero — RankExecutor::can_submit (helios/src/execution/ranks.rs:181-184) — is consumed solely by Worker::submit (helios/src/server/runtime.rs:2261). enter_offload_batch waits on an unbounded condvar (copy_gate.rs:184). With 2-frame pipelining, turn never becomes Offload and that process's restores/checkpoint unpins block forever.
  2. Major — Reply.elapsed now excludes cumulative gate wait (helios/src/offload/transfer.rs:795-798), feeding Rate::observe (selene/src/levels.rs:57-68) → worth_transfer (selene/src/store.rs:424-442) → admission: contended restores look cheapest and stay admitted; zero-clamped samples are silently dropped.
  3. Major — GPU-codec leases cover encode/decode compute, not "a bounded 16 MiB batch drain" as docs/prefix-cache-offload.md:133-136,1025-1029 claims (helios/src/offload/transfer/codec.rs:288-303,318-338,354-377).
  4. Major — a 120 s stall fails the whole served worker (copy_gate.rs:136-146 → ranks.rs:153 → runtime.rs:2332-2339 → fail_all/close at runtime.rs:774-777), after the scheduler already recorded the submission.
  5. Major — the fairness test simulates the loop instead of driving it (copy_gate.rs:453-461); gated codec coverage is #[ignore]d and CUDA-only, so no gated path has run in CI.
  6. Minor — peer-copy detection is literal (Node::Copy with declared Memory::Peer endpoints only); gate is per process; multi-process gate wait can surface as "rank graph completion deadline expired" (parallel.rs:667-671); docs/same-process-tp.md (not opened) not updated.
  7. Charter (#210) — no A/B offload figure or gate-cost measurement; author defers the GPU re-run.

Sound: detection/manifest field and length validation, rank-0 union, zero overhead without peer copies, lock ordering, RAII/panic release, lease clear after drain, Heliopause path unreachable. Open: is a maintainer satisfied that the fairness mechanism is sufficient for RankPeers::Processes?

Full report · Notes

Re-review

Recommendation: Changes Requested

Head 76e1813 cleanly resolves all Round 1 blockers on the in-process threaded TP path—scoping CopyEngineGate exclusively to models with peer-copy graphs (zero overhead on single-GPU and non-peer-copy models), adding bounded fairness in CopyEngineGate wired into RankExecutor::can_submit, bounding peer-graph waits at 120 s, and updating docs/prefix-cache-offload.md. However, 76e1813 also extends gating to multi-process peer ranks (serve_rank / join_peer_with_gate) without wiring should_drain_for_offload() into serve_rank, leaving unbounded offload starvation on RankPeers::Processes, and subtracts max_gate_wait from Reply.elapsed, which distorts Selene's end-to-end inbound_rate / worth_fetching admission pricing; the new gated CUDA tests and A/B latency measurement also remain pending on 76e1813.

Merge Risk

Level: Medium

Walkthrough

Pre-merge Checks

Blockers

  1. Unbounded offload starvation on multi-process peer ranks (helios/src/execution/parallel.rs:627-666, helios/src/execution/ranks.rs:181-184, helios/src/offload/copy_gate.rs:55-68, 120-125, 173-199):
    • Verified behavior & impact: 76e1813 wires owner.copy_gate() into multi-process peer offload workers (flare-cli/src/cluster.rs:254-261 -> helios/src/offload/shard.rs:47-61) and acquires PeerGraphLeases in serve_rank (parallel.rs:563-566, 652-665). However, should_drain_for_offload() is only checked by RankExecutor::can_submit (ranks.rs:181-184) on rank 0 against rank 0's process-local CopyEngineGate; serve_rank never checks leases.should_drain_for_offload(). Under 2-frame pipelined decode (protocol::can_submit_pending in helios/src/execution/threaded/protocol.rs:28), whenever rank 0's local gate has offload_batches_waiting == 0 while a peer process still has a waiting offload batch (e.g., rank 0 finished its batches first, a peer batch arrived slightly later over TCP, or a peer is serving a codec/pool transfer), rank 0 keeps pipelining PREPARE -> READY -> COMMIT back-to-back. On the peer, serve_rank enters frame N+1 while frame N is still active (peer_graphs_active oscillates 1 -> 2 -> 1 -> 2 and never hits 0), maybe_arm_offload_wave() never fires (copy_gate.rs:56 requires peer_graphs_active == 0), and the peer offload worker blocks indefinitely in enter_offload_batch's unbounded Condvar::wait (copy_gate.rs:183-185)—stalling multi-rank restores (which wait for every shard) and keeping GPU checkpoints pinned until decode goes idle.
    • Concrete fix: In serve_rank (helios/src/execution/parallel.rs:627-640), do not defer after COMMIT (at that point rank 0 has already launched its local CUDA graph in commit_and_launch at parallel.rs:359-372). Instead, when PREPARE/PREPARE_MORE arrives and leases.should_drain_for_offload() is true, hold back sending READY (without arming prepared_at) while continuing to poll executor.poll() so active frames finish, leases.release_through drops peer_graphs_active to 0 and arms the peer's offload wave, and send READY once !leases.should_drain_for_offload(). Add a CPU unit test driving serve_rank (or its frame-coordination loop) alongside a waiting offload thread to verify forward progress under 2-frame pipelining.

Should Fix

  1. Subtracting max_gate_wait from Reply.elapsed distorts Selene's inbound_rate and worth_fetching admission pricing (helios/src/offload/transfer.rs:780, 795-799, selene/src/memory.rs:1174, 1450-1457, selene/src/levels.rs:57-68, selene/src/store.rs:424-442, helios/src/server/runtime.rs:223-235, 2834, 2858):
    • Verified behavior & impact: Transfers::absorb reports pending.started.elapsed().saturating_sub(pending.max_gate_wait) as Reply.elapsed. MemoryStore::absorb feeds reply.elapsed into inbound_rate.observe(reply.bytes, reply.elapsed), which computes estimated_seconds for worth_fetching/worth_transfer (estimated_seconds < 0.5 * gained_tokens / prefill_rate) and RestoreWait::defer. Selene's own contract requires inbound_rate to measure end-to-end effective wall-clock restore latency (cf. selene/src/disk_store/coalesce/tests.rs:1444 (not opened), 1982, 2153); stripping gate wait makes gate-contended restores look artificially fast so the scheduler keeps admitting restores that actually lose to prefill (and clamping elapsed to zero causes Rate::observe to silently drop the sample at selene/src/levels.rs:58-60).
    • Concrete fix: Delete the gate_wait/max_gate_wait subtraction from Reply.elapsed (keep pending.started.elapsed(), and remove the ~60 lines of gate_wait plumbing across transfer.rs and codec.rs—see Subtract #1—updating transfer.rs:2047-2051 accordingly). Keep the two valid metric isolations already in 76e1813: GPU-codec transform_ns timers starting after gate acquisition and prefill_started recorded after executor.submit() succeeds.
  2. Complete pending SM120 GPU verification and A/B offload latency measurement (helios/src/offload/transfer.rs:2013-2053, helios/src/offload/transfer/codec.rs:1286-1292):
    • Concrete fix: Once the SM120 GPUs are free, run the newly added gated CUDA transfer and CPU/GPU codec tests on the final commit, post a peer-copy A/B offload throughput/latency comparison per Charter #210, and confirm Helios lifecycle (python3 verification/helios-lifecycle/check.py (not opened)) passes on the final head.

Subtract / Simplify

  1. Delete gate_wait / max_gate_wait plumbing (~60 lines, subsumes Should Fix #1): Remove RankReply.gate_wait (helios/src/offload/transfer.rs:78), Pending.max_gate_wait (:85), the saturating_sub (:780, 795-799), the Duration return from enter_offload_batch/copy_batch_gated/copy_spans_batch/RankWorker::run/RankCodec::run/capture_window/restore_window/decode_pages_cpu_batch, and revert the five (stored_len, elapsed, waited) tuple blocks in helios/src/offload/transfer/codec.rs:288-305, 318-340, 354-376, 673-700, 760-782 to simpler let start = Instant::now(); ... stats.transform_ns += ... blocks (still placed after gate acquisition).
  2. Collapse unused/test-only pass-through wrappers into single entry points:
    • helios/src/offload/mod.rs:114-130: open has zero callers repo-wide (server/runtime.rs:731 already calls open_with_gate). Delete open and rename open_with_gate to open.
    • helios/src/offload/shard.rs:37-61: join_peer is only called in two tests (helios/src/offload/shard/tests.rs:20, helios/src/offload/pool/tests.rs:146); production (flare-cli/src/cluster.rs:254) already calls join_peer_with_gate. Delete the wrapper, pass None at those two test sites, and keep one join_peer.
  3. Deduplicate gated/ungated batch-sync logic (helios/src/offload/transfer.rs:308-339, 459-474, helios/src/offload/transfer/codec.rs:978-1034): Both RankWorker::run and copy_spans_batch repeat the if copy_gate.is_none() { record; synchronize; } pattern and duplicate DrainOnDrop/Fence drop guards plus std::mem::forget. A small GatedCopies<'a> helper with batch(...) and finish() (draining inline on error via drain_stream) replaces all three sites cleanly.
  4. Narrow CopyEngineGate::enter_peer_graph_timeout visibility (helios/src/offload/copy_gate.rs:110): Its only callers are enter_peer_graph (:106) and two unit tests (:509, :518); make it private (fn) instead of widening the public crate API for a test knob.

Nits

  1. Accurate drain bound in docs (docs/prefix-cache-offload.md:919-922, 1025-1028): Line 1026 states that the model worker thread waits only for "a bounded in-flight 16 MiB batch drain", whereas at the five GPU-codec sites (helios/src/offload/transfer/codec.rs:288-303, 318-338, 354-374, 674-695, 761-779) OffloadBatchGuard spans an entire GPU encode/decode call—including up to MAX_PIPELINE_BATCHES = 4 pipelined batches + host emission (gpu_codec.rs:1601-1665) and CPU CRC/staging (gpu_codec.rs:1723-1747). Reword to "a bounded in-flight 16 MiB copy batch or GPU-codec batch/wave drain".

Dropped on verification

Full report

Classify triage

Selected: triage:review

Threshold: 65%

Triage

Apply labels

No label changes Decision to Test: no (99%): Testing will not add significant value as the code stands today. The code is either not yet ready to merge, or adequate testing has already been done to validate the contents of the code, or the available hardware is not suitable to test with.