Case file — PR #628 helios: gate offload Copy Engine batches during peer-copy graphs
Draft, open 2026-11-30, head 1870a27, base main @ c146d7b; 14 files, +572/−72; labels bug, performance, priority:P1; no reviews, no comments, no reactions; CI failed on the head commit. Fixes #627. Discord: D-Rock. Author: yatesdr (COLLABORATOR).
Key findings
Things a reader could not learn from the PR description:
- A documented invariant is reversed and no doc is updated.
docs/prefix-cache-offload.md:133states "Offload work never blocks the model worker thread or the model stream" (repeated at:907"The model stream never waits on an offload event" and:1015"The model worker thread never waits for offload work"). With this change the model worker thread callingRankExecutor::submitblocks inCopyEngineGate::enter_peer_graph()until every in-flight offload batch drains (helios/src/execution/ranks.rs:90-96,helios/src/offload/copy_gate.rs:45-56). Nodocs/file is in the changed set. Section 2.10 (docs:900-918) already anticipates the gap — "Batch size and stream priority alone do not bound those delays" — but states the opposite invariant as the contract. - The offload fast path changes for every prefix-cache run, not only peer-copy runs. The gate is
Somefor every offload binding aNativeModelbuilds (helios/src/runtime_core/model.rs:986-989,1032-1038;ranks.rs:62), soRankWorker::runnow doesrecord+synchronizeper 16 MiBBATCH_BYTESbatch plus one mutex/condvar lock per batch (helios/src/offload/transfer.rs:398-430), where the single end-of-job sync (transfer.rs:431-434) is now the gate-less path only;copy_spans_batchlikewise (helios/src/offload/transfer/codec.rs:976-1002,1025-1028).BATCH_BYTES = 16 << 20(helios/src/cuda.rs:169(not opened)). The description's "zero gate overhead on graphs without peer-copy nodes" is true for graph submission only, and no offload throughput/latency measurement is presented — while the immediately preceding merged offload PR (#497) retuned this same worker specifically to reduce restore latency. - Several copy paths stay ungated despite the "pool and CPU codec paths share the same wiring" claim.
helios/src/offload/shard.rs:47(join_peer, used for a disk-store peer rank fromflare-cli/src/cluster.rs:254) still constructsCopiers::new(gpu_cubins)— no gate.heliopause/src/python.rs:331passespeer_copy_graphs: Vec::new(), so any Heliopause/Python-built manifest never marks peer-copy graphs and never engages the gate.NativeModel::attach_offload's factory only reaches the pool-agent peer path (selene/src/offload.rs:935-949), so "Selene pool workers" gating is narrower than the description reads. - Detection is deliberately narrow and can miss real peer traffic. Only literal
Node::Copynodes whose endpoint allocation is declaredMemory::Peerare marked (helios/src/runtime_core/mod.rs:1149-1156;Memory::Peersemantics athelios/src/runtime_core/format.rs:43-49). Kernel-driven DMA, or copies to a localMemory::Deviceallocation that is merely peer-mapped, are not detected. - Charter tension on root cause. The charter ("Bring real evidence", #397) requires bug fixes to address root cause rather than work around it. Issue #627's own ablation shows the mechanism is not fully characterised (serializing offload workers behind a cross-rank mutex still deadlocked), and the PR frames itself as "Coordinating host offload batches against peer-copy graph execution … resolves the deadlock" — a coordination/mitigation layer.
- Charter performance rule not met in the direction it asks for. #628 carries the
performancelabel but its only comparative datum is the opposite direction (unpatchedmaindeadlocks; patched completes 40/40 at 4.68–4.83 s/burst). The charter asks performance PRs for a benchmark showing a speedup overmain(#210). - Single-process scope only. The gate is per
NativeModel, soRankPeers::Processes(one process per rank, multi-host) gets one gate per process; a rank's offload batches are not coordinated against another rank's peer-copy graph. Description says "Share oneArc<CopyEngineGate>perNativeModel", which is accurate but narrower than "eliminates the TP2 deadlock" reads outside single-host threaded TP.
The change: what it does and how big
Plain terms: a per-model mutex/condvar gate with two RAII leases (helios/src/offload/copy_gate.rs, new, 263 lines):
PeerGraphGuard— taken around submitting a CUDA graph that contains in-graph peer copies. It incrementspeer_graphs_waiting, waits foroffload_batches_active == 0, then promotes topeer_graphs_active(copy_gate.rs:45-56). Waiting peer graphs block new offload batches (copy_gate.rs:60-67), giving prefill launch priority over sustained offload traffic.OffloadBatchGuard<'a>— taken per batch by offload copy workers; concurrently holdable across ranks; blocked while any peer graph is waiting or active (copy_gate.rs:60-67). Drops notify only when the last batch or last graph releases (copy_gate.rs:77-102).
Graph classification is structural, computed once at CUDA graph reconstruction: NativeResources.peer_copy_graphs: Vec<bool>, set when any Node::Copy has a Memory::Peer source or destination (helios/src/runtime_core/mod.rs:117,919,1149-1156,1238), surfaced as ExecutionManifest.peer_copy_graphs + has_peer_copies(index) (helios/src/execution/manifest.rs:436-449), populated per graph name in helios/src/runtime_core/serving.rs:49,59,202.
Wiring: one Arc<CopyEngineGate> per NativeModel (helios/src/runtime_core/model.rs:27,662), passed into offload::Binding::new(inner, cubins, copy_gate) (helios/src/offload/mod.rs:39-60), Copiers::with_gate in attach_offload (model.rs:985-991), manifest.offload build (model.rs:1032-1038), and server attach via open_with_gate (helios/src/server/runtime.rs:715-733).
Execution boundary: RankExecutor split into RankExecutorInner + gate state; merge_peer_copy_graphs unions flags across local RankPeers::Threads manifests so asymmetric peer copies are covered (helios/src/execution/ranks.rs:39-52); guard taken in submit only when peer_copy_graphs[graph] (ranks.rs:90-105), released in poll for fences ≤ the completed frame fence (ranks.rs:108-124), remainder cleared in close after inner close (ranks.rs:170-181).
Gated copy sites: uncompressed RankWorker::run (transfer.rs:398-430), CPU-codec copy_spans_batch (codec.rs:958-1028), and five GPU-codec entry points (codec.rs:290,318,352,668,752).
Compatibility surface: no Protobuf change, no package-format change, no new flag, no core re-export needed; peer_copy_graphs absent ⇒ false (manifest.rs:436-449), which is what keeps legacy cores loading.
The why
- Issue #627 (open,
bug,priority:P1,triage:investigate,area:selene), same author, opened ~1 minute before the PR, 0 comments. Hardware: 4× RTX PRO 6000 (SM120, PCIe), CUDA 13.0.1, driver 595.99.02,main@c146d7b. Repro: Qwen3.8-Flash-Next TP2 (--gpus 0,1),prefill7168graph with 8,613 nodes / 11,726 edges / 1,176Node::Copypeer nodes (4.58 MiB peer-to-peer),--prefix-cache-memory 4G, 8-way concurrent uncached ~6,574-token prompts. - Isolation evidence in #627:
cuGraphAddEventRecordNodefrontier probes show both ranks stalling inside aPCIeDmaAllReduceNode::Copy(4587520 B)+FlagLaunchspin-wait at non-deterministic layer indices (+16.58 ms vs +75.70 ms). Ablations: skipping onlystream.copy_batch(...)intransfer.rspassed 48/48 burst requests; unbatchedcuMemcpyAsync/cuMemcpyDtoHAsync_v2/cuMemHostRegister/normal-priority streams/GPUs 2,3/cross-rank mutex serialization of offload all still deadlocked; disabling host prefix cache or pausing copy windows passed 80/80 bursts at 4.44–4.71 s. - Note the last ablation: serializing offload against itself was insufficient. The fix instead gates offload against peer-graph execution, a different axis — consistent with the ablations but showing the underlying CE/flag interaction is not root-caused.
- How widely wanted: one day old at PR time, one reporter (the PR author), no duplicate reports in the repo. Searches for the deadlock return only #627/#628. Nearest adjacent "collective stalls on this hardware" reports are #348 (PCIe multi-GPU transport selection, open, yatesdr) and #151 (GB10/RoCE collective timeouts, open) — different failures, not claimed fixed here.
Related work
- No competing, duplicate or superseded work. No other PR attempts this fix; nothing in the repo describes the deadlock besides #627.
- File-overlap map (
items_touching, 180 days):helios/src/offload/transfer.rs: only this PR and yatesdr's own lineage — #504, #168, #141, #92, #80. The gated file is effectively the author's own code.helios/src/execution/ranks.rs: #334 (open, javieratomic), #280 (merged, jetnet, GB200 WFET parking), plus #628. No conflict; #334 also touches per-rank manifests.helios/src/execution/manifest.rs: #621 (open, jcartu), #555, #507, #479, #430, #92, #628. Merge-order note: adding a publicpeer_copy_graphsfield to the same struct #621 edits will collide textually — not a defect, but a rebase to sequence.helios/src/server/runtime.rs: 20+ recent PRs (#483, #554, #576, #548, #549, #560, #621, #334, #301, #626, #620, #607, #579, #497). The #628 hunk sits in the offload-attach block.
- Nearest neighbours: #497 (merged 2026-11-29, "Reduce disk offload restore latency and integrated-memory intake overhead") retuned the very worker this PR makes synchronize per batch (
Worker::idle_wait2 ms → 50 µs,Staged::pump_allordering) — a divergence in direction of travel rather than a conflict. #504/#523/#524/#525/#526/#527 (author's KV codec series) are the code that the five GPU-codec gate sites live in. #589 (Luke Alonso, batched copies/ARM64/Selene budgeting) last touched the offload directory before this PR.
Recent activity
- Base
c146d7b(2026-11-29). Only0a8c20f4(#626, Luke Alonso, speculative reasoning for grammar-constrained requests) landed since in the touched files — scheduler/speculation, orthogonal; itsserver/runtime.rschange is elsewhere than #628's hunk, so no textual conflict expected, but the PR is one rebase behind. helios/src/offloadhistory, newest first:1870a273(this PR) →dad2fa56#497 →ba3afb13#589 → warning fixes → yatesdr's codec series (c36a6a02/#527,225758fe/#525,716df00f/#504) → #429/#415/pool attachment/#168/#171/#141/#92/#80 → Luke Alonso's 2026-10-12 prefix-offload merge train. #628 builds on #504/#525/#527 and sits on top of #497 without reversing either.docs/same-process-tp.md:177-180lists as Not qualified: "four ranks, graphs that contain b12x spin-barrier collectives, process checkpoint and restore while rank threads are parked on the DispatchRing condition variable" — exactly the region this PR now touches; the doc is not updated.
People
- yatesdr (COLLABORATOR): 80 merged PRs in 180 days (9 closed, 5 open), touching
helios/src(34),docs(33),selene/src(32),selene-manager/src(25). 47 commits onhelios/srcin 180 days. Original and dominant author of the Selene host prefix-cache tiers this PR gates: #80, #92, #141, #168, #415, #429, #504/#523/#524/#525/#526/#527, and the 2026-11-29 selene/selene-manager hardening run #609–#612. #628 continues that subsystem rather than being a drive-by. Not on the charter's priority-contributor list (@voipmonitor,@original-el8,@lukealonso), but effective owner by commit history. - Regulars in the areas: Luke Alonso (229 commits in
helios/src, 60 inheliopause/src; author of the prefix-offload merge train, #589, #607, #620, #626), Martin Vit (52; #566 Engram prefetch, memory-limit work), FujitsuPolycom (#497, #496, #540, #542), voipmonitor (collectives/capacity), original-el8 (#430 persistent workers), jcartu (#505, #621), Jason Cook / Javier López (multi-host prefix records, #126, #334). - Engagement so far: none.
pr_commentsreturns "No comments"; no review, no inline comment, no reaction, and no flare-autobot case-file comment (which #497 and #525 received within minutes). Issue #627 likewise has no discussion.
Project fit
Where it lines up:
- Target hardware is SM120/SM121 workstation GPUs — the charter's stated focus.
- Model-agnostic: no per-model branch, no new flag, no Protobuf/package change; explanation lives in Helios, not ignition (#267/#334 rule respected).
- A reproducible bug fix of the class the charter says gets merged, with the four expected description parts (why / what / result / evidence).
Where it does not:
- Root-cause rule (#397): the PR coordinates around the CE conflict; #627's ablations show the mechanism is not characterised (see Key findings 5).
- Documented invariant reversal without doc update (Key findings 1); the docs' §2.10 reasoning already names this gap, so the change is anticipated but contradicts the stated contract.
- Performance label without a speedup measurement and without measuring the new per-batch sync cost (#210).
Claims and evidence
| Claim | Backing |
|---|---|
| Eliminates the TP2 prefill deadlock | Live TP2 runs on 4× RTX PRO 6000, 5× 8-way uncached 6,578-token bursts, 40/40 HTTP 200 at 4.68–4.83 s/burst; "unpatched main deadlocked during the first burst". Text only — no logs/artifacts in the PR. |
| No regression in warm/restore correctness | Qwen3.8: warm 0/6 pos0 mismatches (5.08×), restart+disk restore 0/6 (2.45×); GLM-5.3: 0/96 token mismatches warm (3.50×) and restore (1.55×); both 8/8 bursts with 2 aborts. |
| Zero gate overhead on non-peer-copy graphs | True for submit path (ranks.rs:90-96 skips enter_peer_graph when the flag is false). Not true for the offload path, which syncs per batch whenever offload is attached (transfer.rs:398-430). |
| Multi-rank offload concurrency preserved outside peer graphs | Unit test listed ("multi-rank concurrency"); code allows concurrent OffloadBatchGuard holders (copy_gate.rs:60-67). |
| Pool and CPU-codec paths share the gate wiring | CPU codec: yes (codec.rs:958-1028). Pool: only via the factory used when Preparation::Store still has a pool (selene/src/offload.rs:935-949). Multi-host shard peer path: no (shard.rs:47). |
| Preserves compatibility without re-export | peer_copy_graphs absent defaults to false (manifest.rs:436-449); no format/Protobuf change in the diff. |
| Compiler/test results (0 warnings; 5/5, 162/162, 245/245, 200/201, 19/19 + 6/6) | Stated in prose only; CI on the head commit failed and no test output is attached. |
Not measured anywhere: offload capture/restore throughput cost of the per-batch synchronize; latency of peer-copy graphs waiting on offload drain; behaviour under sustained offload + prefill other than the author's burst tests.
Reach
- Who/what is affected: every run with prefix cache configured (
--prefix-cache-memory, disk tier, pool), because the per-batchrecord+synchronizeand the per-batch lock apply whenever offload is attached. Single-host threaded TP (theRankPeers::Threadspath) is the only layout that gets the deadlock protection and the coordination. - Operators: no configuration, default, flag, env-var or CLI change; no dependency change; no deployment change. Behavioural change is latency-side: model worker can block behind offload drain when a peer-copy graph is submitted; offload batches serialize per 16 MiB window instead of queuing back-to-back.
- Compatibility: existing exported cores keep loading unmodified (
peer_copy_graphsdefaultsfalse); no re-export needed. Cores exported through Heliopause/Python never set the flag, so that path gets no protection. - Documentation: none updated.
docs/prefix-cache-offload.md:133, 499-515 (§2.5), 900-928 (§2.10), 1015anddocs/same-process-tp.md:177-180all describe the pre-change contract; §2.5's "records its event … waits on it, and replies" description is the closest existing prose to the new per-batch behaviour.
Process
- Draft, opened 2026-11-30 02:41 and updated the same day; under a day old at case-file time, so "no reviews" is normal for its age.
- CI failed on the head commit
1870a27(no further detail captured here); the description instead reportscargo check --locked --all-targetswithRUSTFLAGS="-D warnings"clean on four crates. - No reviewer assigned; one rebase behind
main(#626 touchesserver/runtime.rs, unrelated hunk). Potential textual collision with open #621 inhelios/src/execution/manifest.rs.
Open questions / not found
- Which CI job failed and why — not retrievable from the material available here; the PR itself claims clean compiler and test runs.
- Whether the per-batch synchronize measurably regresses offload restore latency (the #497 direction); no measurement in the PR or issue.
- The actual driver-level mechanism of the CE/flag deadlock; #627 documents the phenomenology and ablations only, and one ablation (cross-rank offload mutex) is unexplained by a simple "CE submission conflicts with peer CE nodes" story.
- Whether
Memory::Peer-marked copies cover all real peer transfers in shipped cores (kernel-driven DMA and peer-mapped local allocations are unmarked). - Live behaviour for multi-host TP, Selene pool serving, CPU KV codec, and non-SM120 GPUs — explicitly untested end-to-end by the author.
- A second reporter or independent reproduction of the deadlock: none found.