Final review report · NVIDIA/hyperflare-inference #727

Raw Markdown for agents: https://autobot.eidonix.com/p/d9b4d135-76ad-414f-8230-e2b366ffe7e6.md

Recommendation: Changes Requested

The core fixes for #722's PCIe kernel-P2P CopyEngineGate detection, the three-phase cross-rank teardown barrier, the Reply::Started(Result<()>) startup drain handshake, and the global-rank Prometheus metrics label are sound and well-structured. However, verification at 224fb40 confirmed one Blocker in AsyncTransfer's new unflushed-IO tracking (where swap_remove desynchronizes inflight_io order from io_uring SQ FIFO order after a partial submit, causing complete_io to permanently drop a real kernel completion) and two Should Fix defects in ThreadedExecutor (RankWedgeWatchdog::CloseStalled aborting progressing/multi-stage teardowns and best_effort_drain_peers skipping already-drained peers after a wedged peer exhausts the shared deadline).

Merge Risk

Level: High

Walkthrough

Pre-merge Checks

Blockers

  1. mark_io_flushed + complete_io swap_remove desynchronizes inflight_io from io_uring SQ FIFO order and permanently drops real kernel completions (helios/src/async_transfer/scheduler.rs:231-243, 578-583; helios/src/async_transfer/worker.rs:994-1001, 1226-1248)
    • Verified behavior: pop_next_io() pushes new InflightIo entries to the back of self.inflight_io (scheduler.rs:566), and worker.rs:1228-1248 computes flushed_now = scheduler.unflushed_io_count().saturating_sub(args.io_backend.pending_submissions()) and passes it to scheduler.mark_io_flushed(flushed_now), which marks the first count unflushed entries in Vec index order (scheduler.rs:233-241). However, complete_io() removes finished entries via self.inflight_io.swap_remove(pos) (scheduler.rs:583), swapping the last element into pos and scrambling submission order relative to the kernel io_uring SQ FIFO.
    • Concrete failure trace:
      1. Stage reads A, B, C -> inflight_io = [A(unflushed), B(unflushed), C(unflushed)], io_uring SQ FIFO = [A, B, C], queued_sqes = 3.
      2. Partial flush submits 1 SQE (A) (Ok(1) then EBUSY/Ok(0)): queued_sqes = 2, flushed_now = 1 -> mark_io_flushed(1) marks A.
      3. A completes (normal ok = true or ok = false) -> complete_io(A, _) executes swap_remove(0) -> inflight_io becomes [C(unflushed), B(unflushed)], while the io_uring SQ still holds [B, C].
      4. Next partial flush submits 1 SQE (B): queued_sqes = 1, flushed_now = 1 -> mark_io_flushed(1) marks C (inflight_io[0]) as flushed = true while leaving B as flushed = false.
      5. poll_completions() (io_backend.rs:198-201) reaps B's CQE (IoCompletion { op_id: B, ok: true }) and removes B from IoUringBackend.expected; worker.rs:998 calls scheduler.complete_io(B, true).
      6. scheduler.rs:580-582 executes if ok && !self.inflight_io[pos].flushed { return None; } and silently discards B's completion without removing B from inflight_io.
    • Impact: B's CQE is permanently lost. Any GPU demand wait on B's completion slot hangs forever, any bounce slot held by B leaks permanently, and shutdown finish_drain() (scheduler.rs:814) permanently fails into ChannelState::FailedDrain, leaking pinned pools and CUDA handles until process exit.
    • Fix: Preserve submission order in inflight_io by replacing swap_remove(pos) with remove(pos) at scheduler.rs:583 (max_total_io is 32, so ordered removal is O(32) and preserves exact SQ FIFO order), or track a monotonic dispatch sequence number on InflightIo and have mark_io_flushed mark the count unflushed entries with the lowest dispatch sequence. Add a regression test exercising partial flush -> completion of first op -> second partial flush -> complete_io(B, true).

Should Fix

  1. RankWedgeWatchdog CloseStalled fires std::process::abort() during legitimate slow or multi-stage teardowns (helios/src/execution/threaded.rs:594-598, 679-687, 1015-1029, 1211-1233)

    • Verified behavior: begin_close() sets closing = true (one-way) and increments activity, but the closing arm of the watchdog loop (679-687) never reads activity and never resets close_since. It applies a single fixed 150 s wall-clock deadline (TIMEOUT + WATCHDOG_GRACE) across all stages of ThreadedExecutor::close(): draining self.pending via self.poll()? (up to TIMEOUT = 120 s per frame), close_peers(..., TIMEOUT = 120 s), fallback best_effort_drain_peers(..., TIMEOUT = 120 s) whenever poll() or close_peers fails, and self.local.close(). As a result, a poisoned teardown where poll() or close_peers hits its 120 s deadline only gets 30 s inside best_effort_drain_peers before the watchdog calls std::process::abort(), and a healthy slow teardown draining frames plus peers in >150 s while actively progressing also aborts.
    • Fix: Track activity in the closing branch (resetting close_since = Some(now) whenever activity advances, matching the busy branch at 703-707), and call self.watchdog_state.record_progress() across close() stage transitions (after pending drains, as each peer joins in close_peers/best_effort_drain_peers, and before self.local.close()).
  2. best_effort_drain_peers shared deadline skips later peers without checking already-queued Reply::Drained, leaving finished threads detached (helios/src/execution/threaded.rs:1278-1316)

    • Verified behavior: Hoisting let deadline = Instant::now() + timeout; outside the for peer in peers.iter_mut() loop (1292) means that if an earlier peer is wedged and consumes the 120 s budget, deadline.checked_duration_since(Instant::now()) returns None for all subsequent peers (1298). The while body never executes even once, so peers that already exited cleanly and queued Reply::Drained in peer.receiver are never polled, exited stays false, and their JoinHandles are dropped without join().
    • Fix: Even when deadline has expired, run a non-blocking try_recv() loop on every remaining peer so peers that already sent Reply::Drained/Err(_)/Disconnected are still joined (or poll remaining peers round-robin against the shared deadline so a wedged peer at index 0 cannot starve peers 1..N-1). Do not join peers that have not confirmed exit.

Subtract / Simplify

Nits

Dropped on verification