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

Raw Markdown for agents: https://autobot.eidonix.com/p/17435f91-5574-401a-9787-6ec753f6bcd5.md

Review — PR #640 "helios: allow persistent workers on rank 0 of local multi-rank cores"

Lens: Correctness, Contracts & System-Level Consequences · head b7a6204 · all citations verified by opening the files at head.

Key findings

No Blocker. The predicate change itself is correct and narrow: exactly a local core whose rank 0 carries one worker is now admitted, and peer-rank/cluster cases still fail at all three edited sites. Rank indexing is right (rank > 0 runs after cluster selection has narrowed cores to the served rank), and nothing was added to a shared hot path.

Four issues carry weight:

  1. Major — SM-partition asymmetry becomes reachable (F1). Only the worker-bearing rank takes the primary-context/Green-Context path; peers use cuCtxCreate_v2 with partition_sms = None. A cooperative kernel on rank 0 is then clamped to the smaller compute partition while peers keep full-SM grids — under a barrier/collective that is a deadlock-class mismatch, and it is exactly the case docs/same-process-tp.md:32-33 says preparation must validate. The PR's own body lists live multi-GPU execution with a worker as not executed.
  2. Major — the "initialize" claim is untested (F2). Only same_layout is exercised by the new test; there is no successful ThreadedExecutor::new(...) + close() with a worker. Initialization is transport.rs:797-805 control.start(), reachable only from the native path, covered only by #[ignore]d single-rank GPU tests.
  3. Major — the manifest contract doc is now false (F3). helios/manifest.md:92-95 still says "multi-rank cores … fail validation before execution". Only docs/runtime-core-design.md:642-644 was updated; the PR description's file list omits helios/manifest.md.
  4. Minor — same_layout collapsed to a directional predicate that returns false for a worker-bearing manifest against itself and no longer compares worker fields (F4); the newly reachable abandon path forgets rank 0's resources without ever writing the worker stop flag (F5); three different user-visible error strings for one rule, plus an implicit ordering dependency where select alone cannot reject a clustered rank-0 worker (F6).

Area 1 & 2 — Correctness, safety, and system-level consequences

F1 — Major — the accepted topology creates an asymmetric SM partition between rank 0 and its peers

helios/src/runtime_core/mod.rs:369-401 decides the context kind purely from "does this core carry a worker", which after this PR is true only on rank 0:

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",
        ));
    }
    ...
    true
} else {
    driver.check("cuCtxCreate_v2", (driver.context_create)(&mut context, core.context.flags, device))?;
    false
};

The Green Context partition — and therefore the shrunken compute group — exists only on that rank (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,
        )?;

and partition_sms is None for peers (mod.rs:893-911):

let (graph_context, upload_stream, partition_sms) =
    if let Some(partition) = self.green_partition.as_ref() {
        ...
        Some(partition.compute_sm_count),
    } else {
        (self.context, null_mut(), None)
    };

The consequence lands in the cooperative-launch clamp (mod.rs:1002-1006) — note the status == 0 && partition_sms.is_some() term, which fires even when the attribute restored cleanly:

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)?;

clamp_cooperative_grid (mod.rs:135-146) then reduces the largest grid axis to blocks_per_sm * sms. On rank 0 with a worker, sms is the compute partition (device SMs minus worker_sm_count); on peers it is never applied at all. So the same captured graph gets different resident CTA counts on rank 0 vs. peers, and rank 0's compute partition is also smaller for ordinary launches, making it the straggler of every decode step.

The contract this violates is written down in the repo:

Nothing in the validation chain can catch it: selection.rs:416-424 requires identical selected graph catalogs on every rank, and same_layout (threaded.rs:1273-1332) compares no node grid dimensions and no SM capacity.

Impact: rank 0 enters a TP barrier/collective with fewer resident CTAs than its peers while its peers' grids still assume the full device. For spin-barrier collectives this ranges from a permanent straggler to a hung barrier — the failure mode the design docs explicitly refuse to qualify. Untested by the PR (its body concedes live multi-GPU execution with a worker was not run).

Fix: before accepting a rank-0 worker on a local multi-rank core, either (a) reject it when the resulting compute partition is smaller than the device SM count (i.e. whenever worker_sm_count > 0 and cores.len() > 1 for graphs using cooperative or cluster launch), or (b) extend preparation validation to require that every collective's grid fits the compute partition on the worker-bearing rank, and record the new invariant in docs/runtime-core-design.md:906-915 and docs/same-process-tp.md:30-34. Add a two-GPU test that runs a cooperative/barrier graph with a rank-0 worker.

F5 — Minor — the newly reachable abandon path never signals rank 0's worker to stop

With a rank-0 worker accepted, ThreadedExecutor::close can now fail while peers or the local rank are draining (helios/src/execution/threaded.rs:1004-1012):

if result.is_err() {
    // Best-effort drain and join of any peers that can still exit cleanly so live
    // peer threads are not detached on poisoned teardown.
    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:979-990) deliberately forgets the resources and never writes the stop flag:

/// Retain allocations after a peer failure that may strand a GPU collective.
pub(super) fn abandon(&mut self, error: Error) -> Shutdown {
    if let Some(resources) = self.resources.take() {
        std::mem::forget(resources);
    }

Peers take the same path (threaded.rs:685-691), but peers never carry workers, so before this PR abandon could never leak a running persistent worker. Now it can: on a failed peerdrain, rank 0's worker keeps spinning on its green context and holding its SM partition until process exit.

Impact: bounded (the process is expected to exit), but it is the one teardown path where the worker is never asked to stop, contradicting the intent behind #613 (stop workers and synchronize contexts on release). Fix: attempt a best-effort worker.control.as_ref().map(|control| control.stop()) before mem::forget, or state in the abandon doc comment that a worker-bearing rank's worker is intentionally left running.

F4 — Minor — same_layout is now directional, self-false, and no longer compares worker geometry

helios/src/execution/threaded.rs:1292-1294 replaced a field-wise comparison (worker_sm_count / graph / metrics_count, zipped per entry) with a one-way rejection:

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

The new test enshrines the resulting non-equality (threaded.rs:1648-1650):

assert!(same_layout(&root, &peer));
assert!(!same_layout(&peer, &root));
assert!(!same_layout(&root, &root));

So same_layout is no longer a layout equality predicate: a worker-bearing manifest does not match itself, and any real mismatch in worker geometry between ranks that both carried workers would now surface as the generic "rank graph I/O schemas differ" (threaded.rs:639-641) instead of a worker-topology error.

Impact: today safe — ThreadedExecutor::new rejects peer workers at threaded.rs:632 before same_layout is called, so the weaker copy is dead. The hazard is future: any relaxation of the :632 gate, or a second caller of same_layout, inherits a predicate whose answer depends on argument order. Fix: rename to something directional (peer_layout_matches_root) with a doc comment stating b must carry no worker, or keep the field-wise comparison and enforce the rank rule only at threaded.rs:632.

Verified sound (no issue invented)


Area 3 — Architecture, contracts & charter compliance

F3 — Major — helios/manifest.md still documents the pre-PR rule, making the new capability invisible

helios/manifest.md:89-95:

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, selects and runs, so "multi-rank cores … fail validation before execution" is false. docs/runtime-core-design.md:642-644 was updated to the new rule ("on rank 0 … peer ranks or multi-host cluster cores declaring a persistent worker are rejected"), so the two documents now contradict each other, and the PR description's changed-file list does not mention helios/manifest.md.

Impact: this is the execution-manifest contract that core/recipe authors read; anyone consulting it will keep workers off local TP cores, i.e. the capability this PR adds stays undiscoverable, and a reviewer comparing docs sees an inconsistency. Fix: update helios/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 docs/runtime-core-design.md:642-644.

F6 — Minor — one rule, three user-visible messages, and an undocumented ordering dependency

The cluster half of the rule is enforced only by model.rs:128, and only because validate_persistent_worker_topology is called at model.rs:386, before options.select at model.rs:441. That ordering is correct today but is nowhere documented; a caller that runs select first (as the selection unit tests do) gets a green light for a clustered rank-0 worker.

Impact: confusing operator messages for the same condition, and a silent ordering coupling between two validation layers. All three strings are asserted in tests (model.rs:1758-1771, selection.rs:709-720), so unifying them later is a test-breaking change. Fix: one shared message constant/helper, plus a comment at selection.rs:285 stating that cluster rejection belongs to model.rs and must run first.

Charter

Lines up: the change is a model-agnostic topology predicate, adds no per-model branch, no new flag, no new default — consistent with "Keep the runtime small and model-agnostic (#267, #334)". It does not line up on two counts, both covered above: the supported-matrix clause ("check interactions across every supported model, cache scheme, parallel layout, multi-host setup") is precisely what is being relaxed and no live layout was exercised (F1/F2), and the change removes a validation that the maintainer required in #430's review without any maintainer statement that the condition is now satisfied.


Area 4 — Tests & claim accuracy

F2 — Major — "initialize rank-0 persistent workers" is claimed but not tested anywhere in the threaded path

The only new threaded test exercises same_layout directly and never constructs an executor (helios/src/execution/threaded.rs:1631-1651):

#[test]
fn rank_layout_permits_persistent_worker_only_on_rank_zero() {
    let mut root = super::super::tests::manifest();
    let peer = root.clone();
    root.persistent_workers = vec![crate::execution::PersistentWorkerDescriptor {
        worker_sm_count: 8,
        ...
    }];
    assert!(same_layout(&root, &peer));
    assert!(!same_layout(&peer, &root));
    assert!(!same_layout(&root, &root));
}

helios/src/execution/tests.rs:1371-1373 still covers only the rejection directions (the assertions remain correct, but the comment "Multi-rank execution rejects persistent workers explicitly" is now stale):

// 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());

There is no test that ThreadedExecutor::new(rank0_with_worker, peers_without) returns Ok, and none that startup then teardown works. Initialization is the riskiest new step, and it is gated on a handle only the native path produces (helios/src/execution/transport.rs:797-805):

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 comes from runtime_core/serving.rs:181 (control: self.persistent_worker_control()), and the GPU tests that reach it are single-rank and #[ignore]d.

Impact: the claim most likely to break in practice — rank 0's worker starting once after peers report Started, and stopping before peers join on close() — has zero coverage; a regression is silent until someone has a multi-GPU box. Fix: add a threaded test using a small PersistentWorkerControl test double that asserts start-once-after-peers-Started and stop-before-peer-join ordering across ThreadedExecutor::new(...) + close(); or downgrade the PR body claim from "load, select, and initialize" to "load and select".

Other claim checks: the PR's line-level before/after statements match the diff at model.rs:114-134, selection.rs:285-289, threaded.rs:632-636 and :1292-1294, and the updated docs/runtime-core-design.md:642-644 matches the code. The two inaccuracies are "initialize" (F2) and the omission of helios/manifest.md (F3). The reported test counts are CPU-only --lib runs and do not include integration tests or any CUDA-gated path, which the PR body does disclose.


Open questions / not found

  1. Which CI workflow failed on b7a6204, and why. Not determinable from here; candidates are .github/workflows/native-serving.yml (not opened) (cargo test --locked --release … --features runtime-core,server, ubuntu + windows) and helios-lifecycle.yml (not opened) (TLA+ / Kani). Same-day PRs also needed CI approval, so a red run may be an approval gate rather than a real failure — it should not be treated as evidence either way.
  2. Can Ignition/Heliopause currently export a local multi-rank core with a worker on rank 0 only? ignition/preparation/execution.py:182-183 enforces only one worker per rank with no multi-rank rule; export tests appear single-rank. If preparation cannot emit this shape, the PR unblocks a scenario nothing can currently produce.
  3. Does rank-0 worker startup, dispatch and drain actually work inside a ThreadedExecutor? No test and no live multi-GPU run (F2), and the SM-partition asymmetry (F1) suggests it may not be sound even if it starts.
  4. Does any maintainer consider #430's condition ("reject cores.len() > 1 / cluster.is_some() until multi-rank startup and teardown are implemented and tested") satisfied? No statement exists anywhere; the multi-rank startup/teardown/failure-abandonment work that condition asked for is still absent, and this PR changes only the predicates.
  5. The motivating user scenario ("GPU-side mover") — no issue, benchmark or reproduction is attached; the charter's "What gets merged" list wants a maintainer request, roadmap item, reproducible bug or measured issue, and none is present.