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
world = 2: one peer,step ∈ {1}→ identical to before. ✓world = 3, rank 1:p = 2, 0— per-step permutation{1→2, 2→0, 0→1}and{1→0, 2→1, 0→2}. ✓world = 4, rank 0:1,2,3/step=2:2,3,0/step=3:3,0,1. ✓world = 16, rank 15:p = 0,1,…,14; rank 10:11,12,…,15,0,…,9. ✓- Empty chunk tail in
post_pipe_chunk(hi == lo,total < chunk_packs): still posts a zero-byte flag write to each peer (comment 1192-1193); rotation only changes order, so the "receivers wait uniformly for every chunk" property is intact. ✓ - Chain/
ring_open:ring_relayed372 (peer != rank+1 && peer != rank-1) is rotation-invariant; the two-pass filter still separates relayed from direct. ✓ - Degenerate
world == 1would divide-by-zero-free but loopstep=1; step<1never executes — unreachable anyway sinceroce_layoutrejectsworld < 2.
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)
- Relay two-pass ordering — preserved per pass (I2).
relay_via[p] >= 0relay filter — unchanged; no self-skip introduced (I2).c->ring_serial[rail]shared-counter ordering — relay next-hop groups are contiguous cyclic arcs, so a cyclic shift preserves ascending intra-hop serial order; theserial < seenmailbox rejection atroce_proxy.c:1022cannot newly fire (I3).- Flag ownership — pipe flags are keyed by source
c->rank(1456-1459) and read by source (world + s, 1471-1473), never by destination, so destination order cannot affect flag semantics. - Error / partial-post paths — a mid-loop
return -1leaves no counter or slot half-updated differently than before;outstanding[p][lane]is only incremented after a successfulibv_post_send. - ABI — the loop order is not part of
roce_layout,roce_blob_t, or the kernel-visible control words, soROCE_ABI_VERSION 14andhelios/src/execution/roce.rs:23 PROXY_ABI = 14remain valid; the Rust tests (native_proxy_abi_matches_core_contract,peer_records_require_one_native_ring_protocolasserting blob size 1176,roce_layoutgeometry) are untouched by this change.
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.