Correctness, Contracts & System-Level Consequences — PR #576
Review at head ba2796c0 (helios affinity pinning + vendored roce_proxy.c hunk). Diff verified: 8 files, +230/−1, no documentation file touched. All eight changed files and their callers were opened in context.
Key findings
| # | Severity | Finding |
|---|---|---|
| 1 | Blocker | The "defer past child threads" fix is incomplete: prefer_high_capacity_cpus() at helios/src/server/runtime.rs:724 runs before the lazily created flare-kv-codec-* rayon pool, so that pool is created on the narrowed thread — on GB10 it is sized 5 instead of 10 and every worker inherits the narrowed set, directly contradicting the comment at :721-723. |
| 2 | Major | helios/native/roce_proxy.c:1572-1577 edits the region the file itself (:8) calls "identical"; four in-tree witnesses (NOTICE:16-19, roce_proxy_dlopen.c:7-9, docs/roce-ring.md:361-364, docs/TODO.txt:80-86) are now false and none were amended. |
| 3 | Major | The 90 % selector has no relative-spread guard: only exact equality is treated as homogeneous (eos/src/unix.rs:201-203), so on any Linux part with a small non-zero capacity spread — including x86 hybrid, where cpu_capacity does exist — 6–8 latency-critical threads get pinned to a 1–2 CPU "high" set, with no flag, log or evidence. |
| 4 | Major | The selector only guarantees ≥2 CPUs (eos/src/unix.rs:221, roce_proxy.c:1566); flare-model, up to 16 flare-rank-N, flare-execution/flare-cuda and the 20 M-spin flare-roce poller all pile onto that same set. On a small operator cpuset this is worse than the default scheduler. |
| 5 | Minor | Silent outcome: all six call sites let _ = the syscall, the selector aborts on the first unreadable cpu_capacity, and nothing logs or exposes whether narrowing happened. |
| 6 | Minor | Tests cover only the pure selector (eos/src/unix.rs:270-330); no test of the syscall path, no injectable sysfs root (:243), no test of the non-inheritance property the design depends on, zero tests for the C mirror, and CI never runs aarch64 execution. |
| 7 | Minor | helios/src/replay.rs:174 narrows before Stream::open (:114), the opposite ordering to the documented design, and outside what the PR's /proc evidence covers. |
| 8 | Minor | Operator-visible changes undocumented: the flare-roce thread rename and proxy affinity appear in no doc, and docs/prefix-cache-offload.md:927-928 ("Adding CPU affinity requires a serving-latency measurement that shows a benefit") is now violated/stale. |
Verified sound (no finding): no hot-path cost, Windows stub parity, no error-propagation change, no rate/latency/admission metric span shift, no ABI/core-format change, offload SCHED_BATCH/nice policy untouched, and no UB/overflow/out-of-bounds in either selector.
1. Blocker — narrowing precedes the lazy KV-codec pool, which is then built half-sized and pinned
Citation: helios/src/server/runtime.rs:721-729; selene/src/shared/codec.rs:37-59; selene/src/memory.rs:2005-2013; helios/src/offload/transfer/codec.rs:24-25,353,514.
// helios/src/server/runtime.rs:721-729
// Narrow affinity only after RankExecutor, host offload/codec/disk, and image
// preparation child threads have been spawned so background workers stay free
// to run on efficiency cores and observe the full process cpuset.
flare_eos::prefer_high_capacity_cpus();
worker_metrics.scheduler(worker.scheduler.stats());
worker_health.store(true, Ordering::Release);
let _ = ready_tx.send(Ok(()));
let run = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
worker.run(&mut executor)
}));
The comment's claim is false for one pool. cpu_pool() is a OnceLock built on first use, sized from the calling thread's available_parallelism(), and rayon spawns all its workers from that same thread (pthreads inherit sched affinity):
// selene/src/shared/codec.rs:37-53
pub fn cpu_pool() -> Result<&'static rayon::ThreadPool> {
static POOL: std::sync::OnceLock<std::result::Result<rayon::ThreadPool, String>> =
std::sync::OnceLock::new();
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}"))
The first use can happen inside worker.run, on the narrowed thread: worker.run → service_store → selene/src/memory.rs:3064-3066 poll → drain_compressed → pump_spawns (:2005), whose first line is the pool acquisition:
// selene/src/memory.rs:2005-2013
fn pump_spawns(&mut self) {
let Some(scratch) = self.scratch.take() else {
return;
};
let Some(task) = self.queue.pop_front() else {
self.scratch = Some(scratch);
return;
};
let Ok(pool) = host_compress_pool() else {
Impact. On GB10 (0-19 allowed) after narrowing to 5-9,15-19, available_parallelism() returns 10, so the pool is built with 5 instead of 10 threads and all of them inherit Cpus_allowed_list=5-9,15-19 — the codec worker set loses half its parallelism and loses the efficiency cores the comment promises it keeps. This is precisely the outcome the deferral was written to prevent, and the PR's own /proc/<pid>/task/*/status evidence lists flare-model, flare-roce, serve_rank, ImagePreparation, flare-http, tokio-rt-worker and CUDA driver helpers — no flare-kv-codec-* entry — so the one pool that is created after narrowing was never inspected. The PR's Limitations ("host prefix offload … not exercised on multi-host TP4") skip the only workload that instantiates it. helios/src/offload/transfer/codec.rs:24-25,353,514 reaches the same pool from the offload hot path.
Fix. Instantiate/normalise the pool before narrowing (call selene::shared::codec::cpu_pool() during startup, before runtime.rs:724), or have cpu_pool() explicitly restore the process-wide allowed mask on its workers, or pass an explicit thread count. Then re-run the /proc evidence including flare-kv-codec-*.
2. Major — the vendored proxy is edited inside the region four in-tree witnesses call byte-identical
Citation: helios/native/roce_proxy.c:6-8 and :1572-1577; NOTICE:16-19; helios/native/roce_proxy_dlopen.c:7-9; docs/roce-ring.md:361-364; docs/TODO.txt:80-86.
// roce_proxy.c:6-8
// 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.
// roce_proxy.c:1572-1577
static void* proxy_main(void* arg) {
roce_ctx_t* c = (roce_ctx_t*)arg;
#ifdef __linux__
(void)pthread_setname_np(pthread_self(), "flare-roce");
pin_high_capacity_cpus();
#endif
Both the 60-line helper (:1505-1570) and these calls sit below the provenance header, i.e. inside the "identical" region. The witnesses were left unamended (no doc/NOTICE file in the 8-file diff):
NOTICE:16-19
helios/native/roce_proxy.c was contributed by its original author from:
https://github.com/local-inference-lab/flashinfer/blob/f5f5341d.../_roce_proxy.c
The proxy is compiled into Linux aarch64 builds. Its implementation is unchanged
from that revision; Flare adds a license and provenance preamble.
roce_proxy_dlopen.c:7-9
// Loads libibverbs.so.1 lazily with dlopen ... while
// keeping the vendored roce_proxy.c byte-for-byte identical to FlashInfer.
docs/roce-ring.md:361-364 repeats the instruction ("keep the vendored source identical to the dependency after its provenance header"), and docs/TODO.txt:80-86 still describes the parity debt in terms of ABI 10/11 while roce_proxy.c:134 declares ABI 14.
Impact. An attribution/parity contract asserted in four files is now untrue, and nothing detects it: no CI job diffs the vendored file and there is no re-vendor script. The PR body says the hunk was vendored from flashinfer#156, but not that the pinned revision in NOTICE (which predates that merge) and the three in-tree witnesses were left stale.
Fix. Either take the hunk through the roce_proxy_dlopen.c wrapper (the seam that keeps the vendored body untouched), or amend NOTICE to the new pin (335459b2, flashinfer#156) and update roce_proxy_dlopen.c:7-9, docs/roce-ring.md:361-364 and docs/TODO.txt:80-86 in the same PR.
3. Major — the 90 % filter has no relative-spread guard; "x86_64 is a no-op" is not reliable
Citation: eos/src/unix.rs:201-208 and :221-225.
if min_cap == max_cap {
return None;
}
// Performance cores on asymmetric SoCs can differ by a few percent across
// clusters (for example, ACPI CPPC capacities 997..1024 vs efficiency 718..731).
let mut selected: Vec<usize> = allowed_with_capacity
.iter()
.filter(|&&(_, cap)| u64::from(cap) * 10 >= u64::from(max_cap) * 9)
.map(|&(cpu, _)| cpu)
.collect();
if selected.len() >= 2 && selected.len() < allowed_with_capacity.len() {
Some(selected)
} else {
None
}
The homogeneity test is exact equality only. /sys/devices/system/cpu/cpu<N>/cpu_capacity exists wherever arch_topology/CPPC advertises it — including x86 hybrid parts (Alder/Raptor/Meteor Lake) and many server kernels — so the PR's Limitation ("On x86_64 Linux … cpu_capacity is absent so the helper is a no-op") does not hold in general. Two consequences:
- On an x86 hybrid workstation this PR silently pins
flare-model, the rank threads and the RoCE proxy on merge, with no benchmark for that hardware, no flag and no log — contrary todocs/prefix-cache-offload.md:927-928("Adding CPU affinity requires a serving-latency measurement that shows a benefit") and the charter's evidence/opt-in rule (#210). - Even on symmetric-capacity machines, a 1–2 % spread (the PR's own GB10 data spans 997..1024, a 2.7 % spread within one tier; CPPC rounding routinely yields 1023/1024) satisfies
min_cap != max_capand produces a 1–2 CPU "high" set out of 16+, which then passesselected.len() >= 2 && selected.len() < lenand is applied. Nothing in the selector can distinguish "genuinely tiered" from "noisy homogeneous".
Fix. Require a minimum relative spread before acting (e.g. max_cap >= min_cap * 12 / 10, the ~40 % gap real big.LITTLE parts show) and/or gate the whole feature behind an explicit env/flag, as the docs demand.
4. Major — the ≥2-CPU floor is not related to how many threads get pinned, and the busy-polling proxy shares the set
Citation: eos/src/unix.rs:211-225; C mirror helios/native/roce_proxy.c:1543-1568; spin loop :1586-1599; rank call sites helios/src/execution/threaded.rs:683, worker.rs:86, parallel.rs:573, server/runtime.rs:724, replay.rs:174.
if selected.len() < 2 {
// Avoid collapsing multiple busy threads onto a single prime core on
// three-tier topologies: fall back to all cores above the capacity midpoint.
let sum = u64::from(min_cap) + u64::from(max_cap);
selected = allowed_with_capacity
.iter()
.filter(|&&(_, cap)| u64::from(cap) * 2 > sum)
.map(|&(cpu, _)| cpu)
.collect();
}
if selected.len() >= 2 && selected.len() < allowed_with_capacity.len() {
C behaves identically (roce_proxy.c:1555-1568: if (selected >= 2 && selected < count)), and the proxy then spins:
// roce_proxy.c:1586-1599
while (atomic_load_explicit(&c->running, memory_order_relaxed)) {
uint32_t seq = __atomic_load_n(&ctrl[CTRL_SEQ], __ATOMIC_ACQUIRE);
...
if (seq == c->last_seq) {
idle++;
if (idle % 64 == 0) {
if (drain_all(c) != 0) {
(ROCE_IDLE_SPINS 20000000 at :172 before a 20 µs nap.)
Impact. Every narrowing caller is latency-critical and lands on the same set: flare-model (rank 0), one flare-rank-{i} per TP rank (up to 16), flare-execution, flare-cuda, and the 100 %-duty flare-roce poller. On GB10 the high set is 10 CPUs, so this is fine; but on an operator cpuset such as taskset -c 0-3 on a 1-prime + 3-efficiency asymmetric part, the fallback can return 2 CPUs and 8+ hot threads — including a full-duty spinner — are then forced onto them. That is strictly worse than letting the scheduler spread them, and it can recreate the host-wake-gap latency this PR is measuring, this time by oversubscription instead of by core tier. Nothing compares selected.len() to the number of threads that will be pinned, and nothing logs.
Fix. Require the selected set to be at least the number of threads that will be pinned (or a named minimum such as 4) and no-op otherwise; consider excluding one CPU for the proxy, or leaving the poller unpinned.
5. Minor — the outcome is entirely silent: no log, no flag, no metric
Citation: eos/src/unix.rs:244-249 and :260; helios/native/roce_proxy.c:1527-1536 and :1567.
if unsafe { libc::CPU_ISSET(cpu, &allowed) } {
let path = format!("/sys/devices/system/cpu/cpu{cpu}/cpu_capacity");
let Ok(text) = std::fs::read_to_string(&path) else {
return;
};
let Ok(cap) = text.trim().parse::<u32>() else {
return;
};
let _ = unsafe { libc::sched_setaffinity(0, std::mem::size_of::<libc::cpu_set_t>(), &next) };
A single unreadable or unparsable cpu_capacity file silently disables the feature for the whole thread; a sched_setaffinity failure (bad mask, restricted cgroup) is discarded at all six call sites, and the C side does the same ((void)sched_setaffinity at :1567, early return on fopen/fscanf failure at :1528-1536). Because the change is unconditional and default-on, an operator has no way to tell whether narrowing happened, which set was chosen, or why it did nothing — and the PR's own evidence gathering required reading /proc/<pid>/task/*/status by hand.
Fix. Log once per thread (debug/info) the chosen CPU set or the reason for no-op, and expose it (e.g. a startup log line or metric alongside worker_metrics.scheduler).
6. Minor — tests do not reach the code the design depends on, and CI cannot run either implementation
Citation: eos/src/unix.rs:266-330; sysfs path hard-coded at :243; C helper helios/native/roce_proxy.c:1510-1569.
#[test]
fn select_high_capacity_cpus_splits_asymmetric_tiers() {
let mut gb10 = Vec::new();
for cpu in 0..5 {
gb10.push((cpu, 718));
}
Only the pure selector is tested (three cases: tier split, homogeneous/single-tier, three-tier midpoint fallback). prefer_high_capacity_cpus (:232-261) has no test and no injection point — the sysfs root is a literal in the format string (:243) — and nothing asserts that a child thread spawned after narrowing sees a wider mask than its parent, which is the property the whole deferral argument rests on. The C mirror is untested, and the aarch64 CI leg only builds and runs --version/--help; the x86_64 legs never exercise the sysfs path. The claimed wins were measured on binary 4c82ab5b, not this head.
Fix. Take a path root parameter (cfg(test) or env override) and add a test over a temp sysfs tree plus a parent/child mask test; add at least one C-side self-check or an integration test that runs on an aarch64 runner.
7. Minor — flare-cuda narrows before Stream::open, opposite to the documented ordering
Citation: helios/src/replay.rs:171-176 versus :113-123.
let thread = thread::Builder::new()
.name("flare-cuda".into())
.spawn(move || {
flare_eos::prefer_high_capacity_cpus();
run(receiver, completion_sender, ready_sender)
})
move |receiver, sender, ready| {
let stream = match Stream::open(bundle.context, bundle.device) {
run's closure body opens the stream first, so the flare-cuda thread is narrowed before Stream::open. In the flare-model path the opposite ordering is deliberate: RankExecutor::new at runtime.rs:585 precedes the narrowing at :724, and the PR's /proc evidence ("CUDA driver helper threads retained 0-19") was taken there — it cannot cover this path. Impact is bounded (Stream::open takes a pre-existing bundle.context, :114, so per-stream driver threads, if any, would inherit the narrowed mask). Not a proven defect, but an unmeasured asymmetry against the PR's stated rule.
Fix. Move the call into run after Stream::open succeeds (replay.rs:123), matching runtime.rs.
8. Minor — operator-visible changes undocumented; a normative doc rule is now stale
Citation: docs/prefix-cache-offload.md:919-928; helios/native/roce_proxy.c:1575.
- CPU: transfer threads sleep on event waits and channel receives; the disk
thread submits I/O and hashes multi-page raw batches across the scoped
helpers of section 2.5. On Linux, offload threads use `SCHED_BATCH` with a
positive nice value, ... Adding CPU affinity requires a
serving-latency measurement that shows a benefit.
No doc file appears in the 8-file diff. (a) The rule above is now violated for the offload-adjacent RoCE proxy, which this PR pins with no measurement for that path — either supply the measurement or scope the rule. (b) pthread_setname_np(pthread_self(), "flare-roce") (roce_proxy.c:1575) changes the proxy thread's comm from the process/exe name to flare-roce; anything identifying proxy threads by comm (top/htop, pgrep flare, systemd accounting, the Orbit monitor) sees a different name. The rename is also the instrument the placement evidence depends on, so it must be documented rather than existing only in the diff. Verified untouched by this PR: SCHED_BATCH/nice behaviour (helios/src/offload/transfer.rs:281, called at :531) and selene's disk-thread policy, so the "offload threads lower priority" contract still holds for threads that keep the full mask.
Claim accuracy (Tests & Claim Accuracy area)
Verified against the diff (5 items):
- Body: "no-op when
cpu_capacityis absent, homogeneous, or already single-tier" + Limitations "On x86_64 Linux … absent so the helper is a no-op" — not reliable; see finding 3 (eos/src/unix.rs:201-203). - Body: "Defer … until after child-thread spawning so background threads retain the unnarrowed process affinity mask" — true for the eagerly spawned threads (
runtime.rs:585,:684-707,:719all precede:724), false for the lazyflare-kv-codec-*pool (finding 1). - Body's
/procevidence names the threads it inspected but omitsflare-kv-codec-*— the one pool created after narrowing — and was measured on4c82ab5b, not this head. - Body: "falling back above midpoint to never collapse below 2 cores" — accurate, but "never below 2" is the only floor and has no relation to the number of pinned threads (finding 4).
- Body presents the
flare-rocerename as the measurement instrument without stating that it is a user-visiblecommchange (finding 8).
Areas verified sound (stated plainly, no finding)
- No hot-path cost.
prefer_high_capacity_cpusruns once per thread at start (6 sites);pin_high_capacity_cpusruns once per proxy thread (roce_proxy.c:1576). No new locks, channels, buffers or allocations; the steady-state spin loop (:1578-1650) andWorker::runpoll path are untouched. - Ordering/synchronisation. Each narrowing call is strictly after the executor it affects is constructed (
runtime.rs:585vs:724;worker.rs:75-86;parallel.rs:563-573;threaded.rs:672-683).catch_unwindstill encloses only the loops, so narrowing cannot panic on the unwind path; allunsafecalls are plain libc with ignored return values, so no new failure path is introduced. - Windows parity.
eos/src/windows.rs:219-220adds a total no-op stub matchingraise_open_file_limit(:215), and the C helper is#ifdef __linux__-gated (roce_proxy.c:1506/1570), so builds and behaviour elsewhere are unchanged. - Metric / rate / admission span check. This PR changes no rate, latency or admission metric or its sampling scope;
worker_metrics.scheduler(...)and Engram metrics are untouched, and scheduler cost calibration consumes graph descriptors, not timings. The claimed win is reduced variance of timings the scheduler already observes — no measured span shrank. - Contracts/ABI. No wire/proto/core-format/ABI change;
ROCE_ABI_VERSION 14(roce_proxy.c:134) is unchanged, so existing ABI-14 cores still load. - No UB or arithmetic hazards in either selector:
CPU_SET/CPU_ISSETindices derive from the same0..size_of::<cpu_set_t>()*8loop (eos/src/unix.rs:239-242), C arrays are bounded byCPU_SETSIZEincrements (roce_proxy.c:1516-1541), and both sides widen tou64before multiplying (unix.rs:208,214;roce_proxy.c:1550,1558), withval > UINT32_MAXrejected at:1534. - No instruction-like or injected content was found in the PR body, comments or reviews; all of it was treated as material under review.
Open questions / not found
- Whether the author will build or normalise the
flare-kv-codec-*pool before narrowing (finding 1), or re-pinNOTICE/docs/TODO.txt/docs/roce-ring.md/roce_proxy_dlopen.cto flashinfer#156 (finding 2). No maintainer comment follows the author's 2026-11-30 00:39 reply. - Whether the merged #589 wrapper (
roce_proxy_dlopen.c) is the intended home for the pin/rename instead of the vendored body: it is the exact seam that keeps the vendored file untouched, and this PR still edits the file the wrapper#includes. - Rebase order against open #625 (rewrites the same region of
eos/src/unix.rs:map_host→map_host_with+MappingGuard, ~440 test lines) and draft #628 (CopyEngineGatearound the same offload codec sites this PR keys off). Overlap is certain; textual conflict was not asserted here (not merged or rebased). - Whether
Stream::open(replay.rs:114) creates any per-stream CUDA driver threads that would now inherit the narrowed mask — no evidence either way in this PR. - Whether the
2e5bdesign-review digest matches the currentdocs/design-review.md(not opened) (not recomputed).