Correctness, Contracts & System-Level Consequences — PR #496 @ ba1c73fd
Scope of inspection: all six changed files read at the PR head — selene/src/disk_store/coalesce.rs (1,416 lines, in full), the disk_store.rs diff plus its fetch/apply/Staged/HostInbound/close paths at head, selene/src/shared/record.rs (Hash), selene/src/shared/packed.rs (Hash), the docs/prefix-cache-offload.md diff, and selene/src/disk_store/coalesce/tests.rs — plus the direct callers/contracts they depend on: selene/src/disk.rs (job/Reply semantics and the single-threaded FIFO run loop), selene/src/levels.rs (Rate), selene/src/composite.rs (disk_inbound_rate, hit(), disk_read), selene/src/store.rs (not opened) (worth_fetching), helios/src/server/runtime.rs (not opened) and helios/src/server/metrics.rs (not opened).
Key findings
- F1 — Major, metric span / claim accuracy. The one sentence this PR adds about
CompositeStore(docs/prefix-cache-offload.md:1625-1627) states that itsdisk_inbound_rateis end-to-end. The code it describes is not: it samples physical/compressed disk payload bytes over a disk-read-only span that excludes codec decode and GPU upload, and that is the rate used to price admission. Two different quantities are documented as one. - F2 — Minor, tests. The anti-regression poll-latency test guards at
mean_us < 200.0(≈250× looser than the claimed 0.25–0.75 µs) and prints but never asserts the credit-regained demand pass — so the exact per-probe hashing regression the reviewer measured atcb3db468can return without a failing test. - F3 — Major, charter/evidence (#210). Every served-workload number in the description predates this head by at least two commits; the author discloses this, but the repo's charter requires served-workload evidence for performance PRs.
- The coalescing mechanics themselves are sound — verified in detail below rather than padded with invented issues: aligned planning keeps ticket-order and file-order offsets distinct, row replies match the disk thread's per-reader FIFO ordering, upload references cannot leak, shared segments are removed only after
Closed && disk_outstanding == 0, failure blast radius matches the documented private-vs-shared split (and is covered by a corrupt-ancestor test), and no public contract changed.
F1 — CompositeStore's disk_inbound_rate is documented as end-to-end but is disk-read-only over physical bytes (Major)
Citations: docs/prefix-cache-offload.md:1625-1627; selene/src/composite.rs:1059-1068; selene/src/composite.rs:954, 957; selene/src/composite.rs:357-358, 361-375; selene/src/composite.rs:340-342; selene/src/disk_store.rs:3240-3251.
The doc sentence added by this PR (verbatim, from pr_diff on docs/prefix-cache-offload.md):
+down and allow upward recovery when throughput improves. `CompositeStore`
+maintains an end-to-end `disk_inbound_rate` over `read_into` and
+`read_into_packed` completions.
The observing code (selene/src/composite.rs:1059-1068):
(Ok(bytes), Some(index)) => {
inbound.disk_bytes += bytes;
if inbound.reads == 0
&& let Some(started) = inbound.disk_started
{
self.disk_inbound_rate
.observe(inbound.disk_bytes, started.elapsed());
inbound.disk_started = None;
inbound.disk_bytes = 0;
}
disk_started is stamped only when a disk read is submitted (composite.rs:954 inbound.disk_started.get_or_insert_with(Instant::now);) and is cleared as soon as reads drains to 0 — so the sampled span begins at the first start_read and ends at the last read reply. It excludes codec decode of the v4 packed payload and the GPU/host upload, which the PR's own DiskStore rate deliberately includes (disk_store.rs:3243 let elapsed = job.started.elapsed();, observed in apply at disk_store.rs:3249 self.inbound_rate.observe(job.logical_bytes, elapsed); where started is taken before transport.fetch and logical_bytes = layout.record_bytes(chain.pages)).
The units differ too. CompositeStore denominates in physical/compressed record bytes (composite.rs:357-358):
disk_bytes += node.tail_pages as u64 * layout.page_record_bytes
+ if row { layout.row_record_bytes } else { 0 };
and prices admission with exactly that quantity against that rate (composite.rs:374):
estimated_seconds: disk_bytes as f64 / self.disk_inbound_rate.get().max(1.0)
+ bytes as f64 / memory_rate,
while DiskStore's new rate is denominated in uncompressed logical bytes.
Compounding inconsistency: the composite copies the disk store's end-to-end logical rate into its own reported stat (composite.rs:340-342):
if after.fetched > before.fetched {
self.stats.inbound_rate = after.inbound_rate;
}
so for a composite, stats().inbound_rate (exported as host_inbound_rate, helios/src/server/metrics.rs:656 (not opened)) is not the disk_inbound_rate that produced the admission estimate at composite.rs:374. The two serve different purposes but share one documentation paragraph and, on the operator side, one number that cannot be reconciled with observed restore latency.
Impact. The section this PR rewrites is the normative description of rate accounting the review lens is asked to check ("did the measured time span shrink?"). Here the doc widens the composite's described span while the code keeps the narrow one, so a reader (or a future change) can believe composite admission is priced end-to-end when it is priced on disk-read time at a 3.0 GB/s-class seed (Rate::new(INITIAL_STAGED_DISK_RATE), composite.rs:197) — over-optimistic admission when decode/upload dominates, which is exactly the regime the PR's own packed tests exercise (150 ms decode delay case).
Concrete fix. Either narrow the doc sentence to state what the composite actually measures — "the disk-read-time disk_inbound_rate over physical payload bytes for read_into and read_into_packed" — or make the composite observe end-to-end: stamp disk_started at fetch admission, stop the sample when the upload completes rather than when reads hits 0, and denominate in layout.record_bytes so the composite and the disk store share one definition. Also decide explicitly whether stats.inbound_rate for a composite should be the copied disk-store value or the composite's own pricing rate, and document whichever is chosen. This is an already-existing CompositeStore behaviour, but the PR makes it a documented contract statement, so the fix belongs here.
F2 — The anti-regression poll-latency test cannot catch the regression it was written for (Minor, tests)
Citations: selene/src/disk_store/coalesce/tests.rs:583-586; selene/src/disk_store/coalesce/tests.rs:593-602.
// Generous guard even for debug builds; release builds stay well under 2 us.
assert!(
mean_us < 200.0,
"tp{ranks} p{num_pages} fetches={fetches}: full-credit poll stalled at {mean_us:.3} us"
);
and, for the demand pass:
let credit_us = t_credit.elapsed().as_secs_f64() * 1e6;
assert!(
staged.demand_builds() > builds_before,
"expected demand build when a fetch regained window credit"
);
eprintln!(
"packed_demand_pass tp={ranks} pages={num_pages} fetches={fetches}: {credit_us:.3} us"
);
The measured quantity that regressed at cb3db468 was per-poll() cost at 8 concurrent fetches (reviewer-measured 1.47 ms / 9.73 ms / 49.33 ms). Against this assertion, a regression from 0.75 µs to 150 µs — still 200× worse than the PR's own result table, and enough to reintroduce hundreds of microseconds to milliseconds of worker-thread stall at 8 fetches — passes. The credit-regained pass, which is the one that actually exercises HeaderIdentity/WindowKey hashing across all fetches, is only printed. The PR's central performance claim therefore rests on a printed number, not a guarded invariant.
Impact. Low today, high later: the exhaustive Header/packed::Layout hashes still exist (selene/src/shared/record.rs, selene/src/shared/packed.rs) and are now paid per segment per fetch in HeaderIdentity::new; any future change that moves that work back inside a probe, or drops the cached digest, is test-silent.
Concrete fix. Assert credit_us < 200.0 as well (it is the same generous bound used just above, so it stays debug-safe), and either tighten mean_us to a debug-tolerant but meaningful bound (e.g. 20 µs) or gate a tighter bound on cfg!(not(debug_assertions)). Consider also asserting a bound relative to the 1-fetch case measured in the same test, so the guard tracks the ratio that the claim is about rather than an absolute number.
F3 — All served-workload evidence predates this head (Major, charter compliance / PR-description accuracy)
Citations: PR description "Result" and "Not covered" sections (verbatim, quoted below); project charter "Bring real evidence" (#210).
Verbatim from the PR description:
Prior live `flare run` A/B on NVIDIA GB10 (SM121) comparing `main` before v4 packed records (`c0c4f798`) against `0c04b1e2` with `--lossless-kv-compression` off
- Not covered: post-fix SM121 `flare run` re-measurement on `ba1c73fd`, live SM121 `--lossless-kv-compression` (`cpu`/`gpu`) serving, multi-host RoCE serving, 2-GPU `split_pools`, discrete PCIe GPUs, Windows serving, and live warm-plus-disk (`--prefix-cache-memory > 0`) or `PooledStore` HTTP serving
The served numbers (2,274 MB single restore; 18,177.5 -> 4,306.7 MB, TTFT −29.0%/−13.5% on 27B; 7,944.9 -> 1,981.1 MB on Flash-Next) are at 0c04b1e2, which is behind this head by both the v4 packed-record work and the three review-driven fixes. This head's only fresh numbers are a microbenchmark of Staged::poll().
Impact. The charter asks performance PRs to bring benchmarks showing an actual speedup on a served workload. The claim being defended at this head is the coalescing behaviour on a served restore pattern, and the honest disclosure shows it has not been re-measured since the record format changed to v4 packed underneath it — precisely the format whose window planning and no-slot-allocation path this PR rewrote. The reviewer's outstanding ask (live serving validation with --lossless-kv-compression cpu|gpu) is the same gap from the correctness side: v4 packed coalescing is unit-tested only.
Concrete fix. One flare run A/B at ba1c73fd vs current main repeating the 27B warm-plus-8-branches procedure, including one --lossless-kv-compression gpu run so the packed path is exercised live, reporting NVMe read bytes and median TTFT. Given the reviewer request, this is the last substantive blocker, not a documentation nicety.
Verified sound (reported so the above is not read as a general defect list)
- Aligned window planning is correct.
plan_windows(..., true)keepsWindowPlan.offset(ticket-order cumulative page index, used asdst_offset) separate fromcursor(file-relativefirst), sorecord.pages[plan.offset..plan.offset + plan.count]inbuild_upload_job(coalesce.rs:1186-1191, 1200-1204) stays correct across multi-segment chains and thepages == 0row-only plan. - Row reply routing is correct.
ReadRowcarries no window id;SharedSegment.pending_row_readsis a per-segment FIFOVecDeque(coalesce.rs:116, 500, 1090) matching the disk thread's per-reader FIFO reply order (selene/src/disk.rs:478-485, single-threaded run loop). - Upload references cannot leak.
complete_finished_fetchesremoves a record only whenactive.is_empty()(coalesce.rs:1333-1337), anddetach_unwinding_windowsrefuses to detach windows withupload_submitted && !upload_done(coalesce.rs:782-786), so a sharedSlabPoolslot orArc<Vec<u8>>packed buffer cannot be released under an in-flightCopierdecode or GPU upload. - Segment removal cannot race a reply.
remove_shared_segmentis gated ondisk_settled()=Closed && disk_outstanding == 0(coalesce.rs:130-133, 1360-1369), which is the same condition the docs promise for the last user waiting on the disk close beforeFetched. - Failure blast radius matches the docs. Private child segments and transient follower upload errors fail only that restore (
coalesce.rs:557-565); shared open/read/packed-content errors fail every attached restore viafail_segment_users/fail_window(coalesce.rs:436-476, 531-536). The corrupt-shared-ancestor test asserts all four followers getrecord_readerrors withdisk_opens == 1and a fully freed pool (coalesce/tests.rs:1093-1179), andDiskStore::applydrops only the corrupt endpoint's row onis_record_read()(disk_store.rs:3255-3262). - Tight-pool holdback is deadlock-free and self-releasing.
reachable_free = free + staged_slots + outbound_slotsand thebest_demand >= max_reachable_shared_demandrule (coalesce.rs:698-745) recompute from live records every pass, so a cancelled or finished peer drops itspeer_demandto zero and the held-back plan proceeds;tight_pool_wait_never_deadlocks_without_releasable_staged_slotscovers the no-releasable-slots case. Packed plans need zero slots (coalesce.rs:724-728), so they are never held back by this rule. inbound_ratespan widened, not shrunk — and the coalesced-follower guard is correctly ordered.started = Instant::now()is taken before the transport fetch andlogical_bytes = layout.record_bytes(chain.pages)is end-to-end (disk_store.rs:3422-3453), observed once inapply(disk_store.rs:3245-3250). Forrode_preexistingrestores the observation is skipped when the follower's throughput is not below the current estimate (disk_store.rs:3244-3247), so a fast follower cannot inflate the rate while slowdowns and leader-failure bursts still push it down.StoreStats.bytes_instays per-fetch payload bytes (disk_store.rs:3240) with no double count: each follower addswin.read_bytesonce inreap_completed_uploads(coalesce.rs:757-763), matchingdocs/prefix-cache-offload.md:1613-1615.- No public contract changed.
TransportEventstill has fiveJobId-carrying variants (disk_store.rs:89-109),FetchSegmentis unchanged (disk_store.rs:171-177),plan_windowsis private, and no record-format, wire-protocol, or core-export surface moved. The out-of-bandInboundWindowSampleplumbing that earlier revisions carried is gone. - Close/leak accounting is separated.
Staged::closereports abandoned transport jobs apart from leaked shared staging entries and only forgets packed buffers still upload-referenced (disk_store.rs:1983-2021,coalesce.rs:313-319). - Cross-platform: the coalescing code is plain
HashMap/VecDeque/Arcover the existingDiskTransportabstraction, with noO_DIRECT- orio_uring-specific logic and nocfg(unix)additions, so there is no Unix/Windows parity regression in this diff.
Open questions / could not be found
- No re-review at
ba1c73fd. The only verdict on record for this head is CHANGES_REQUESTED (2026-11-29 02:14); its three blockers are fixed in source, but whether the reviewer accepts the fixes, and the outstanding live--lossless-kv-compressionvalidation, is unknown. Design-Signed-Off-Bytrailer absent.ba1c73fdis a single commit dated 2026-11-26, before the 2026-11-29 sign-off, so the trailer required bydocs/design-review.md(not opened) (Design-Signed-Off-By: <reviewer>; design-review=<4 hex>) and the maintainer-request recordAGENTS.md(not opened) asks for are still owed on the merge commit. I did not re-open those files this pass to quote them.- Whether the composite's
disk_started-scoped sample was documented differently before this PR — I read only the current sentence, so F1's "the doc is new, the behaviour is old" framing is verified for the sentence, not for prior doc text. - No test run, live or release-mode, was performed for this review. Every conclusion above is from source reading at the PR head; the PR's own
cargo/pytestresults are taken from its description. - Tool limits: review bodies behind the
autobot.eidonix.comURLs were not fetched, so per-item wording comes from the on-GitHub text;pr_difftruncates on a diff this size, sodisk_store.rs,coalesce.rsand its tests were read at head rather than through the diff.