Correctness and contracts scratchpad · NVIDIA/hyperflare-inference #640

Raw Markdown for agents: https://autobot.eidonix.com/p/5e0fc004-1d4a-4307-b17b-196dabc3955b.md

#1 [high] Findings index for PR #640 correctness/contracts lens

All verified against head b7a6204 by reading files (no guessing).

F1 (Major) SM-partition asymmetry: cooperative grids clamped on rank 0 only. F2 (Major) "initialize" claim unverified / no executor-level success test. F3 (Major) stale contract doc helios/manifest.md:89-95. F4 (Minor) same_layout degraded to a directional predicate; loses worker field comparison. F5 (Minor) rank-0 worker never signalled when peer drain fails (newly reachable abandon path). F6 (Minor) error-message/contract wording drift across four sites. Sound areas: selection rank indexing vs cluster selection; metrics reader span; parallel.rs/helio­pause unchanged; no new deps/flags/wire changes; no locks or hot-path allocations added.

#2 [high] F1 SM partition asymmetry on rank 0 clamps cooperative grids

helios/src/runtime_core/mod.rs:374-402 — primary context + green partition path is taken only when wants_worker.is_some() (i.e. only rank 0 after this PR); peers use cuCtxCreate_v2. mod.rs:763-780 — GreenContextPartition::create(... worker.worker_sm_count) per rank, gated on self.primary_context and execution.persistent_workers.first(). mod.rs:888-911 — partition_sms = Some(compute_sm_count) only when self.green_partition is Some; peers get partition_sms = None, upload_stream = null. mod.rs:1002-1016 quote:

if attribute.id == 2
    && value[0] as u32 != 0
    && (status == 720 || (status == 0 && partition_sms.is_some()))
{
    self.clamp_cooperative_launch(&mut params, partition_sms)?;

=> on rank 0 a cooperative kernel whose attribute restores cleanly (status == 0) is still clamped because partition_sms.is_some(); on peers status == 0 and partition_sms is None so nothing is clamped. mod.rs:135-146 clamp_cooperative_grid reduces the largest grid axis to fit blocks_per_sm * sms. docs/runtime-core-design.md:906-915 requires cooperative grids to tolerate the reduction, but says nothing about cross-rank symmetry. docs/same-process-tp.md:30-34 "Preparation must validate that each collective's worker grid can remain resident on every participating GPU"; same-process-tp.md:177-180 "Not qualified: four ranks, graphs that contain b12x spin-barrier collectives". selection.rs:416-424 requires identical selected graph catalogs across ranks, so captured grid dims are identical everywhere; same_layout (threaded.rs:1273-1332) compares no node grid dimensions and no SM capacity, so it cannot detect the mismatch. Impact: rank 0 participates in a TP collective / barrier with fewer resident CTAs than its peers, and rank 0's compute partition is 8 SMs smaller than peers (imbalanced decode step time bounded by rank 0). The PR body lists live multi-GPU execution with a worker as not executed. Fix: either reject rank-0 workers when the created compute partition is smaller than the device SM count used by peers (or when any serving graph uses cooperative launch / cluster launch), or validate the barrier protocol against asymmetric resident-CTA counts and record it in docs/runtime-core-design.md; add a two-GPU test that runs a cooperative/barrier graph with a rank-0 worker.

#3 [high] F2 initialize claim has no test in threaded path

helios/src/execution/threaded.rs:632-636 only rejects peer manifests; rank 0's worker is accepted at construction. But nothing exercises a successful construction with a worker.

// Multi-rank execution rejects persistent workers explicitly.
assert!(unsafe { threaded::ThreadedExecutor::new(value.clone(), vec![value.clone()]) }.is_err());
assert!(unsafe { threaded::ThreadedExecutor::new(manifest(), vec![value.clone()]) }.is_err());

(these two remain correct under the new rule, so the comment is stale but the assertions hold)

if let Some(worker) = self.manifest.persistent_workers.first() {
    let control = worker.control.as_ref().ok_or_else(|| Error::execution(
        ExecutionError::Manifest,
        "persistent worker requires green-context runtime control (export a core and serve with flare run)",
    ))?;
    control.start()?;
}

control is only produced by the native path (runtime_core/serving.rs:181 control: self.persistent_worker_control()), so a CPU/manifest-only test cannot reach it. The GPU test that does (helios/src/runtime_core/persistent_worker.rs:1095 cuda_... test and :2029) is single-rank and #[ignore]d.

#4 [high] F3 stale manifest contract doc

helios/manifest.md:87-95 still describes the old rule and is the execution-manifest contract AGENTS.md:227 points Helios changes at:

An execution catalog may optionally declare `Execution.persistent_workers`
(repeated Protobuf message `PersistentWorker`, field 8) to run a dedicated
graph concurrently with serving graphs on a spatially partitioned CUDA Green
Context. Helios currently supports at most one persistent worker entry on
single-rank cores; cores declaring more than one entry, multi-rank cores, and
multi-host cluster cores declaring a persistent worker fail validation before
execution.

After this PR a local multi-rank core with a rank-0 worker loads and serves, so "multi-rank cores ... fail validation" is false. Only docs/runtime-core-design.md:642-644 was updated; the PR description's changed-file list does not mention helios/manifest.md. Impact: an exporter/recipe author reading the manifest contract will believe the topology is rejected and keep the worker off local TP cores, i.e. the capability this PR adds stays undiscoverable; also a reviewer/doc test mismatch. Fix: update manifest.md:92-95 to "at most one entry on rank 0 of a local core; peer ranks and multi-host cluster cores declaring a persistent worker fail validation", matching runtime-core-design.md:642-644.

#8 [high] F7 areas verified sound

Verified as sound in this PR (state plainly in report, do not invent issues):

#9 [high] Research summary

Reviewed PR #640 (correctness / contracts / system-level lens) by reading every changed file, its callers, contracts and tests at head b7a6204. Findings are in the scratchpad (entries 1–8); summary below.

Blockers: none. The relaxation itself is correct and narrow: validate_persistent_worker_topology (model.rs:114-134), LoadOptions::select (selection.rs:285-289) and ThreadedExecutor::new (threaded.rs:632-636) now admit exactly a local core whose rank 0 carries one worker, and peer/cluster cases still fail. Rank indexing is right (rank > 0 runs after cluster selection narrows cores to the served rank at model.rs:345-350), no wire/proto/ABI change, no new locks, allocations or I/O on hot paths, and the metrics//v1/worker/dashboard reader still sees the single worker because rank 0's manifest is the only one that can carry it.

Major — SM-partition asymmetry is now reachable (F1, helios/src/runtime_core/mod.rs:374-402, :888-911, :1002-1016). Only the worker-bearing rank takes the primary-context/green-context path; peers use cuCtxCreate_v2 with partition_sms = None. So on rank 0 a cooperative kernel whose launch attribute restores with status 0 is still clamped (partition_sms.is_some()), and rank 0's compute partition is worker_sm_count smaller, while selection.rs:416-424 forces identical selected graph catalogs on every rank and same_layout compares neither node grids nor SM capacity. A same-host TP core with a rank-0 worker therefore runs TP collectives/barriers with fewer resident CTAs on rank 0 and an imbalanced decode step — exactly the "not qualified" case in docs/same-process-tp.md:30-34 and :177-180. The PR body itself lists live multi-GPU execution with a worker as not executed.

Major — the "initialize" claim has no test (F2). Only same_layout is exercised by the new test (threaded.rs:1631-1651); execution/tests.rs:1371-1373 still asserts only rejections, and there is no successful ThreadedExecutor::new + close with a worker. Initialization goes through transport.rs:797-805, which needs worker.control, produced only by the native path (runtime_core/serving.rs:181) and covered only by #[ignore]d single-rank GPU tests. Nothing verifies the worker starts once after peers report Started, or that close drains peers and the worker together.

**Major — stale contract doc (F3, helios/manifest.md:92-95).** Still says "multi-rank cores … fail validation before execution", which this PR makes false; only docs/runtime-core-design.md:642-644was updated, and the PR description omitshelios/manifest.md`. AGENTS.md:227 points Helios changes at that file, so the new capability stays undiscoverable to core authors.

Minor: same_layout became a directional, self-false predicate with the worker field comparison deleted and the asymmetry enshrined in the test (threaded.rs:1292-1294, :1648-1650) — F4; the newly reachable abandon path forgets rank 0's resources without ever writing the stop flag (threaded.rs:1004-1013 → transport.rs:980-990) — F5; three different error strings for one rule plus an implicit ordering dependency where select alone cannot reject a clustered rank-0 worker (F6).

Sound and stated plainly: nothing added to shared hot paths, socket TP and the Python loader still reject workers in line with the stated scope, and the PR's before/after text matches the diff apart from the word "initialize" and the omitted manifest doc.

#10 [high] F1 supporting quotes and severity summary

Additional verbatim quotes for F1 (the green-context gate that makes the partition rank-0-only), to be quoted directly in the report:

helios/src/runtime_core/mod.rs:369-380

let wants_worker = core
    .execution
    .as_ref()
    .and_then(|execution| execution.persistent_workers.first());
let mut context = null_mut();
let primary_context = if wants_worker.is_some() {
    if driver.green_ctx.is_none() {
        return Err(invalid(
            "persistent worker requires CUDA driver Green Context APIs",
        ));
    }

and the else branch at :396-401 (cuCtxCreate_v2, primary_context = false).

helios/src/runtime_core/mod.rs:763-774

if self.primary_context {
    apply_context_settings(&driver, self.context, &core.context)?;
    if let Some(worker) = core
        .execution
        .as_ref()
        .and_then(|execution| execution.persistent_workers.first())
    {
        let partition = persistent_worker::GreenContextPartition::create(
            &driver,
            self.device,
            worker.worker_sm_count,
        )?;

So green_partition (and therefore partition_sms = Some(compute_sm_count) at :895-908) exists only on the rank that declares the worker. Peers fall to (self.context, null_mut(), None) at :909-911.

Severity summary for the report:

#5 [medium] F4 same_layout asymmetry

helios/src/execution/threaded.rs:1292-1294 replaced a field-wise comparison with a one-way predicate:

if !b.persistent_workers.is_empty() {
    return false;
}

Before: compared len + worker_sm_count/graph/metrics_count for every entry. Now:

#6 [medium] F5 abandon skips worker stop for rank 0

Newly reachable path: with a rank-0 worker, ThreadedExecutor::close can fail while peer drain or the local drain fails, taking self.local.abandon(error) (helios/src/execution/threaded.rs:1004-1013):

if result.is_err() {
    best_effort_drain_peers(&self.ring, &mut self.peers, self.started, TIMEOUT);
}
let shutdown = match result {
    Ok(()) => self.local.close(),
    Err(error) => self.local.abandon(error),
};

GraphExecutor::abandon (helios/src/execution/transport.rs:980-990) takes resources and std::mem::forgets them without signalling the worker stop flag:

if let Some(resources) = self.resources.take() {
    std::mem::forget(resources);
}

Whereas GraphExecutor::close (transport.rs:1371-1378) stops the worker and counts it into drained. Peer threads do the same on their error path (threaded.rs:685-691 -> executor.abandon(error)), but peers never have a worker. Impact: when a peer's close/drain fails, rank 0's persistent worker keeps running on its green context and the process retains driver/GPU resources until exit — the documented "retain on failed drain" invariant covers it, so this is acceptable but it means the worker is never asked to stop on that path (no 1u32 release to stop_flag), i.e. a leaked worker spin that also keeps the SM partition busy. Bounded blast radius (process is expected to exit), so Minor; worth a one-line note in the teardown comment or a worker.control.as_ref().map(|c| c.stop()) attempt before forgetting. File:line: helios/src/execution/threaded.rs:1004-1013, helios/src/execution/transport.rs:980-990.

#7 [low] F6 message drift and implicit validation ordering

Error wording/contracts now differ across sites after this PR; each string is user-visible and tests assert on substrings: