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
- Multi-process TP liveness regression (
RankPeers::Processes): Newly gating peer offload workers (flare-cli/src/cluster.rs:254-261->helios/src/offload/shard.rs:47-61) alongsideserve_rank(helios/src/execution/parallel.rs:563-566, 652-663) without checkingleases.should_drain_for_offload()lets 2-frame pipelined decode starve peer-rank offload workers indefinitely whenever rank 0's local gate has no waiting offload batches. - Prefix-cache admission pricing distortion: Subtracting
max_gate_waitfromReply.elapsed(helios/src/offload/transfer.rs:780, 795-799) hides real restore wait time fromMemoryStore::inbound_rate(selene/src/memory.rs:1455) andworth_fetching/RestoreWait::defer, biasing heavily gate-contended restores to look faster than prefill. - Zero blast radius on non-peer-copy models, unverified gated GPU paths on
76e1813:NativeModel.copy_gateisNonewhen no rank reconstructed a peer-copy graph (helios/src/runtime_core/model.rs:827-831), keeping single-GPU and non-peer-copy models untouched, but the new gated CUDA transfer/codec tests and peer-copy A/B measurements have not yet run on76e1813.
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:838-843): Recordspeer_copy_graphs[i] = truewhen anyNode::Copyreferences aMemory::Peerallocation, validates populated lengths inExecutionManifest::validate(), and only instantiatesNativeModel.copy_gatewhen 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-583,helios/src/offload/mod.rs:26, 39-60, 114-130,helios/src/offload/shard.rs:37-61,flare-cli/src/cluster.rs:254-261): AddsCopyEngineGate(withMAX_PEER_STREAK_WHILE_OFFLOAD_WAITING = 4andPEER_GRAPH_GATE_TIMEOUT = 120 s) andPeerGraphLeases, wired acrossNativeModel,offload::Binding,open_with_gate, and multi-process peerjoin_peer_with_gate. - Execution boundary (
helios/src/execution/ranks.rs:19-196,helios/src/execution/parallel.rs:563-566, 652-665, 692,helios/src/server/runtime.rs:718-733, 2340-2360): SplitsRankExecutorInner, merges asymmetricpeer_copy_graphsacrossRankPeers::Threads, checks!self.leases.should_drain_for_offload()inRankExecutor::can_submit, acquires/releases leases in fence order in bothRankExecutorandserve_rank, and recordsprefill_startedonly afterexecutor.submit()succeeds. - Offload transfer & codec gating (
helios/src/offload/transfer.rs:292-339, 441-505, 780, 795-799,helios/src/offload/transfer/codec.rs:288-376, 673-700, 760-782, 971-1034): Gates uncompressed batches viacopy_batch_gated(preserving single end-of-window sync whencopy_gateisNone), gates all five GPU-codec sites withgpu.codeclocked beforeCopyEngineGate, movestransform_nstimers after gate acquisition, and threadsgate_waitintoReply.elapsed. - Documentation & tests (
docs/prefix-cache-offload.md:133-138, 917-924, 1025-1029,copy_gate.rs:308-583,ranks.rs:198-227,transfer.rs:2013-2053,codec.rs:1286-1292): Updates offload blocking/queueing invariants and adds unit tests for gate fairness/timeout/lease ordering plus ignored CUDA tests for gated transfer and codec paths.
Pre-merge Checks
- [PASS] Security / malicious screen: Pure host-side synchronization and manifest metadata; no new dependencies, external I/O, wire/Protobuf contract changes, or prompt-injection attempts.
- [WARN] Charter & value fit: Model-agnostic Helios fix addressing a reproducible SM120 TP2 deadlock (#627) with preserved core compatibility (#267/#334), but peer-copy A/B offload latency measurements remain pending on
76e1813(#210) andReply.elapsedsubtraction weakens Selene's admission cost model. - [PASS] Related / duplicate / conflict check: Fixes #627 with no competing or duplicate PR; pre-existing Python CPU CI failure was unrelated (
#623/#624). - [WARN] Tests & verification evidence: Full
--locked --releaseCPU suites (helios1,740/1,740,flare245/245,flare-cli201/201 + 4 integration suites) andRUSTFLAGS="-D warnings" cargo check --locked --all-targetspassed on76e1813; however,offload_makes_forward_progress_under_pipelined_peer_graphshand-simulates the loop rather than exercisingserve_rank, the new gated CUDA tests and A/B latency measurements have not yet run on76e1813, andpython3 verification/helios-lifecycle/check.py(not opened) (or greenHelios lifecycleCI) should confirm the final head perdocs/design-review.md:209-215.
Blockers
- 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:
76e1813wiresowner.copy_gate()into multi-process peer offload workers (flare-cli/src/cluster.rs:254-261->helios/src/offload/shard.rs:47-61) and acquiresPeerGraphLeasesinserve_rank(parallel.rs:563-566, 652-665). However,should_drain_for_offload()is only checked byRankExecutor::can_submit(ranks.rs:181-184) on rank 0 against rank 0's process-localCopyEngineGate;serve_ranknever checksleases.should_drain_for_offload(). Under 2-frame pipelined decode (protocol::can_submit_pendinginhelios/src/execution/threaded/protocol.rs:28), whenever rank 0's local gate hasoffload_batches_waiting == 0while 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 pipeliningPREPARE->READY->COMMITback-to-back. On the peer,serve_rankenters frameN+1while frameNis still active (peer_graphs_activeoscillates1 -> 2 -> 1 -> 2and never hits0),maybe_arm_offload_wave()never fires (copy_gate.rs:56requirespeer_graphs_active == 0), and the peer offload worker blocks indefinitely inenter_offload_batch's unboundedCondvar::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 afterCOMMIT(at that point rank 0 has already launched its local CUDA graph incommit_and_launchatparallel.rs:359-372). Instead, whenPREPARE/PREPARE_MOREarrives andleases.should_drain_for_offload()is true, hold back sendingREADY(without armingprepared_at) while continuing to pollexecutor.poll()so active frames finish,leases.release_throughdropspeer_graphs_activeto0and arms the peer's offload wave, and sendREADYonce!leases.should_drain_for_offload(). Add a CPU unit test drivingserve_rank(or its frame-coordination loop) alongside a waiting offload thread to verify forward progress under 2-frame pipelining.
- Verified behavior & impact:
Should Fix
- Subtracting
max_gate_waitfromReply.elapseddistorts Selene'sinbound_rateandworth_fetchingadmission 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::absorbreportspending.started.elapsed().saturating_sub(pending.max_gate_wait)asReply.elapsed.MemoryStore::absorbfeedsreply.elapsedintoinbound_rate.observe(reply.bytes, reply.elapsed), which computesestimated_secondsforworth_fetching/worth_transfer(estimated_seconds < 0.5 * gained_tokens / prefill_rate) andRestoreWait::defer. Selene's own contract requiresinbound_rateto 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 clampingelapsedto zero causesRate::observeto silently drop the sample atselene/src/levels.rs:58-60). - Concrete fix: Delete the
gate_wait/max_gate_waitsubtraction fromReply.elapsed(keeppending.started.elapsed(), and remove the ~60 lines ofgate_waitplumbing acrosstransfer.rsandcodec.rs—see Subtract #1—updatingtransfer.rs:2047-2051accordingly). Keep the two valid metric isolations already in76e1813: GPU-codectransform_nstimers starting after gate acquisition andprefill_startedrecorded afterexecutor.submit()succeeds.
- Verified behavior & impact:
- 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.
- 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
Subtract / Simplify
- Delete
gate_wait/max_gate_waitplumbing (~60 lines, subsumes Should Fix #1): RemoveRankReply.gate_wait(helios/src/offload/transfer.rs:78),Pending.max_gate_wait(:85), thesaturating_sub(:780, 795-799), theDurationreturn fromenter_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 inhelios/src/offload/transfer/codec.rs:288-305, 318-340, 354-376, 673-700, 760-782to simplerlet start = Instant::now(); ... stats.transform_ns += ...blocks (still placed after gate acquisition). - Collapse unused/test-only pass-through wrappers into single entry points:
helios/src/offload/mod.rs:114-130:openhas zero callers repo-wide (server/runtime.rs:731already callsopen_with_gate). Deleteopenand renameopen_with_gatetoopen.helios/src/offload/shard.rs:37-61:join_peeris 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 callsjoin_peer_with_gate. Delete the wrapper, passNoneat those two test sites, and keep onejoin_peer.
- Deduplicate gated/ungated batch-sync logic (
helios/src/offload/transfer.rs:308-339, 459-474,helios/src/offload/transfer/codec.rs:978-1034): BothRankWorker::runandcopy_spans_batchrepeat theif copy_gate.is_none() { record; synchronize; }pattern and duplicateDrainOnDrop/Fencedrop guards plusstd::mem::forget. A smallGatedCopies<'a>helper withbatch(...)andfinish()(draining inline on error viadrain_stream) replaces all three sites cleanly. - Narrow
CopyEngineGate::enter_peer_graph_timeoutvisibility (helios/src/offload/copy_gate.rs:110): Its only callers areenter_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
- 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)OffloadBatchGuardspans an entire GPU encode/decode call—including up toMAX_PIPELINE_BATCHES = 4pipelined 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
- 120 s
ExecutionError::Draintearing down the worker (Correctness Finding 4 / Dossier §5.4): Dropped. Disk I/O never holdsOffloadBatchGuard(only pinned host <-> VRAM DMA and GPU codec calls do); a 120 s drain failure indicates a wedged CUDA stream and intentionally matchesThreadedExecutor::TIMEOUT(helios/src/execution/threaded.rs:23, 120 s). The proposed fix of returningOk(false)fromWorker::submitafterself.scheduler.submitted_step(fence)(helios/src/server/runtime.rs:2282) would corrupt scheduler state and reintroduce an unbounded hang. serve_ranklaundering gate wait intoprepared_at/starteddeadline errors (Correctness Finding 5 / Dossier §5.6): Dropped as misread.prepared_at = Noneruns athelios/src/execution/parallel.rs:643beforeleases.enter(graph)?at:652, andstarted.push_backruns at:657after (whenleases.enterblocks,peer_graphs_active == 0). A 120 s stall can race rank 0'sframe.dispatcheddeadline (parallel.rs:306-315) against the peer's 120 sPEER_GRAPH_GATE_TIMEOUT, which is low-signal diagnostic detail on a catastrophic hang.- Per-process gate vs cluster-wide invariant (Correctness Finding 6): Dropped. Each process owns its own GPUs and local offload workers, so per-process gating is the right synchronization boundary for preventing local Copy Engine collisions; the actual multi-process bug is the missing
should_drain_for_offload()check inserve_rank(Blocker #1). - Literal
Node::Copy+Memory::Peerdetection (Correctness Finding 7): Dropped. VerifiedMemoryvariants inhelios/src/runtime_core/(Device,MappedHost,Peer); structural detection is model-agnostic and already accurately scoped indocs/prefix-cache-offload.md:135-136, 917-918. - Deleting the fairness machinery (Subtraction §4a): Dropped. Round 1 established unbounded offload starvation under 2-frame pipelined decode as a Blocker; deleting fairness would reintroduce it.
- Deleting
#[cfg(test)] Copiers::new(Subtraction §1c): Dropped. Churning 15 untouched test sites acrossgpu_tests.rs(not opened),transfer.rs, andcodec.rsadds diff noise without simplifying production code. - Claim that
codec.rs:1005Fencehas nothing to protect on the ungated path (Subtraction §2 parenthetical): Dropped as inaccurate—on the ungated pathcopy_batch_gatedenqueues without syncing, soFencedrains earlier batches if a later batch errors. - Claim that a single rank's
gate_waitsum can exceedpending.started.elapsed()(Correctness Finding 2 detail): Dropped as inaccurate—batches on one rank execute sequentially afterpending.started, somax_gate_waitis bounded by wall time; the actual bug is the admission-pricing span shrinkage documented in Should Fix #1. - Stale
docs/same-process-tp.md:177-180(Dossier / Lenses): Dropped. Verified lines 177-180 discuss external process checkpoint/restore while parked onDispatchRing, unrelated to prefix-cache offload.