Recommendation: Ready To Merge
Head fdd898b cleanly resolves all Round 2 blockers and should-fix items: multi-process peer ranks (serve_rank) now defer READY while active peer-copy frames drain for a waiting offload wave, Reply.elapsed restores honest wall-clock timing for Selene admission pricing, the redundant *_with_gate constructors and batch-sync duplication are collapsed into offload::open, offload::shard::join_peer, and GatedCopies, and all 8 ignored SM120 CUDA offload::transfer:: tests plus the Qwen3.8-Flash-Next TP2 A/B run passed on hardware. Adversarial verification confirmed that CopyEngineGate, PeerGraphLeases, lock ordering (gpu.codec → CopyEngineGate), stream drains on error, and executor.close()-before-store.close() teardown are sound, with zero overhead on single-GPU and non-peer-copy models.
Merge Risk
Level: Medium
- Zero blast radius on single-GPU and non-peer-copy models:
NativeModel.copy_gateisNoneunless at least one rank reconstructed a graph containingNode::CopytargetingMemory::Peer(helios/src/runtime_core/model.rs:827-831), keeping ungated models on the single-sync-per-window path (helios/src/offload/transfer.rs:347-363) and skipping mutex locks viaself.guards.is_empty()(helios/src/offload/copy_gate.rs:258-264). - Core execution and offload hot paths on peer-copy TP models: Touches
RankExecutor(helios/src/execution/ranks.rs:99-196),serve_rank(helios/src/execution/parallel.rs:563-710), and all uncompressed/CPU/GPU codec transfer paths (helios/src/offload/transfer.rs:290-498,helios/src/offload/transfer/codec.rs:288-373, 665-796, 958-1011). - Residual verification gaps: Live multi-host TCP/RoCE execution of the deferred-
READYpath was not exercised on hardware (only simulated in a unit test), and the branch predates merged#645(which addsGraphKind::PrefilltoGraphKind::pipelines()onmain); there are no textual conflicts withmain, andCopyEngineGatealready handles 2-frame pipelined peer-copy graphs, so a routine rebase before merge will keep CI (Helios lifecycle+ CPU suites) current.
Walkthrough
- Structural peer-copy graph detection (
helios/src/runtime_core/mod.rs:119, 919, 1149-1156, 1238, 1347-1349,helios/src/runtime_core/serving.rs:49, 59, 202,helios/src/execution/manifest.rs:436-440, 838-843): Recordspeer_copy_graphs[i] = truewhenever anyNode::Copyendpoint resolves toMemory::Peer, validates length when populated, and instantiatesNativeModel.copy_gateonly when at least one rank has peer-copy graphs (helios/src/runtime_core/model.rs:827-831). - Bounded fairness & timeout gate (
helios/src/offload/copy_gate.rs:1-645,helios/src/offload/mod.rs:19-60, 114-123,helios/src/offload/shard.rs:37-51,flare-cli/src/cluster.rs:254-261): AddsCopyEngineGate(MAX_PEER_STREAK_WHILE_OFFLOAD_WAITING = 4,PEER_GRAPH_GATE_TIMEOUT = 120 sreturningExecutionError::Drain) and fence-orderedPeerGraphLeases, wired throughBinding,offload::open,attach_offload, andoffload::shard::join_peer. - Execution boundary (
helios/src/execution/ranks.rs:19-227,helios/src/execution/parallel.rs:563-710,helios/src/server/runtime.rs:714-734, 2340-2360): SplitsRankExecutorInner, unions asymmetricpeer_copy_graphsacrossRankPeers::Threads, gates submission pipelining viaRankExecutor::can_submitandserve_rankdeferredREADY, acquires/releases leases in fence order, clears residual leases afterclose()/abandon(), and timestampsprefill_startedafterexecutor.submit()returns. - Offload transfer & codec gating (
helios/src/offload/transfer.rs:290-505, 807-816,helios/src/offload/transfer/codec.rs:152-373, 530-800, 958-1011): ExtractsGatedCopiesto share per-batch gating + error stream drain across uncompressed and CPU-codec paths (while preserving one end-of-window sync when ungated), gates all five GPU-codec entry points undergpu.codec→CopyEngineGatelock order, restores wall-clockReply.elapsed, and keeps GPUtransform_nstimers scoped after gate acquisition. - Documentation & tests (
docs/prefix-cache-offload.md:133-138, 917-924, 1025-1029,copy_gate.rs:303-645,ranks.rs:198-227,transfer.rs:2025-2059,codec.rs:1264-1270): Documents the bounded drain and fairness behavior, adds 8copy_gateand 2ranksunit tests, and adds ignored CUDA tests for gated uncompressed, CPU-codec, and GPU-codec transfers.
Pre-merge Checks
- [PASS] Security / malicious screen: Pure host-side synchronization and manifest metadata; no new dependencies, external I/O, wire/Protobuf/package-format changes, or prompt-injection attempts.
- [PASS] Charter & value fit: Model-agnostic Helios bug fix resolving a reproducible SM120 TP2 deadlock (#627) without package re-export or per-model branches (#267, #334); A/B confirms zero offload latency regression (
1.04xcold,1.15xwarm,0.98xdisk restore,8/8burst wheremaindeadlocked). - [PASS] Related / duplicate / conflict check: Fixes #627 with no duplicate or competing PR; verified against current
main(e85019b9/ #645) that none of the 20 changed files have textual merge conflicts. - [WARN] Tests & verification evidence: Author verified
RUSTFLAGS="-D warnings" cargo check --locked --all-targetsacross all 4 crates,heliosoffload::+execution::(134/134), all 8 ignored SM120 CUDAoffload::transfer::tests (11.91 s), and liveQwen3.8-Flash-NextTP2 A/B + burst onfdd898b; live multi-host TCP/RoCE deferred-READYwas not run on hardware, and CI /python3 verification/helios-lifecycle/check.py(not opened) (perdocs/design-review.md:209-215) should confirm green on the final rebased head.
Blockers
None.
Should Fix
None.
Subtract / Simplify
- Store
copy_gateonRankCodecinstead of threading it through 5 signatures (helios/src/offload/transfer/codec.rs:44-72, 160, 227, 536, 585, 961,helios/src/offload/transfer.rs:408-421, 459):RankCodec::newis called from a single site (transfer.rs:410) wherecopy_gateis already in scope, andRankCodecalready ownscounters,write_mode,cpu, andgpu. Holdingcopy_gate: Option<Arc<CopyEngineGate>>as a struct field removes ~16 pure pass-through arguments, sixsuper::super::CopyEngineGatespellings, and two#[allow(clippy::too_many_arguments)]attributes while preservinggpu.codec→CopyEngineGatelock ordering via disjoint field borrows. - Return
copy_gatefromBinding::take()(helios/src/offload/mod.rs:78-82,helios/src/server/runtime.rs:718-724): WideningBinding::take(&self)toOption<(Prepared, Vec<Arc<Vec<u8>>>, Option<Arc<CopyEngineGate>>)>eliminates the intermediate closure and 3-tuple shuffle inserver/runtime.rs:718-724. - Deduplicate the starvation threshold predicate and narrow visibility (
helios/src/offload/copy_gate.rs:28, 55-68, 94-100, 258-264): ExtractState::offload_owed_turn(&self) -> boolfor the sharedoffload_batches_waiting > 0 && peer_entries_while_offload_waiting >= MAX_PEER_STREAK_WHILE_OFFLOAD_WAITINGcheck used by bothmaybe_arm_offload_waveandshould_yield_to_offload. NeitherPEER_GRAPH_GATE_TIMEOUT(:28) norCopyEngineGate::should_yield_to_offload(:94) has any caller outsidecopy_gate.rs, so both can be module-private. (Optionally, the two ~55-line simulated fairness loops atcopy_gate.rs:439-496and:578-644can also be consolidated into one test.)
Nits
- Stale PR description: Update the PR body to remove superseded names (
has_peer_copies,open_with_gate) and old test counts (5/5,6/6,19/19) so the merge commit summary matchesfdd898b. - Rebase onto current
mainbefore merging: Currentmainincludes#645(GraphKind::pipelines()now includesGraphKind::Prefillathelios/src/execution/manifest.rs:89-91); rebasing before merge lets CI (Helios lifecycleand--releaseCPU suites) validate the exact merge tree. - Minor polish: In
helios/src/execution/parallel.rs:639, 676, passinggraphinto a graph-awareshould_drain_for_offload(graph)would avoid deferring non-peer-copy frames when only a subset of graphs carry peer copies. Inhelios/src/offload/copy_gate.rs:580, clarify the comment that the unit test simulates theserve_rankdeferral state transitions (sinceserve_rankconstructs a CUDAGraphExecutor::new_unstarted). Indocs/prefix-cache-offload.md:920-922, optionally note that hitting the 120 s drain bound fails the submission and stops the worker (consistent with §2.12 at:1030-1031).
Dropped on verification
- F1 / A1 (claimed deferred
READYinserve_rankhas no peer deadline and busy-spins with 0 outstanding frames): False on verification.PeerGraphLeases::should_drain_for_offload()(helios/src/offload/copy_gate.rs:258-264) requires!self.guards.is_empty(). Becauseleases.trackandstarted.push_backare paired inCOMMIT(parallel.rs:661-666) andrelease_through/started.pop_frontare paired inpoll()(:671-674), wheneverready_pendingis true there is guaranteed to be at least one committed in-flight frame (executor.outstanding() >= 1,started.front().is_some()), so both the peer'sstartedcompletion deadline (:686-688) andexecutor.park()(:694) remain active. The instant the last active peer-copy frame completes,leases.guardsempties,!leases.should_drain_for_offload()immediately becomes true at:676,READYis sent withprepared_at = Some(Instant::now()), and subsequentCOMMITblocks cleanly onCopyEngineGate'sCondvar::wait_timeoutwith its own 120 sExecutionError::Draindeadline. - B2 (claimed concrete merge collision between
parallel.rs:603-711/threaded/protocol.rsand merged#645): False on verification. Checkedmaindirectly:#645modifiedparallel.rs:262-268(g.kind.pipelines()), leavingserve_rank(parallel.rs:550-691) untouched, and this PR does not modifythreaded/protocol.rs. None of the 20 changed files conflict withmain. - F2 / A3 (claimed 120 s
ExecutionError::Drainshould degrade instead of stopping the worker, andreserve_and_packprecedesexecutor.submit): Dropped. Launching a peer-copy graph while an offload Copy Engine batch has been hung for 120 s would re-trigger the exact PCIe deadlock this PR fixes; stopping the worker matchesThreadedExecutor/TensorParallelExecutor's 120 s stall policy (threaded.rs:23,parallel/wire.rs:28) anddocs/prefix-cache-offload.md:1030-1031.reserve_and_packbeforeexecutor.submit(server/runtime.rs:2280-2336) is pre-existing code required to build&uploads. - F4 / B1 (blocking on re-running A/B post-
#645under charter#210): Dropped as a blocker. This PR is a deadlock bug fix (#627), not a speedup PR; the A/B against3801ff1dalready demonstrates zero latency regression, andCopyEngineGatealready supports 2-frame pipelined peer-copy graphs (prefill pipelining onmainexercises the same mechanism). Kept only as a rebase Nit. - F5 & F6 (
prefill_startedand GPU-codectransform_nsstarting after gate acquisition): Dropped. Both were intentionally placed in Round 1/2 (76e1813) and untouched infdd898b:transform_nsspecifically measures codec compute time rather than gate queuing, andprefill_startedprevents outbound offload capture stalls from artificially collapsing GPUprefill_rate. - F7 / A4 (claimed GPU-codec lease spans host emission and contradicts docs): Dropped.
encode_pages_batches_with(gpu_codec.rs:1626-1663) overlaps batchb+1's GPU kernels/D2H with batchb's CPU emission on the same stream, so the gate must cover the wave;docs/prefix-cache-offload.md:1026-1027already explicitly states"16 MiB copy batch or GPU-codec batch/wave drain". - A6 (speculative non-
Node::Copy/ peer-mappedMemory::Devicedetection): Dropped. Unverified speculation; SM-driven peer loads/stores do not use the Copy Engine hardware implicated in #627. - A7 (public API signature change on
offload::open/offload::shard::join_peer): Dropped. Directly requested in Round 2 to eliminate duplicate*_with_gateconstructors, with all callers in-repo. - Subtraction #5b (replacing
GatedCopies::newwith struct literals): Dropped.GatedCopiesmaintains an internalneeds_draininvariant (transfer.rs:307, 320); keepingGatedCopies::newpreserves encapsulation better than exposingneeds_drain: falseat call sites.