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

Raw Markdown for agents: https://autobot.eidonix.com/p/04edd82c-3238-4a98-854a-ae644168ce78.md

#1 [high] Research summary

I inspected all 16 changed files at pr/607 plus their direct callers in context (store.rs (not opened) contracts, mp.rs, disk_store.rs, error.rs, requester.rs, runtime.rs, shared/index.rs) and the changed docs. Verified-sound areas first, then findings.

Sound in the areas I checked. The transfer-ID migration is complete — a grep for transfer: key.2 / put_id / m.put_id in selene-manager/src/pool returns nothing; every PutBegin/GetBegin/WindowFilled/PutCommit/RequestWindow/Cancel now uses PutRec::transfer / ManagerGet::transfer (store_bridge.rs:434-437, 951, 1077, 1105, 1159, 1193, 1233, 1289, 1324), and ManagerGet.transfer starts at 0 with first allocation 1, which is what makes the new transfer != 0 filter in store_cancel_get (store_bridge.rs:1226-1234) safe. The walk_chain rewrite (index.rs:171, 184-214) is correct and has no off-by-one regression for ordinary chains (steps tracks nodes.len() when every parent has tail_pages > 0, so the extra steps >= max_nodes gate fires at exactly the old bound), and it genuinely bounds zero-page chains. The withdraw_queued predicate (requester.rs:1177) now matches the three other release sites (:739, :790, :898). The Agent::window_drained fix (agent.rs:1561-1565) is correct — forget_window before fail means drive's cleanup loop (:1637-1642) can no longer re-release the slot. The docs edit matches the new code, and there is no proto/Cargo/on-disk change.

Findings.

  1. Major — selene/src/composite.rs:1125-1133 quarantines on transient record I/O, not just corruption: if error.is_record_read() { self.disk.quarantine_corrupt(&node); }. is_record_read() is set on Operation::Open failure too (disk_store.rs:1099-1104: file.state = FileState::Closed; self.fail(error.with_record_read())), and quarantine_corrupt permanently does set_ready(key,false) … node.location.failed = true (disk_store.rs:3099-3105). Impact: one EIO/ENOENT/EMFILE while opening any record of a chain marks that ancestor failed until recaptured; every descendant lookup then misses (is_failed feeds needs_row, disk_store.rs:2507-2514), and a full re-store is needed. The packed path already distinguishes content errors (composite.rs:1088-1103 gates on packed::Checksum). Fix: gate the new arm on a content/corruption predicate, not is_record_read (or record the failing Operation and quarantine only on ReadPages|ReadRow|ReadPacked content errors).

  2. Major — description/evidence accuracy, three places. "All 11 added regression tests verify each invariant directly on production entry points" is not accurate: the collision test builds the claim through #[cfg(test)] Claim::new_for_test (claims.rs:283-291) with a seeded ManagerGet { transfer: 0 } and drives manager_get directly, and linked_multi_process_put_… hand-builds PutRec { accepted: None, … } and feeds PutAnswer — neither passes through claim_begin/put_begin framing. Two of the tests can pass vacuously: corrupt_ancestor_v3_page_is_quarantined_and_replaceable starts with let Some(directory) = test_directory(...) else { return; } (composite.rs:6000-6003), and async_cpu_codec_refill_wakes_deferred_child is #[cfg(feature = "codec")] (memory.rs:6258-6259) while the reported command only passes --features test-support. Fix: re-run with --features test-support,codec and state which tests bypass production entry points.

  3. Minor — selene/src/shared/index.rs:503-511: take_while → filter makes the sweep scan the whole order map (ordered() at :347-349) instead of stopping at the first fresh leaf; take(64) now caps the result only. This runs on the once-a-minute model-thread poll (and per namespace on the manager's tick, per the doc). Cost grows with live-node count rather than with the number of expired leaves. Also, the mechanism named in #439 (touch_ancestors refreshing last_used without advancing accessed, index.rs:477-490) is left in place — the fix scans past the symptom, which is the kind of skip the charter's #397 asks reviewers to question. Fix: either advance the tick in touch_ancestors (keeps take_while valid and makes the scan O(prefix)) or bound the number of examined nodes.

  4. Minor — selene-manager/src/pool/claims.rs:1513-1516 removes validation, not just the release, for channel requesters on the untrusted gRPC path: if claim.channel().is_some() { return Ok(()); } sits before the window was never issued / WindowReleased before the window was filled violations at :1517-1529. Any bogus index or premature release from a channel requester is now silently accepted. Also, the guard's leg differs from the one the description compares it to: channel() = root(&legs,false) (:293) is the requester leg, while window_filled tests source_channel() = root(&legs,true) (:296, 1437). Fix: keep the index/phase validation and return Ok(()) only after it, without calling reader_done.

  5. Minor — selene-manager/src/pool/store_bridge.rs:643-647: the grant.page_first as u32 - rec.accepted.expect("put accepted").1 subtraction is now evaluated for every grant, and before the region check at :651-655 (previously the expression was only reached after let Some(region) = region else { put_fail_by_key(…); return }). A store grant whose page_first precedes the accepted first page now panics in debug / wraps in release instead of failing the put cleanly, and the value is computed even for single-process puts, where PutWin.first_page is never read (put_commit uses mp.whole only when mp.layout.world() > 1, :1052). Fix: checked_sub with put_fail_by_key(Io, …), computed after the region validation.

  6. Minor — selene/src/memory.rs:2347-2349 now calls start_deferred for a record whose async CPU-codec refill is still in flight; the deleted if !refill guard was the only thing keeping deferred children of that key from being woken before the refilled row is published. The new test asserts the child wakes and that the parent ends with a row, but not that the wake happened after the row landed. Worth confirming start_deferred (memory.rs:1693) re-checks readiness before releasing a child; otherwise a child can be committed against a parent whose row is still being written.

  7. Minor — no backstop for a peer that never reports, now that withdraw_queued refuses to release (requester.rs:1170-1189). Release and claim removal both depend on peer done: drive_claim's gone requires claim.peers.iter().all(|p| p.done.is_some()) (:1016-1020) and the only slot cleanup is inside that branch (:1027-1033). If a cancelled rank never answers, peers_left stays non-empty and neither the window nor its slot is released. Worth documenting which path guarantees it (rank link loss → on_peer_done?) and adding a test with a never-done peer, as the description does not say.

  8. Minor — helios/src/server/runtime.rs:2117-2121 clears blocked and restore_wait on every park. RestoreWait::defer starts its budget from self.started.get_or_insert(now) (:224-236), so each park restarts the "restore must beat recompute" wait budget (:2855-2861); a repeatedly preempted request resets rather than exhausts it. The description lists these two fields as "surviving pre-admission" state to clear but the test only covers pool_plan/pool_lookup.

  9. Minor — store_bridge.rs:599-602: Ok(PutAnswer::Accept(accept)) stores accept.parent/first_page with no correlation to rec.transfer, so the manager's "disjoint transfer ID" invariant is enforced only by store-side echoing; a mis-routed answer now corrupts windows silently (previously the id space overlapped so a mix-up was at least visible). Add an assertion against rec.transfer if PutAnswer::Accept carries the echoed id.

No lock/contention, memory-amplification or cross-platform (Unix/Windows) defect was introduced by the production hunks; the added debug_assert! in Staging::release (net.rs:159-167) is a debug-only detector, so the underlying double-push into free is still possible in release builds from any other caller.

#2 [high] PR #607 correctness review — sound areas and 9 findings with line cites

Lens: Correctness, Contracts & System-Level Consequences. All at pr/607 (head 4f12cae).

VERIFIED SOUND (do not re-report as bugs):

FINDINGS:

  1. MAJOR composite.rs:1125-1133 quarantines on transient I/O. Quote: (Err(error), position) => { let _ = self.memory.complete_record(&node, false); if let Some(index) = position { inbound.nodes[index].state = NodeState::Waiting; } if error.is_record_read() { self.disk.quarantine_corrupt(&node); } inbound.error.get_or_insert(error); }. is_record_read also set on Open failure: disk_store.rs:1099-1104 Operation::Open => match reply.result { Ok(()) => {} Err(error) => { file.state = FileState::Closed; self.fail(error.with_record_read()); } }. quarantine_corrupt permanently: disk_store.rs:3099-3105 let _ = self.index.set_ready(key,false); self.index.drop_row(key); ... node.location.failed = true. Consequence: one EIO/ENOENT/EMFILE on open marks ancestor failed until recaptured; descendants stop being selectable (needs_row/covered_endpoint disk_store.rs:2507-2514). Packed path already gates on content error (composite.rs:1088-1103 checks packed::Checksum). Fix: quarantine only on content corruption, not is_record_read alone.
  2. MAJOR claim-accuracy: "11 tests verify each invariant directly on production entry points" inaccurate. Claim::new_for_test is #[cfg(test)] (claims.rs:283-291) — collision test seeds ManagerGet { transfer: 0, .. } and calls manager_get directly; linked-mp test hand-builds PutRec{accepted:None} and feeds PutAnswer, so put_begin/framing not exercised. Two tests can pass vacuously: composite.rs:6000-6003 let Some(directory) = test_directory(...) else { return; }; memory.rs:6258-6259 #[cfg(feature = "codec")] while reported command used only --features test-support.
  3. MINOR selene/src/shared/index.rs:503-511: filter over self.ordered() (ordered() = :347-349 full order map iteration) means the sweep scans every live node each minute instead of stopping at the first fresh leaf; take(64) caps only the result. Sweep runs on model-thread poll (docs say at most once a minute; manager sweeps every namespace per store tick). Root mechanism named in #439 (touch_ancestors refreshing last_used without advancing accessed, index.rs:477-490) left in place — a skip, not a root-cause fix (charter #397 tension). Fix: advance tick in touch_ancestors, or bound examined nodes.
  4. MINOR selene-manager/src/pool/claims.rs:1513-1516 guard removes validation on the untrusted gRPC path: quote if claim.channel().is_some() { // A data-channel requester's windows are released when its handler reports them sent. return Ok(()); } placed BEFORE the violations at :1517-1529 ("WindowReleased names a window that was never issued" / "WindowReleased before the window was filled"). Also guard leg differs from the one cited: channel() = root(&legs,false) (claims.rs:293 requester leg) vs window_filled's source_channel() = root(&legs,true) (:296, :1437). Fix: validate index/phase first, then return Ok without reader_done.
  5. MINOR store_bridge.rs:643-647: let first_page = if grant.page_count == 0 { 0 } else { grant.page_first as u32 - rec.accepted.expect("put accepted").1 }; is now computed for every grant and BEFORE the region validity check (:651-655 let Some(region) = region else { self.put_fail_by_key(key, v2::Reason::Io, "a window in an unknown region"); return; };) — in main the subtraction lived inside the WindowSpec after that check. Panic/wrap risk on a bad grant; also computed for single-process puts where PutWin.first_page is unused (put_commit uses mp.whole only when layout.world()>1, :1052). Fix: checked_sub + put_fail_by_key, after region validation.
  6. MINOR selene/src/memory.rs:2347-2349 (deleted if !refill guard, now unconditional self.core.start_deferred(&key, events)): deferred children of a key whose async CPU-codec refill is still in flight can be woken before the refilled row is published. New test asserts child stored + parent ends with row, not ordering. Verify start_deferred (memory.rs:1693) re-checks readiness.
  7. MINOR requester.rs:1170-1189 + :1016-1020: no backstop if a peer never reports. gone requires claim.peers.iter().all(|p| p.done.is_some()); slot cleanup only inside that branch (:1027-1033). Cancelled rank that never answers leaves peers_left non-empty, so neither window nor slot is released. No test for a never-done peer; description does not say which path guarantees release.
  8. MINOR helios/src/server/runtime.rs:2117-2121 clears blocked and restore_wait on every park; RestoreWait::defer starts from self.started.get_or_insert(now) (runtime.rs:223-236) so each park restarts the "restore beats recompute" budget (used at :2855-2861) rather than exhausting it. Test (phase_tests.rs:6851-6928) covers only pool_plan/pool_lookup.
  9. MINOR store_bridge.rs:599-602 Ok(PutAnswer::Accept(accept)) => { rec.accepted = Some((accept.parent, accept.first_page)); ... } never correlates accept with rec.transfer, so the disjoint-ID invariant rests on the store echoing correctly; a mis-routed answer silently corrupts window geometry. Add an echoed-id assertion if PutAnswer::Accept carries it.
  10. NOTE net.rs:159-167 duplicate-release detection is debug_assert! only (compiled out in release); the release-mode fix is behavioural only (forget_window).

Reach notes: no lock/contention, allocation-amplification or Unix/Windows parity defect introduced by the production hunks. Manager-side store work still runs through store_call/block_in_place (store_bridge.rs:89-114) unchanged in kind.