Code correctness report · NVIDIA/hyperflare-inference #725

Raw Markdown for agents: https://autobot.eidonix.com/p/e019be11-8162-418f-91d2-9b6438c30529.md

Deep correctness / invariants / hot-path audit — PR #725 (helios/native/roce_proxy.c, +11/−14, head 8b06cda)

Scope note (important, affects how the rest should be read)

pr_files and the PR description both say 1 file, +11/−14, and that matches the real change. However the pr_diff tool returns a ~2 MB diff touching dozens of files (helios/src/async_transfer/*, .github/workflows/*, docs/*, AGENTS.md (not opened), …). That is a stale-mirror artifact, not this PR's content: read_file ref=main reports roce_proxy.c at 1971 lines vs 2248 at head, and search_code ref=main finds no KIND_RING_RS and no roce_create_with_gids, both of which are present at head. search_history is also broken against this mirror (Could not read c513e46… cannot simplify commit ef38cb9…). I therefore audited only the four rotated loops; the ring_bidir / per-HCA-GID / RING_WINDOW content visible in that diff belongs to older PRs and is out of scope here.

The change

// post_op (1294-1307), post_pipe_chunk (1437), post_credits (1556), run_varlen_op (1939)
-    for (int p = 0; p < c->world; p++) {
-      if (p == c->rank) { continue; }
+    for (int step = 1; step < c->world; step++) {
+      int p = (c->rank + step) % c->world;

1. Callee / design-invariant resolution (all opened at 8b06cda)

Helper Definition Verdict
ring_relayed 370-374 Depends only on (rank, peer) distance — rotation-invariant.
post_striped 1194-1260 Per-destination, self-contained (reserve → ibv_post_send → outstanding[p][lane]++). No cross-peer state.
ring_post 1145-1188 Uses c->ring_serial[rail] (1159) shared across targets on a rail — see ordering analysis below.
reserve / reserve_limit 886-911 Waits on outstanding[p][lane] of one (h,p,lane); rotation only changes which peer we stall on. ROCE_RESERVE_OPS bump at 157 is not part of this PR.
credits_arrived 1589-1597 Unchanged and deliberately not rotated; it is a read of credit[p], order-free.
pipe_chunk_arrived 1470-1481 Indexes flags by source ((world + s)); destination order irrelevant.
Ring relay deserialization ring_service_slot 1006-1085 (validation ring_distance(previous,target) != ring_distance(rank,target)+1 at 1025), ring_service 1094-1139 (ascending-serial sort at 1117-1135) See invariant I3.

Normative reference docs/roce-ring.md (rank order 0..N-1, shorter-path routing with ties to increasing rank: lines 32-63) constrains paths, not per-op posting order; nothing in it pins the ascending destination loop.

2. State-order / invariant tracing — all four sites

I1 — permutation completeness. roce_layout rejects world < 2 (line 389: if (world < 2 || world > ROCE_MAX_PEERS …)), so c->world is 2..16 and % c->world is never a zero divisor. {(rank + step) mod world : step = 1..world-1} = Z_world \ {rank} exactly once each. ✓ (Also holds for world = 2, where the old p==rank skip becomes the single step=1 iteration.)

I2 — relayed-first two-pass preserved. post_op line 1300: if (c->ring != NULL && (ring_relayed(c, p) != 0) != want_relayed) continue; is untouched; the rotation inside the pass loop permutes destinations within each pass, so the documented "post relayed multi-hop peers first so the critical-path hop starts earliest" (comment 1220-1222) still holds per pass. post_pipe_chunk's guard at 1439 (phase == 1 && c->relay && c->relay_via[p] >= 0) is verbatim preserved — critical because roce_set_relay requires plan[rank] == -1 (838-849) while relay_via is calloc'd to 0, so a wrong predicate would self-skip a real peer rather than merely reorder.

I3 — ring serial ordering under rotation (the only non-obvious risk). ring_post allocates serial = ++c->ring_serial[rail] (1159-1160) shared by every target on a rail, and relays require per-next-hop ascending serial order (ring_service_slot: serial < seen ⇒ "invalid ring mailbox", 1022-1033; ring_pending gate 1020). Claim checked: for a fixed next hop, the set of destinations routed through next is the contiguous cyclic arc next, next+1, …, target_max (ring_next_from 363-368, ties clockwise). A cyclic shift p = (rank + step) mod world maps that arc to a contiguous ascending run within the original arc ordering, so the sequence of serials arriving per next-hop group stays ascending. ✓ No serial < seen rejection is introduced. (Chain mode ring_open is the monotone case, likewise preserved.)

I4 — same-iteration stale-state scan. In run_varlen_op the rotation sits inside while (posted < chunks); the loop body reads ctrl[CTRL_READY_VL + posted], posts all peers, then posted++. The ready word is read once before the peer loop and not re-read mid-iteration, and posted/idle are mutated only after all peers are posted — no read/write reordering hazard, no counter or flag corruption on the error paths (return -1 happens before posted++, and all post_striped failures already poison the transport via atomic_store(&c->failed, 1) at 2137-2139).

I5 — other all-peer loops were (correctly) left in rank order: credits_arrived 1591, outstanding scan 1610, forwarded[] init 1654, setup loops 508/673/747/767/806/838/850 and ring_relays_origin 791 — all read-only or topology-building. Rotating them would have been wrong; the PR did not.

3. Adversarial boundary inputs

4. Hot-path complexity

No new allocation and no asymptotic change: the added % c->world is one integer division per peer per chunk (integer modulo on x86-64 is ~20-26 cycles). Worst case post_pipe_chunk runs (world-1) × n_rail per chunk, i.e. (2..16-1) × 2 ≈ 30 extra divides per chunk; with chunks ≤ 64 that is ≤ ~2k cycles (≈0.5 µs at 4 GHz) per pipelined op, against RDMA chunk latencies of tens of µs. post_op adds (world-1) × n_rail divides per one-shot op. This is noise on the critical path; the classic compiler-strength-reduction tweak (int p = c->rank + 1; if (p == c->world) p = 0;) would remove it if desired, but it is not a defect.

5. Findings

Minor — tests/preparation/test_roce_proxy_parity.py:35-65 fails at head 8b06cda; the pin it compares against was not advanced.

# tests/preparation/test_roce_proxy_parity.py:48-51
vendored_body = b"".join(lines[PROVENANCE_LINES:])
upstream_path = _upstream_roce_proxy()
upstream_raw = upstream_path.read_bytes()
if vendored_body != upstream_raw:
# pyproject.toml:47  (unchanged by this PR)
flashinfer-python = { git = "https://github.com/local-inference-lab/flashinfer.git", rev = "1441ce862ffbc9d8550fdda7ad90e97ca04f4b8e" }

The test asserts the vendored body (after the 9-line provenance header, PROVENANCE_LINES = 9 at line 17) is byte-identical to the pinned flashinfer _roce_proxy.c (not opened). That invariant held before the PR, and this PR edits the vendored body while leaving pyproject.toml:47 at a revision that predates the companion local-inference-lab/flashinfer#221; the cumulative error message at lines 62-65 ("helios/native/roce_proxy.c diverged from pinned FlashInfer _roce_proxy.c (not opened)") triggers immediately. The mismatch is purely textual (diff --git heredoc at lines 1794-1819 explaining the 1-hop ring kinds), so the transport ABI is unaffected. Fix: bump pyproject.toml:47 to the merged commit of local-inference-lab/flashinfer#221 in this same PR (or land #221 first and re-point), then re-run pytest tests/preparation/test_roce_proxy_parity.py. Caveat on severity: no CI workflow under .github/workflows references tests/preparation (grep: no matches), so this does not break a required check today, and helios/native/roce_proxy.c is itself only compiled by helios/build.rs:83-88 (not opened) — hence Minor rather than Blocker.

Minor (behavioral accuracy of the claimed guarantee, not a code defect) — the rotation is a collision reducer, not an incast eliminator, because there is no barrier between per-rank posting loops. Each rank posts step = 1 … world-1 back-to-back with no cross-rank synchronization, so the permutation property holds only when two ranks happen to be at the same step index simultaneously. With per-step skew of one step or more, two ranks can still drive the same destination concurrently. The practical effect is that guaranteed (world−1):1 incast becomes a per-step collision probability of roughly 1/world — a real improvement, but the PR text's "eliminating synchronized (world−1):1 incast" overstates it, and this is exactly why the "live switched-mesh multi-node benchmarking has not been run" limitation matters. No code change required; wording/validation only.

6. Explicitly checked and cleared (no finding)

Bottom line: the four-loop rotation is arithmetically exact (world ∈ [2,16], every peer visited once per pass), preserves the relayed-first two-pass ordering, preserves the relay_via relay filter, and does not disturb the ring mailbox serial-ordering proof or any flag/ABI invariant; its hot-path cost is a few dozen integer divides per op. The only directly verified defect is the now-stale pyproject.toml:47 pin that makes tests/preparation/test_roce_proxy_parity.py fail (Minor), plus the overstated "eliminating incast" claim given the absence of any inter-rank barrier.