Deep Code Correctness, Invariants & Hot-Path Audit — PR #707 @ 81ef561
Partitioned into 3 disjoint slices (C proxy / helios Rust / CLI+heliopause+ignition+parity) and audited with the full 4-part protocol (callee/enum resolution, same-loop state ordering, adversarial boundary inputs, hot-path big-O) on each. I independently re-read and verified the C findings below.
FINDING 1 — Major: credit_phases() holds only ONE phase on a pipe↔1-hop transition, leaving the other phase of a two-phase op unguarded (silent peer-row/flag corruption)
Diff site: helios/native/roce_proxy.c:1530-1547, buggy branch at 1536-1538 (new in this PR).
static uint32_t credit_phases(uint32_t prev, uint32_t kind) {
uint32_t prev_p = kind_phases(prev);
uint32_t cur_p = kind_phases(kind);
if (prev_p == 0 || cur_p == 0) {
return 0;
}
if (kind_1hop(prev) != kind_1hop(kind)) {
return (cur_p & PIPE_PHASE_RS) != 0 ? CREDIT_RS : CREDIT_AG; // <-- drops the other phase
}
Callee / enum resolution (verified by me):
kind_phases(roce_proxy.c:1508-1522):KIND_TWOSHOT(1) andKIND_RING_RSAG(9) →PIPE_PHASE_RS|PIPE_PHASE_AG(=3);KIND_REDUCE_SCATTER(3)/KIND_RING_RS(7) →PIPE_PHASE_RS;KIND_GATHER_SHARDS(4)/KIND_RING_AG(8) →PIPE_PHASE_AG. Kinds defined:187-196;PIPE_PHASE_RS 1u/PIPE_PHASE_AG 2uat:207-208;CREDIT_RS 1u/CREDIT_AG 2uat:185-186.kind_1hop(:1524):kind >= KIND_RING_RS && kind <= KIND_RING_RSAG.- Credit mask consumers:
run_pipe_opposts RS at:1668(!(credit & CREDIT_RS)) and AG at:1676(!(credit & CREDIT_AG)), relay forward at:1684;run_ring_bidir_opgates AG forwarding at:1823, RS at:1846, AG step 0 at:1867. The mask is cleared in one step when all peers arrive (:1665-1667,:1816-1818), so holding more bits cannot deadlock. - The file's own normative statement this branch contradicts —
:78-81: "For those transitions every rank writes a start-of-op credit … and holds the hazardous phase until every peer's credit reached the op", and the newly added:92-93: "Cross-family transitions between two-shot/pipe and ring_bidir ops exchange start-of-op credits because their pipe_recv layouts overlap." The code holds one phase, not every overlapped phase. - Region fact that makes the overlap real:
pipe_recvrows are2*shard_capwide (post_pipe_chunk,:1452-1454), while 1-hop half-shard slots areshard_cap/2(:1747-1752), so 1-hop slot k aliases pipe row k/2, i.e. both phases interleaved; 1-hop AG flag rows areW+dir(:1833-1834) which are exactly the pipe phase-1 flag rows read bypipe_chunk_arrived, whose row is(world + s)(:1469-1472) — flags are shared across families too.
Concrete counterexample (prev = KIND_GATHER_SHARDS, cur = KIND_RING_RSAG, world W=4, rank R=0, 2 rails, chunks=4, chunk_packs=8, nbytes=1024 → total=64 packs, half_max=32, widest=8, half_cap large):
prev_p = 2, cur_p = 3, kind_1hop(4)=0 != kind_1hop(9)=1 → returns CREDIT_RS only. The AG half (do_ag) is therefore never gated: at :1823 and :1867 credit & CREDIT_AG == 0 from the first loop iteration, so with dir=0, s=1, c_idx=0 we take src_slot = 2*(4-1)+0*(4-1)+(1-1) = 6, dst_slot = 7 → bytes [3·sc, 3.5·sc) written into peer 3's pipe_recv row 3 = (source 1, phase 1) region while peer 3 may still be reading that row for its predecessor op, and the AG flag write lands on row W+0 = 4 = peer 3's pipe (source 0, phase 1) flag row. Result per :76-78: "Either write could replace a flag before the peer saw it (a wait timeout) or the rows it is reading (silent corruption)." The same under-hold exists in the reverse direction (prev = KIND_RING_RSAG(9), cur = KIND_TWOSHOT(1) → CREDIT_RS only, while :1676 posts pipe phase 1 unguarded).
Fix — hold every phase the new op performs:
if (kind_1hop(prev) != kind_1hop(kind)) {
uint32_t need = 0;
if (cur_p & PIPE_PHASE_RS) need |= CREDIT_RS;
if (cur_p & PIPE_PHASE_AG) need |= CREDIT_AG;
return need;
}
Safe because credits_arrived clears the whole mask once every peer's credit lands. Escalates to Blocker once the companion recipes PR (#114) enables KIND_RING_RSAG: it is an unfixable-after-the-fact silent data-corruption race, and no in-tree test covers it (roce.rs:695-746 only exercises roce_set_relay rejection).
FINDING 2 — Minor: the mixed-GID legacy guard is keyed on a parameter name, so a legacy AllReduce that declares gid_indices=None/**kwargs is misclassified as per-HCA-capable, silently preparing fewer rails than serving connects
Diff sites: ignition/preparation/collectives.py:85-97; test tests/preparation/test_roce_proxy_parity.py:77-81, 110-119.
if "gid_indices" in inspect.signature(roce.AllReduce.__init__).parameters:
gid_kwargs = {
"hca_names": [name for name, _ in devices],
"gid_indices": [gid for _, gid in devices],
}
The test models "legacy" as def __init__(self, *, gid_index=None, **kwargs), so it exercises only the **kwargs-free case. Counterexample: a legacy __init__(self, *, gid_index=None, gid_indices=None, **kwargs) (or a **kwargs-only signature) plus roce_devices() == [("roce0",3),("roce1",5)] selects the gid_indices branch, never raises the RuntimeError("… distinct GID indices") the code claims guarantees "fail loudly rather than dropping rails", and the hca_names/gid_indices kwargs are swallowed. Fix: require both names to be explicit parameters and reject a VAR_KEYWORD-only signature (per_hca = {"hca_names","gid_indices"} <= params), and add a third test class whose signature accepts but ignores gid_indices, asserting the mixed-GID host raises. Minor because the pinned environment (pyproject.toml:47) does honour gid_indices.
Verified sound (no defect found)
roce_blob_t1168 → 1176 (roce_proxy.c:257-269): two appended fields, natural alignment; validation inroce_connect(:744-763) is symmetric (each side compares against its ownRING_WINDOW/ring_bytes(world)) and runs in the first peer loop before any region write; a legacy 1168-byte record is rejected earlier in Rustpeer_blobs(roce.rs:86-95) and the ABI gate (:164).roce.rs:491assertssize == 1176,:501-503asserts 1168 rejection (intentional tripwires).- Send-queue arithmetic:
ROCE_SEND_DEPTH 512(:150),ROCE_RELAY_OPS = 64(:156),ROCE_RESERVE_OPS = 48(:157),_Static_assert(RESERVE < RELAY)(:158); static asserts64*3+16*16 = 448 ≤ 512and222+192+4*16 = 478 ≤ 512(:225-230). Onlyoutstanding[p][0]is read byreserve/ring_service_slot/ring_submit/post_credits, so lane-0 ≤ 448 holds forworld = 2..16;world > 16is rejected byroce_layout(:389). The "48 < 64 preserves relay headroom" claim is arithmetically correct. - 1-hop slot/flag bounds: RS slots
dir*(W-1)+s ≤ 2W-3, AG src/dst≤ 4W-5 = 4(W-1)-1(:1831-1834,:1871-1872) exactly fitting the4(W-1)half-shards;r_word ≤ 63by:1776; chunk-coverage andhalf_capguards at:1786-1795(including the clamped empty-chunk path). CTRL word ranges (RS 64-127, AG 128-191, VL 256-767, CREDIT 768-783) do not overlap. drain_allordering (:1271-1276):drain_cqsbeforering_serviceis required — the reverse could spin on a completion already reaped.post_creditsat:1552-1587is correct (rail-0/lane-0 inline 4-byte write, or empty mailbox write for non-neighbours).ring_service_slotre-checksserialagainstring_inflightat ack time (:1010) andring_pendingpreserves two-pass ordering;wr_idencode/decode (:1219/1237,:927/965/1050,:866-871) is consistent, sooutstanding[peer][lane]cannot underflow.roce_create_with_gidsvalidatesgid_indices != NULLand0..=255(:563-575) beforecalloc/anyibv_*call;sgid_indexisuint8_t(:702), so the cast is exact.- helios Rust slice (
helios/src/execution/roce_fabric.rs,roce.rs): no defect.Shape/Linksare complete partitions (roce_fabric.rs:231-293);relay_plan(:1021-1061) implements "even world ≥ 4,Links::All, every rank exactly one mutual direct partner" and fails closed (None) otherwise — verified for world 1,2,3,4,5,6,16, duplicate partners, all-false/all-truedirect, self-partner.gid_indicesis indexed by local HCA,directby peer rank — no index-space swap; all three parallel vectors are built from one filtereddevicesvector (:416-476),pick_gid_index(:409-415) is stateless so no stale accumulator, andfindover0..16ascending really is "lowest".RoceTransport::openvalidatesgid_indices.len() == hcas.len()(roce.rs:214-220) before zeroing the region and beforeroce_create_with_gids;connectcallsroce_set_relaybetweenroce_connectandroce_start(:344-354) exactly as C requires, andvalidate_relay_plan(:102-132) mirrors C'sroce_set_relaychecks statement-for-statement (roce_proxy.c:838-849), withvia < 0short-circuiting theas usizecast — no accept-then-reject, no leftover plan (the plan lives in immutableself.topology). No leaks on error paths (Drop→roce_destroy, one call site each). Hot path:partners/relay_planis O(world²)Planner::peercalls (240 at world=16) but runs once per connect, never per collective step;health()/posting never readsrelay_plan. Tests are not tautologies (the mixed-GID test would fail under a reverted host-wide index; the relay test independently recomputes writers/forwarders). - CLI/heliopause/ignition slice:
cluster.rs:96-114appends", all-gather relay"only whentopology.relay_plan.is_some(), which isMesh-only — ring/chain/switch onlysummaries unaffected.flare-cli/src/doctor/spark.rs:152-181keepsfabric.endpoints[i]aligned withfabric.gid_index_for(i), treats a missing index as unresolved (no OOB), computes sufficiency over all accumulated devices (ready.is_empty()), and reports unselected devices separately.heliopause/src/python.rs:710-727really exportsroce_devices() -> Vec<(String,u32)>in discovery order, consistent withroce_gid_index()'s first-device/PREFERRED_GID_INDEXfallback. The parity test cannot pass vacuously:PROVENANCE_LINES = 9matches the actual header (roce_proxy.c:1-9, line 9 blank), itpytest.fails rather than skips when flashinfer is absent, asserts LF-only, and byte-compareslines[9:]against the whole upstream file; the monkeypatch ofsys.modules["flare_heliopause"]/b12x.comm/b12x.comm.rocematches the function-local imports atcollectives.py:64-65.pyproject.toml:47rev is valid 40-hex and is the same sourceuvinstalls, so pin and test cannot skew. Doctor/cluster cost is O(devices) startup-only withMAX_DEVICES = 4; no hot-path work. - Docs ↔ code consistency (as a runtime contract, not wording):
docs/roce-ring.md:109-114,129,161-171matchesRING_WINDOW = 16, ~2.008 MiB/rank (32.13 MiB at 16 ranks) againstring_bytes = 16*16*2*(65664+8+128), and the 1-hop/relay behaviour.
Unverifiable here: byte-for-byte parity against FlashInfer 524799c4 (upstream tree not present in-repo), multi-node wire behaviour, and the claimed 25% switch-traffic / 1.20x–1.46x speedups (single host, as the PR itself states).