#1 [high] PR #699 changed-code facts (verified)
Diff (5 files, +175/−12), head 135633f, base main.
budget.rs:15-28 costs from Iterator<Item=u64> to (u64,u64); additional_host = bytes.saturating_sub(backed_bytes.min(bytes)); device term unchanged bytes.div_ceil(512).
budget.rs:30-42 charges: device + host.div_ceil(integrated) for integrated devices only — so zeroing host also removes the per-GPU shared-host apportionment.
budget.rs:44-72 approve maps (region.bytes, region.backed_bytes); host Err and GPU-rank errors unchanged.
startup.rs:19-46 RegisteredRegion/PlannedRegion gain required pub backed_bytes: u64; both #[derive(Clone, Debug, PartialEq, Eq)], no #[non_exhaustive], no Default; re-exported at pool/mod.rs:60 pub use startup::{Approve, PlannedRegion, RegisteredRegion};.
conn.rs:678-699 linux backed_shm_bytes: CString, libc::statfs, f_type as u64 == libc::TMPFS_MAGIC as u64, then metadata(path).blocks()*512 min declared_bytes, 0 on any failure.
conn.rs:701-704 non-linux stub -> 0.
conn.rs:706-717 registered_region gained backed_bytes param (pub(crate)).
conn.rs:774-779 measures backed for shared.arena_path/staging_path BEFORE Regions::map at conn.rs:813-829.
conn.rs:794-800 remote data-staging backed_bytes: 0.
conn.rs:852-864 RegisteredRegion gets shared_backed.unwrap_or((0,0)).
conn.rs:865-870 still prints registered {:.1} GiB of pool memory from full bytes sum — does not print backed.
builder.rs:239-245 registration_costs maps (bytes as u64, backed_bytes); builder.rs:188-193 charges uses it with host: Ok(0).
builder.rs:246-249 summary() = "{host} host bytes · {device} device bytes per GPU" — now smaller.
#2 [high] F1/F2 — ordering/race and file-sharing findings with citations
F1 (Major) selene/src/pool/conn.rs:774-779 measures backed bytes from shared.arena_path/staging_path BEFORE Regions::map at conn.rs:813-829 / shm.rs:42-66. Region::map re-stats: shm.rs:53-57 if len == 0 || size < bytes { Err(...) }. If a manager with a larger --memory/--staging had preallocated the old files, allocated_blocks=new_size (FS_IOC_SETFLAGS) lets fallocate extend st_size via sparse pages with 0 blocks; metadata after = arena+staging => host charge 0 at conn.rs:780-793, approval passes, then map fails on size < bytes. Before the patch, the plan charged full bytes and rejected with a budget message, never entering the map. Root cause: two independent stats race the manager. Fix: derive backed from the same metadata/mapped mapping (shm.rs holds the fd and len; return blocks from map).
F2 (Major) selene/src/pool/conn.rs:774-779 measures immediately after Hello, but the tmpfs pages are trivially reclaimable: no mlock anywhere (verified grep), owner Regions::Reuse destructor: :300-330 / Region::Drop shm.rs:139-153. If the manager restarts/takes Regions::Recreate/local.rs:194-206 or another process/drop-cache reclaims tmpfs, the pages get zapped and are re-faulted by mmap+first touch, i.e. real host RAM again. The security margin the old full-byte charge provided (for the window between approve and registration/first touch) is now 0, so a kernel-defined estimate yields an unbounded-overcommit admission policy on a 1/N-shared region.
F3 (Major) The design docs state a contract this PR breaks without updating: docs/runtime-core-design.md:768-771 "On integrated GPUs such as GB10, that budget is Linux MemAvailable, capped by CUDA's device total. CPU allocations, registered buffers, and GPU allocations share physical DRAM". docs/cli-design.md:884-891 "Integrated GPUs also count resident host tables, embedding row caches, and prefix-cache host pools in the same physical budget. Shared host memory is charged once per host." After this twice-priced once accounting, on the host in the report (494.5 GiB unified) tmpfs arena+staging leaves the physical budget entirely. AGENTS.md:182-186 says do not "relax ... references, workloads ... to obtain passing checks".
F4: nothing.
F5: none raised.
F6 (Major) selene/src/pool/startup.rs:19-46 — RegisteredRegion and PlannedRegion are publicly re-exported (selene/src/pool/mod.rs:60) and each gains a required pub backed_bytes: u64; not #[non_exhaustive], no Default. Out-of-tree constructors (helios/src/offload/pool/tests.rs:13-18, PoolBuilder { budget: Budget... }) break compilation. Undeclared in the body.
#3 [high] F4/F6, metric shift, and why no concurrency hazard
F4 (Major) selene-manager preallocates its regions under /dev/shm/selene/<instance>/ (selene-manager/src/local.rs:26 pub const SHM_ROOT: &str = "/dev/shm/selene";, :581-602 fallocate). The client budget exclusion starts from host path (realpath, blocks) (conn.rs:686-698). So the manager may move (bind-mount) or be created from a restored/manually-created file and this silently still counts.
F6 (Major) SELECTED: selene/src/pool/conn.rs:774-779,780-793 / shm.rs:53-57 vs free-space. Also: after this change, the host fill on /dev/shm that the manager's later growth needs is never checked: host_pool_budget (offload.rs:951-985) subtracts MemAvailable-reserve; nothing checks /dev/shm free space or fallocate reserving the region at the manager. But the manager allocates before the instance starts (selene-manager/main.rs), so this belongs to a different code path.
UNSELECTED: AGENTS.md:194-199 "Require focused, meaningful validation. Tests must exercise the affected behavior... source-text checks and mocks that bypass the behavior cannot establish runtime correctness." New tests fabricate PlannedRegion (budget/tests.rs:92-186) and never run the statfs or an attachment (body admits it).
Also found: baseline uses Fabricate approach; the platform tests are in src/*_test*.
System-level consequences:
- No new locks, channels, threads, syscalls on a hot path;
backed_shm_bytesruns only inregister_memoryon the one startup connect (conn.rs:638-650,None => // The first connect: the only time anything is registered.) and runs insidetokio::task::spawn_blocking(conn.rs:748). - Failure propagation unchanged:
approveerror still returned via conn.rs:801-812, closes registration conn.rs:653-656. - Memory amplification: none; two extra
statfs+metadatasyscalls per attachment. - Metric shift:
registered {:.1} GiB of pool memory(conn.rs:866-870) still prints full bytes whilePreparedPool::summary()(builder.rs:246-249) now prints host bytes minus backed, andcharges(builder.rs:188-193) shrinks. Two operator-visible numbers now disagree; the larger one reads as if more was committed than was approved.
#4 [high] Research summary
Reviewed PR #699 (5 files, +175/−12) against the changed code, its callers, and the contracts/docs it touches. The arithmetic in Budget::costs is sound and I found no concurrency, locking, memory-amplification, or failure-propagation regressions: backed_shm_bytes runs only on the single first-connect registration path (conn.rs:638-650), inside spawn_blocking, adding two syscalls and no state. The device charge is correctly preserved, the overflow checks and host: Err propagation are intact, and the non-Linux stub is correct.
The substantive findings are about trusting the new number and contracts left behind:
-
Ordering/race (Major,
conn.rs:774-779vsshm.rs:53-57). Backed bytes are measured from the path beforeRegions::mapre-stats the file. For a manager restarted with larger--memory/--staging,fallocateextends the old file'sst_sizesparsely with zero blocks, so the pre-map measurement reports host charge 0 and approval passes, andmapthen fails with "shared memory … has N bytes, expected M" — a confusing error reached only because this change removed the pre-map full-byte charge. Fix: derive backed bytes from the samemetadata/fd used bymap. -
The measurement is a reclaimable estimate used as a hard admission fact (Major). tmpfs pages are not
mlocked (verified: nomlockin the tree) and the manager'sRegions::Recreatepath (local.rs:194-206) can zap them; once reclaimed, first touch re-allocates real host RAM that is now charged at 0, removing the whole safety margin the old full-byte charge provided for a region shared by all attaching instances. -
Contract/docs not reconciled (Major).
docs/runtime-core-design.md:768-771anddocs/cli-design.md:884-891both state that on integrated GPUs prefix-cache host pools count in the same physical budget and that "Shared host memory is charged once per host"; the new test pins the opposite for unified hosts (budget/tests.rs:118-123), the exact configuration from the report. Also an undeclared source break:PlannedRegion/RegisteredRegiongain a required public field (re-exported atmod.rs:60, not#[non_exhaustive]). -
Evidence and operator output (Major/Minor). Neither the
statfshelper nor an attachment path is exercised by a test, contrary to AGENTS.md:194-199, and the live-manager harness that could do it (helios/src/offload/pool/tests.rs) uses onlyu64::MAX/1budgets.summary()now reports a smaller host figure whileconn.rs:866-870still prints the full byte sum, so the two operator-visible numbers disagree.
#5 [high] FINAL findings table for PR #699 with verbatim quotes (report source)
PR #699, head 135633f, base main. 5 files, +175/−12. No CI, no reviews, first-time contributor. VERDICT: arithmetic sound; the issues are about trusting the new measurement and about unsynchronised contracts.
--- FINDING 1 — Major — measurement precedes the map that validates it (ordering/race) ---
selene/src/pool/conn.rs:774-779 (measure) vs conn.rs:813-829 (Regions::map):
let shared_backed = shared.map(|shared| {
(
backed_shm_bytes(&shared.arena_path, shared.arena_bytes),
backed_shm_bytes(&shared.staging_path, shared.staging_bytes),
)
});
then conn.rs:780-793 builds the plan (host charge = bytes - backed) and conn.rs:801-812 approves;
only afterwards conn.rs:813 let regions = shared.map(|shared| { Regions::map(shared) ... }.
shm.rs:42-57 is the real authority and can still fail after approval:
let size = file.metadata()...?.len();
if len == 0 || size < bytes {
return Err(Error::new(format!(
"shared memory {path} has {size} bytes, expected {bytes}"
)));
}
IMPACT: for a manager restarted/recreated with larger --memory/--staging over a preallocated old file
(local.rs:627-667 reusable -> Regions::Recreate, local.rs:194-206 removes and recreates),
fallocate can extend st_size in sparse pages with zero blocks, so the pre-map reading reports the regions
as fully backed (host charge 0) and approval passes; map then fails with the byte-count error. Pre-patch the
plan charged full bytes, so the budget normally stopped the attach before map, and the operator got a
budget message ("reduce the manager's --memory and --staging sizes") instead. Note: the sparse-extension
kernel behaviour is inferred from fallocate semantics, NOT executed in-repo — mark as inference.
FIX: take backed bytes from the same metadata/fd that Region::map uses (shm.rs already opens the file and
holds the fd), i.e. return blocks from map instead of stat-ing the path twice.
--- FINDING 2 — Major — a reclaimable estimate is used as a hard admission fact --- conn.rs:696-698: std::fs::metadata(path) .map(|meta| meta.blocks().saturating_mul(512).min(declared_bytes)) .unwrap_or(0) and budget.rs:19: let additional_host = bytes.saturating_sub(backed_bytes.min(bytes)); IMPACT: tmpfs pages are not mlock'ed anywhere (verified: no mlock in the tree) and are reclaimable; the manager's Recreate path (local.rs:194-206) and any process pressure can drop them, after which first touch re-allocates real host RAM that this change now charges 0 for. The old full-byte charge was the only margin covering the window from approve to first touch, and it is the same physical region shared by all attaching instances (the PR body itself says "(N + 1)× when multiple instances map the same shared files"). FIX: keep a fraction of the region charged (or charge unbacked remainder plus a bound on reclaim), or state explicitly in the code and docs that the pool budget is now an estimate and not an admission guarantee.
--- FINDING 3 — Major — public contract + design docs contradict the new behaviour on unified hosts ---
startup.rs:19-46, both re-exported at pool/mod.rs:60 pub use startup::{Approve, PlannedRegion, RegisteredRegion};:
pub struct PlannedRegion {
pub name: &'static str,
pub bytes: u64,
/// As [RegisteredRegion::backed_bytes]. Only bytes - backed_bytes draws
pub backed_bytes: u64,
}
No #[non_exhaustive], no Default => out-of-tree constructors break (undeclared in the body).
budget.rs:30-42 charges apportions host.div_ceil(integrated) to every integrated device, so zeroing host
also removes the per-GPU shared-host charge; budget/tests.rs:118-123 pins that for the unified case:
let budget = Budget { host: Ok(25u64 << 30), devices: vec![(device, false), (device, true)] };
assert!(budget.approve(&plan).is_ok());
assert_eq!(budget.charges(host, device), vec![device, device]);
Docs that still assert the opposite (not updated by this PR):
docs/runtime-core-design.md:768-771 "On integrated GPUs such as GB10, that budget is Linux MemAvailable,
capped by CUDA's device total. CPU allocations, registered buffers, and GPU allocations share physical DRAM"
docs/cli-design.md:884-891 "Integrated GPUs also count resident host tables, embedding row caches, and
prefix-cache host pools in the same physical budget. Shared host memory is charged once per host."
IMPACT: on the reported 494.5 GiB unified host, tmpfs arena+staging leave the physical budget entirely;
AGENTS.md:182-186 forbids relaxing references/bounds to obtain passing checks, and AGENTS.md:171+ requires a
maintainer decision for scope/invariant changes.
FIX: reconcile the docs and get an explicit maintainer decision for the unified-memory case (or keep the
per-GPU apportionment for integrated devices while exempting only the host term).
--- FINDING 4 — Major — the new syscall path and the attachment path are never executed ---
conn.rs:683-699 has no test; budget/tests.rs:92-186 fabricate PlannedRegion values; conn.rs:1013-1043 tests
only pass None/(1,4096) with ClosedRegistrar; the live-manager harness always passes unlimited or host:Ok(1):
helios/src/offload/pool/tests.rs:13-18 host: Ok(u64::MAX), :46-56 0 => Budget { host: Ok(1), .. }.
AGENTS.md:194-199: "Require focused, meaningful validation. Tests must exercise the affected behavior or
contract; source-text checks and mocks that bypass the behavior cannot establish runtime correctness."
The body admits: "they do not directly execute the statfs helper or a fresh manager attachment reproduction."
IMPACT: the branch that decides the whole fix has zero coverage; the tests only restate the arithmetic.
FIX: a test against selene_manager::testing::Manager (already a dev-dependency, helios/Cargo.toml:74), whose
regions really live in /dev/shm (local.rs:26 SHM_ROOT = "/dev/shm/selene"), asserting
backed_shm_bytes(arena_path, arena_bytes) == arena_bytes on a tmpfs host and 0 elsewhere.
--- FINDING 5 — Minor — two operator-visible numbers now disagree ---
conn.rs:865-870 still sums full bytes:
let bytes: usize = registered.iter().map(|region| region.bytes).sum();
eprintln!("registered {:.1} GiB of pool memory in {:.1} s", ...)
while builder.rs:246-249 summary() = "{host} host bytes · {device} device bytes per GPU" now excludes
backed bytes, and builder.rs:188-193 returns shrunken charges.
IMPACT: the startup line reports more pool memory than the budget approved, with no mention of backed_bytes.
FIX: print unbacked/backed split in the same line, or state "registered {bytes} (of which {backed} already backed)".
--- SOUND (do not invent issues) ---
- budget.rs:18-28 arithmetic:
saturating_sub(backed_bytes.min(bytes))cannot underflow or overflow, device termbytes.div_ceil(512)unchanged, both overflow checks kept (budget.rs:22,25). - budget.rs:49-58 host Err propagation and GPU-rank messages unchanged.
- conn.rs:701-704 non-Linux stub returns 0 => Windows/macOS keep old conservative behaviour.
- conn.rs:794-800 remote anonymous data-staging correctly charged 0 backed.
- No new locks/channels/hot-path syscalls: measurement happens once, on the first connect only
(conn.rs:638-641
if !link.startup.begin() { return Err(Attempt::Ended) }), inside spawn_blocking (conn.rs:748-757). No contention or blocking added; approval failure path (conn.rs:653-656) unchanged. - NUL path, statfs failure, non-tmpfs, metadata failure all fail closed to full charge.