PR #609: fix(selene): preserve DMA, RDMA, and shared-region lifetimes across cancel, close, and scatter

Raw Markdown for agents: https://autobot.eidonix.com/api/v1/cases/2c454f4d-6a00-457c-b60c-40a2611c9111

Opened by a workflow run, Nov 29, 2026 12:56 PM EST. decide malicious: all_clear (100%): No malicious content found

explore

Author: yatesdr (COLLABORATOR; Discord "D-Rock") Motivation: The GPU copy, compression and RDMA code can still touch host-shared memory while the pool unmaps or frees it, and Selene's manager could hand out overlapping mutable slices. This makes each teardown, quarantine, RDMA and shared-region path keep its backing memory alive and hand out disjoint byte ranges. Scale: +225 / −71 lines in 15 files Proposal:

Full report · Notes

Value Proposition

Value Proposition — PR #609, "fix(selene): preserve DMA, RDMA, and shared-region lifetimes"

Charter alignment — on-goal, no non-goal touched. Hardening the host prefix-cache / Selene path matches the Goal "Store prefix-cache checkpoints in host memory and share them across Flare instances via Selene." No wire-protocol, on-disk format, config, CLI, dependency or public-API change; no per-model branches or flags, so "keep the runtime small" and "pin everything (#215)" hold. The deliberate leaks on failure paths are ownership retention, not swallowed errors, so the root-cause rule (#397) is honoured in spirit.

Novelty & status — genuinely additive, weakly isolated. Nothing was reverted; the PR stacks on reviewed #607, the strongest independent corroboration that pool-staging UAF/aliasing was real. It is neither obsolete nor superseded. But #611 rewrites Agent::quarantine and conn::shutdown one commit later, #612 lands the same checked-arithmetic hardening and prunes part of the multi-rank surface #609 made alias-free, and #610 rewrites the same store/teardown files — substantial same-day overlap, and nothing isolates #609's own contribution.

Value vs maintenance cost. The defects are real: the CompositeStore::close short-circuit and the unattached Windows IOCP handle are plainly visible, and the aliasing strand was verified reachable. But the evidence is one qualification run cited verbatim across four PRs, executed on the combined stack before rebase; the named CUDA suite (helios::offload::) is in a crate this PR does not touch; "zero latency regression" has no numbers — failing the "bring real evidence (#210)" bar. Costs: 15 files, invisible Drop-order invariants no compiler protects, an unexercised #[cfg(windows)] path, red head CI, zero reviews, and — decisive — relaxation of #497's fail == Some(1) assertion, deleting the only test for the very close short-circuit being fixed, with no replacement asserting both closes now run. New operator-visible behaviour ("host KV compression did not finish before close", PoolStatus::Disabled with process-lifetime retention) is undocumented.

Verdict: Worth it with changes — assessed retrospectively; it was merged 19 minutes after opening with 0 reviews on a failing head commit. The substance belongs in the project; the submission did not meet it. Needed: post-rebase evidence isolating #609 on SM120/SM121 with actual latency figures; Windows CI confirmation; replacement (not deletion) of the #497 assertion; documentation of the new close error and widened quarantine retention; and separation of the checked-arithmetic hunks that duplicate #612.

Full report Decide Value: yes (100%): This change is worth reviewing: it provides value to the project in line with its charter.

Classify intake

Selected: triage:review, bug, area:selene

Threshold: 65%

Triage

Priority

Type

Area

Model

Apply Labels (Intake)

Applied: +triage:review, +bug, +area:selene

Subtraction and simplicity

The diff is lean in direction — no new flags, cfg knobs, feature gates, fallback layers or public API (all new items are pub(crate)) — but it adds three constructs that duplicate constructs already in the tree. No finding is a correctness bug; each is a delete-or-collapse.

  1. HIGH: SliceLayout::scatter_disjoint (selene/src/shared/slice.rs:214-248) is a line-for-line copy of the existing safe scatter (slice.rs:180-206) — identical check, identical slice_bytes guard, identical page_at/row_at loop. Make scatter a 3-line unsafe wrapper; ~18 lines deleted, all five existing callers unchanged.
  2. MED-HIGH: the new Windows IOCP attach (selene/src/disk.rs:2031-2035) is the third verbatim #[cfg(windows)] ring.queue.attach(&file).map_err(...) copy (pre-existing at disk.rs:986-990, 1296-1300). One cfg'd helper removes two of three cfg attributes and makes the only unverified code path identical to the reviewed one.
  3. MED: MemoryStore::close recomputes the codec-idleness predicate it already has in the busy closure ten lines above (memory.rs:3095-3098 vs 3077-3086). One compressor_busy() method kills both cfg pairs and moves the mem::forget cfg out of the function operators must reason about.
  4. MED-LOW: LocalRegions::ptr_mut (selene-manager/src/regions.rs:58-66) is a pass-through alias of the private range (regions.rs:30-40) that also echoes the caller's own length back.
  5. LOW: take + mem::forget is now at 7 sites (pool/engine/mod.rs:555-566, pool/agent.rs:1729-1737) with no helper, and the Arc rewrite made the field-order comment at pool/net.rs:61-63 stale — this PR updated memory.rs/disk_store.rs (not opened) comments but not that one.
  6. LOW: checked-add in SliceLayout::new (slice.rs:69-74) is a rigour its producer Layout::new (geometry.rs:177-178) does not follow, and is outside the PR's stated thesis.

Open: whether docs/TODO.txt records the unverified Windows attach (unconfirmed); whether the relaxed offload/tests.rs:659 assertion still leaves coverage for the close short-circuit.

Full report · Notes

Correctness and contracts

Correctness/contracts/system-level review of PR #609. The proposed mechanisms are mostly sound, but three Major contract defects survive into main and the aliasing fix moves UB rather than removing it.

  1. Major — CompositeStore::close clears its journals even when a tier fails (selene/src/composite.rs:1602-1626). The doc still promises "An error leaves ownership intact until their transfers can be drained", but the unconditional outbound/parked/inbound/jobs/stale.clear() now runs before disk.and(memory) returns. The pre-change self.disk.close()?; short-circuited. On failure the composite erases the outstanding-copy record while MemoryStore::close has deliberately pool.leak()ed, and then reports outbound_in_flight == 0 (composite.rs:1611-1613). Fix: clear only when both tiers succeed.

  2. Major — disk.and(memory) discards the new memory error (composite.rs:1626 vs memory.rs:3108-3116). "host KV compression did not finish before close" is lost exactly when disk also failed — the leaked-pool + forgotten-compressor case it was written for. Fix: fold both messages.

  3. Major — ptr_mut is a safe fn returning a writable raw pointer (selene-manager/src/regions.rs:59-66) while sibling bytes is unsafe for the same access (:68-80). Raw writes at selene-manager/src/data/channel.rs:934-942; the new test at regions.rs:132-146 establishes overlapping views as normal. The aliasing-UB class is relocated to raw pointers with the unsafe marker removed. Fix: make it unsafe fn with the disjointness/lease contract.

  4. Minor — conn::shutdown's new engine.quarantine() (selene/src/pool/conn.rs:216-223) now fires for a still-open, merely slow session (previously gated on sess.is_none(), engine/mod.rs:533-544), permanently mem::forgeting session/SHM regions and staging and setting PoolStatus::Disabled (mod.rs:549-573). Correct intent, undocumented consequence.

Verified sound: field reordering, ActiveGuard (fixes a real shutdown hang), Arc<Region> RDMA re-plumbing, scatter_disjoint bounds, Windows IOCP attach placement. The relaxed offload/tests.rs:659 assertion is legitimate, not lost coverage. Gaps: no concurrent test of the aliasing fix, no test of the shutdown-timeout branch, "zero latency regression" carries no numbers, and the cited CUDA suite is helios::offload::, untouched by this PR.

Open: which CI job failed on 304dd3a (possibly the Windows job); whether #610 already reconciled the composite close path.

Full report · Notes

Final review

Recommendation: Changes Requested

The core lifetime and aliasing fixes in PR #609 are technically sound and address real teardown, quarantine, RDMA-registration, Rust aliasing-UB, and Windows IOCP defects across selene and selene-manager. However, direct inspection of the changed close paths caught a concrete bug in MemoryStore::close (where a copier close error bypasses std::mem::forget(compressor) while compression is still busy, leaving AsyncCompressor::drop exposed to a condvar hang) and a broken error-path invariant in CompositeStore::close (clearing in-flight tracking maps even when a tier fails to close). Fixing those two small defects—and verifying the uncompiled #[cfg(windows)] attach path—will make this ready to merge.

Merge Risk

Level: Medium

Walkthrough

Pre-merge Checks

Blockers

  1. MemoryStore::close skips mem::forget(compressor) when transfers.close() also fails (selene/src/memory.rs:3104-3116).
    • Verified behavior & impact: When both closed.is_err() and compressor_busy are true, line 3105 leaks self.core.pool, then line 3107 (closed?;) returns early before lines 3108-3112 take and forget self.compressor. While helios/src/server/runtime.rs:1260 wraps the top-level store in ManuallyDrop on close error, MemoryStore is a public HostStore implementation; any standalone caller, test, or unwind path that drops MemoryStore after this error executes AsyncCompressor::drop (selene/src/memory.rs:2043-2054), which blocks indefinitely on self.active.1.wait(count) while *count > 0—defeating the exact close-timeout safeguard this PR adds.
    • Concrete fix: Forget the busy compressor before propagating closed?:
      if closed.is_err() || compressor_busy {
          self.core.pool.leak();
      }
      if compressor_busy {
          #[cfg(feature = "codec")]
          if let Some(compressor) = self.compressor.take() {
              std::mem::forget(compressor);
          }
      }
      closed?;
      if compressor_busy {
          return Err(Error::new(
              "host KV compression did not finish before close",
          ));
      }
      

Should Fix

  1. CompositeStore::close clears in-flight journals unconditionally even when a tier fails to close (selene/src/composite.rs:1602-1627).
    • Verified behavior & impact: Before this PR, self.disk.close()?; self.memory.close()?; returned before clearing outbound, parked, inbound, jobs, and stale. Now those five maps are cleared even when disk.is_err() or memory.is_err(), directly contradicting the doc comment at selene/src/composite.rs:1603-1604 ("An error leaves ownership intact until their transfers can be drained"), diverging from MemoryStore::close (selene/src/memory.rs:3107-3118, which skips abandon()/events.clear() on error), and causing CompositeStore::stats() (selene/src/composite.rs:1558-1561) to under-report outbound_in_flight / inbound_in_flight after a failed close.
    • Concrete fix: Propagate the tier close error before clearing:
      let disk = self.disk.close();
      let memory = self.memory.close();
      disk.and(memory)?;
      self.outbound.clear();
      self.parked.clear();
      self.inbound.clear();
      self.jobs.clear();
      self.stale.clear();
      Ok(())
      
  2. Verify the uncompiled #[cfg(windows)] IOCP attach (selene/src/disk.rs:2032-2035) in Windows CI.
    • Verified behavior & impact: The placement and contract match selene/src/disk.rs:986-990, selene/src/disk.rs:1296-1300, eos/src/completion.rs:49-54, and eos/src/windows.rs:115-124, but the PR notes it was never compiled or run on Windows. Confirming a green Windows build/test run closes the only uncompiled code path in the diff.

Subtract / Simplify

  1. Deduplicate SliceLayout::scatter by delegating to scatter_disjoint (selene/src/shared/slice.rs:181-248).
    • scatter (181-206) and scatter_disjoint (214-248) repeat identical check, slice_bytes, error-string, and page/row loop logic. Replace lines 189-205 with:
      // SAFETY: `&mut [u8]` provides exclusive access to `window` and cannot alias `packed`.
      unsafe { self.scatter_disjoint(rank, window.as_mut_ptr(), window.len(), pages, row, packed) }
      
      Deletes ~17 lines and guarantees one scatter implementation.
  2. Extract one Ring::attach helper for the three identical Windows IOCP attach blocks (selene/src/disk.rs:986-990, 1296-1300, 2032-2035).
    • Adding a small #[cfg(windows)]/#[cfg(not(windows))] Ring::attach(&self, file: &File, what: &str) -> Result<()> helper removes the repeated #[cfg(windows)] blocks at all three call sites and ensures ReadAhead::start shares the exact attach code compiled for record readers/writers.
  3. Eliminate the duplicate #[cfg(feature = "codec")] idleness check in MemoryStore::close (selene/src/memory.rs:3078-3081 vs 3095-3098).
    • Add a fn compressor_busy(&self) -> bool helper on MemoryStore so the drain loop (!store.compressor_busy()) and post-loop leak/forget check (self.compressor_busy()) cannot drift and close drops the repeated #[cfg] pairs.
  4. Collapse LocalRegions::range into LocalRegions::ptr_mut (selene-manager/src/regions.rs:30-66).
    • ptr_mut is currently a 1-line pass-through to private range with an identical signature. Inlining range's body into ptr_mut and calling self.ptr_mut(...) from bytes_read and bytes removes the redundant wrapper with no API change.

Nits

Dropped on verification

Full report

Classify triage

Selected: triage:review

Threshold: 65%

Triage

Apply labels

No label changes Decision to Test: no (100%): Testing will not add significant value as the code stands today. The code is either not yet ready to merge, or adequate testing has already been done to validate the contents of the code, or the available hardware is not suitable to test with.