Correctness and contracts report · NVIDIA/hyperflare-inference #576

Raw Markdown for agents: https://autobot.eidonix.com/p/554659a3-e05e-47ff-982e-25d853f43982.md

Correctness, Contracts & System-Level Consequences — PR #576

Reviewed at pr/576 head 4b41ddc: eos/src/unix.rs (+145), eos/src/windows.rs (+3), helios/native/roce_proxy.c (+71), helios/src/execution/parallel.rs (+1), helios/src/execution/worker.rs (+1), helios/src/replay.rs (+4/−1), helios/src/server/runtime.rs (+1) — verified with pr_files. Callers, contracts and policy docs opened in context: runtime.rs, worker.rs, replay.rs, parallel.rs, threaded.rs, selene/src/shared/codec.rs, NOTICE, docs/prefix-cache-offload.md, plus main's helios/build.rs.

Key findings

# Severity Finding
F1 Blocker Editing the vendored roce_proxy.c falsifies four in-tree "keep identical" witnesses; the Flare-owned seam that would avoid the edit already exists on main (#589).
F2 Major runtime.rs:568 is the first statement of the flare-model closure: every later child thread (ranks, offload, disk, image-prep) inherits the X925-only mask although it is deliberately demoted to spill onto efficiency cores — directly contradicting the in-tree policy in docs/prefix-cache-offload.md:863-867.
F3 Major selene/src/shared/codec.rs:41 sizes the rayon KV-codec pool from available_parallelism(), which honours that inherited narrowed mask → the host encode/decode pool silently shrinks on the path this PR never benchmarks.
F4 Major parallel.rs:539 mutates the caller's own affinity mask inside an unsafe fn whose Safety doc says nothing about it; no restore, no return value, hits the peer-process main thread and the Python interpreter thread.
F5 Major flare-rank-* (threaded TP) threads are pinned only by inheritance; the reviewer's proposed fix (move the call near worker.run) would silently unpin them.
F6 Minor The selected.len() >= 2 floor ignores how many threads are being confined; on a 2P + kE cpuset, k+2 threads share 2 cores.
F7 Minor Affinity failures and the 0.9 capacity cut are silent — no log, metric, flag, config or env — so the behaviour is unobservable except through the thread rename this same PR adds.
F8 Minor Neither new affinity function runs in any CI job (x86_64 + Windows only); the Rust and C twins already diverge with no shared test vector.

1. Correctness, Safety & Platform Parity

F1 — Blocker: the vendored-file contract is broken, and the sanctioned seam already exists

helios/native/roce_proxy.c:1505-1569 adds a 65-line static void pin_high_capacity_cpus(void) inside the vendor file, called at :1572-1577. The file's own header forbids that:

// helios/native/roce_proxy.c:6-8 (verified)
// Vendored from FlashInfer's pinned preparation dependency
// (flashinfer/experimental/b12x/comm/roce/_roce_proxy.c (not opened), proxy ABI 14).
// Keep the source below identical so preparation and serving share the transport ABI.

Three more in-tree witnesses, all opened:

NOTICE:18-19
The proxy is compiled into Linux aarch64 builds. Its implementation is unchanged
from that revision; Flare adds a license and provenance preamble.

THIRD_PARTY_NOTICES.md:48-52
The Linux aarch64 runtime also compiles the RoCE proxy in `helios/native/roce_proxy.c`,
contributed by its original author from the pinned FlashInfer/b12x source.

docs/roce-ring.md:362-364
When changing the protocol, keep the vendored source identical to the dependency after
its provenance header and verify their ABI and collective-region layouts together.

The divergence is also not recorded in the file that already tracks proxy-parity debt (docs/TODO.txt:80-86), which this PR does not touch.

Decisively, main now supplies the exact place this change belongs. After #589 (ba3afb13, merged 2026-11-28), helios/build.rs:67-77 on main (verified) compiles only the Flare-owned translation unit:

println!("cargo:rerun-if-changed=native/roce_proxy.c");
println!("cargo:rerun-if-changed=native/roce_proxy_dlopen.c");
cc::Build::new()
    .file("native/roce_proxy_dlopen.c")

and helios/native/roce_proxy_dlopen.c:7-9 states the invariant in a maintainer-authored file: "…while keeping the vendored roce_proxy.c byte-for-byte identical to FlashInfer." At pr/576 the build still compiles native/roce_proxy.c directly, so this PR is editing the one file the tree now explicitly means to keep untouched.

Impact: the NOTICE/provenance claim in shipped binaries becomes false; the transport-ABI identity argument (preparation and serving share the same proxy source) is weakened for the one code path that carries cross-node collectives; and the 65 lines of C duplicate the Rust logic with no test anywhere (see F8). It also makes a future re-vendor of roce_proxy.c from FlashInfer #156 a manual merge in exactly the polling path.

Fix: delete roce_proxy.c:1505-1570 and the pin_high_capacity_cpus() call, keeping only pthread_setname_np if the name is needed for observability (see the measurement caveat below). Apply the pin from Flare-owned code — either flare_eos::prefer_high_capacity_cpus() on the proxy thread from the Rust side around proxy creation, or from the already-Flare-owned helios/native/roce_proxy_dlopen.c. Leave roce_proxy.c byte-identical; if the divergence is kept anyway, it must be recorded in docs/TODO.txt:80-86 and the NOTICE:18-19 / THIRD_PARTY_NOTICES.md:48-52 wording corrected.

F4 — Major: serve_rank mutates the caller's mask with no restore and no documented side effect

/// # Safety
/// The caller retains all graph owners and b12x IPC mappings when drained is
/// false. A failed collective requires coordinated process termination before
/// reclaiming those resources; this function never synchronizes a stranded graph.
pub unsafe fn serve_rank(
    manifest: ExecutionManifest,
    socket: RankStream,
    rank: usize,
    world: usize,
) -> Shutdown {
    flare_eos::prefer_high_capacity_cpus();

— helios/src/execution/parallel.rs:527-539, verified

Unlike the other three call sites (runtime.rs:568, worker.rs:71, replay.rs:174), which are first statements of newly spawned threads, serve_rank runs on the caller's thread: flare-cli/src/main.rs:560 (the peer process's main thread) and heliopause/src/python.rs:548 (the Python interpreter thread, inside py.detach). The narrowed mask persists past drain and is inherited by every thread that process or the Python interpreter creates afterwards; the function returns only Shutdown, so the caller can neither observe nor undo it, and the Safety section documents no affinity effect.

Impact: silent process-wide behavioural change in an in-process/Python-embedded deployment, applied by a function whose contract is about graph ownership. Anything the host app spawns after serve_rank that does CPU work (log shippers, tokenizers, its own worker pools) is confined to the performance cores.

Fix: drop this call site and let the rank's own executor closure pin itself (as worker.rs:71/replay.rs:174 do), or save and restore the previous mask before returning and document the effect in # Safety.

Areas verified sound


2. Unintended system-level consequences

F2 — Major: the pin at the head of the flare-model closure confines threads that were deliberately demoted off the model cores

let thread = thread::Builder::new()
    .name("flare-model".into())
    .spawn(move || {
        flare_eos::prefer_high_capacity_cpus();
        if matches!(peers, Some(crate::execution::RankPeers::Processes(_)))

— helios/src/server/runtime.rs:565-569, verified

Because this is the closure's first statement, every thread spawned later in that call chain inherits the narrowed X925-only mask: RankExecutor::new (:585), crate::offload::open (:698) → flare-offload-{rank} (helios/src/offload/transfer.rs:509-511) and flare-offload-disk (selene/src/offload.rs:676 → selene/src/disk.rs:358-360) and flare-input-records (selene/src/input.rs:268-271), and ImagePreparation::new (:721) → its thread::spawn at runtime.rs:1011; also the rayon KV-codec pool (F3).

Those threads are deliberately demoted so they can spill onto efficiency cores:

docs/prefix-cache-offload.md:863-867 (verified)
- CPU: transfer threads sleep on event waits and channel receives; the disk
  thread computes checksums and submits I/O. Both use `SCHED_BATCH` with a
  positive nice value to reduce contention with the model worker, HTTP runtime,
  and frontend workers. Adding CPU affinity requires a serving-latency
  measurement that shows a benefit.

with the demotion implemented at helios/src/offload/transfer.rs:531 (lower_priority()), selene/src/disk.rs:489-491, selene/src/input.rs:271, selene/src/shared/codec.rs:47-54 (libc::nice(10)) over eos/src/unix.rs:77-83 (SCHED_BATCH + setpriority).

Impact: nice/SCHED_BATCH reduces priority, it does not free cores. After this change the demoted host-I/O and checksum threads can no longer run on the 10 A725 efficiency cores at all; they contend with the model worker, the CUDA launch thread and the busy-polling proxy on the same 10 X925 cores. That is the opposite of the stated intent, and it is exactly the case the in-tree policy says requires a serving-latency measurement before adding affinity — which the PR does not supply (its numbers are inter-graph gap and decode tok/s on the pinned paths, not the offload/encode paths). On GB10 with --roce-ring and prefix offload active simultaneously, one slow offload burst can now preempt the launch thread on the shared subset — a plausible mechanism for exactly the kind of tail-latency jitter the PR claims to remove, with no measurement to exclude it.

Fix: do not narrow at the head of the flare-model closure. Call prefer_high_capacity_cpus() only inside the closures that own latency-critical work (the executor/flare-rank-* threads, flare-cuda), or explicitly re-widen/reset the mask before crate::offload::open (runtime.rs:698) and ImagePreparation::new (runtime.rs:721). Either way, add the serving-latency measurement (with offload + prefix cache enabled) that docs/prefix-cache-offload.md:863-867 demands, and update that doc.

F3 — Major: the KV-codec pool silently shrinks and is pinned by inheritance

POOL.get_or_init(|| {
    let threads = std::thread::available_parallelism()
        .map(|n| (n.get() / 2).clamp(1, 24))
        .unwrap_or(4);
    rayon::ThreadPoolBuilder::new()
        .num_threads(threads)
        .thread_name(|i| format!("flare-kv-codec-{i}"))

— selene/src/shared/codec.rs:40-46, verified

available_parallelism() on Linux honours the calling thread's affinity mask. The pool is lazily initialised on an offload thread first touched after runtime.rs:568 (helios/src/offload/transfer/codec.rs:353, :514), so on GB10 it sees 10 CPUs instead of 20 and sizes to 5 threads instead of 10 — and those threads then inherit the same narrowed mask while running at nice(10).

Impact: host KV encode/decode parallelism halves on the prefix-cache path, unmeasured by this PR. On a machine where the whole point of the change is more consistent throughput, a 2× reduction in codec concurrency is a plausible regression on prefix-heavy workloads, and it is invisible because nothing logs the pool size.

Fix: size the pool from the process-start (pre-narrowing) parallelism — compute and cache available_parallelism() before any affinity change, or derive it from the full capacity list — and leave the pool's threads on the default, demoted mask. Same class of hazard exists at helios/src/frontend/mod.rs:333-337.

F5 — Major: the threaded-TP ranks are pinned only by accident

let thread = thread::Builder::new()
    .name(format!("flare-rank-{}", index + 1))
    .spawn(move || {
        let _exit_guard = PeerExitGuard(peer_ring.clone());

— helios/src/execution/threaded.rs:652-655, verified (no prefer_high_capacity_cpus() anywhere in that closure)

and the one site that does call the helper sits on a thread documented as non-serving:

helios/src/execution/worker.rs:36-37
/// Synchronous control surface for bootstrap/qualification callers on other threads.
/// The native scheduler owns its rank executor directly without this channel boundary.

The flare-rank-* threads are therefore pinned in serving only because runtime.rs:568 narrowed the parent first. Coverage depends on the ordering of two unrelated statements: the reviewer's suggested remedy ("call it just before worker.run") would silently unpin every threaded rank, and any refactor that moves the closure head loses the pin with no test failing.

Fix: call prefer_high_capacity_cpus() explicitly at the head of the flare-rank-* closure, and add a test that asserts the child thread's mask is a subset of the selected set rather than relying on inheritance.

F6 — Minor: the "≥ 2 CPUs" floor ignores how many threads are being confined

if selected.len() >= 2 && selected.len() < allowed_with_capacity.len() {
    Some(selected)
} else {
    None
}

— eos/src/unix.rs:205-209; identical twin at roce_proxy.c:1566

On a two-tier cpuset such as 2 performance + 8 efficiency cores, or a three-tier part where the midpoint fallback at eos/src/unix.rs:195-204 selects 2 of 3 tiers, the whole set — model worker, flare-cuda, TP ranks, the RoCE proxy, codec threads — is confined to 2 cores. Nothing compares the selected size with the number of threads that will be pinned.

Fix: take the expected thread count as a parameter (or refuse + log when selected.len() is below it), instead of a bare 2-core floor.

F2/F3 secondary note — no contention added on the hot path

There is no lock, no channel, no allocation and no I/O added to any per-request path. The helper runs once per thread creation. The consequences above are all about where threads run afterwards, not about added serialization. No head-of-line blocking, no memory amplification, no buffering change, no failure-propagation blast radius: if the sysfs read fails the mask stays wide and serving continues.


3. Architecture, contracts & charter compliance


4. Tests & claim accuracy

F8 — Minor: neither new affinity function ever executes in CI, and the twins already diverge

.github/workflows/native-serving.yml:16-21 (not opened)
matrix:
  include:
    - os: ubuntu-24.04
      target: x86_64-unknown-linux-gnu
    - os: windows-2022
      target: x86_64-pc-windows-msvc

Only select_high_capacity_cpus is tested (eos/src/unix.rs:254-314, three tests calling the pure selector). prefer_high_capacity_cpus and pin_high_capacity_cpus are never exercised: on x86_64 /sys/devices/system/cpu/cpuN/cpu_capacity does not exist, so the early return at eos/src/unix.rs:228-230 runs; the RDMA job (:109-113) only cargo checks; and there is no aarch64 job anywhere except the arm64 archive smoke build in release.yml (not opened), so the GB10 path never runs even when CI does.

The two implementations already differ in ways a shared test would catch:

Fix: make the C helper testable (a small entry point taking (cpu, capacity) fixtures, compiled under a test target) and feed both implementations one shared fixture table; better, delete the C duplicate per F1 and test only the Rust function.

Claim accuracy


Open questions / what could not be verified

  1. Rebase collision. #589 also rewrote eos/src/unix.rs (+60/−1), adding map_host_advises_hugepages_and_prefaults_zeroed_pages at eos/src/unix.rs:207-248 on main — the same file and region into which #576 appends its prefer_high_capacity_cpus and its three tests. A textual conflict in that module is likely but was not asserted here (neither revision was rebased).
  2. Author intent. Whether the author will rebase, re-vendor via FlashInfer #156, or move the pin/rename into the now-existing roce_proxy_dlopen.c seam. No comment from the author since opening (last update 2026-11-28 22:12).
  3. Commit-body content (the 6-launch / "follow immediately" mismatch raised by the reviewer) could not be retrieved with these tools; it remains reviewer-asserted.
  4. Sibling #577 (open, same author, same vendored file) sits behind the same wrapper and raises the same merge-order/re-vendor question in either order; it was not re-examined for this lens.
  5. No aarch64 CI run exists for any part of this PR, so none of the new behaviour has ever been executed by CI — every correctness claim about the GB10 path rests on the author's local soak.