#1 [high] Research summary
Correctness / contracts / system-consequences lens on #674 at head 831c47c7. Tooling note: pr_diff fails at this head (error: Could not read c513e46a… bad revision), so everything below is verified in tree at the head, quoted exactly, and framed as head-state behaviour rather than as a before/after diff. No blocker was found in the areas I opened; findings are one Major system-level hazard on the manager hot path, one Major telemetry-accuracy defect, one Major-ish write-path amplification note, and four minors.
1. Major — waiter-storm scan re-derives a full sorted tree snapshot on every pass, on the single store thread. selene-manager/src/store.rs:1610-1666 scans a bounded prefix (WRITEBACK_WAKE_SCAN = 32, :43) and re-arms itself (self.writeback_wake_remaining > 0 → self.notify_wakeup(), :1657-1659, and pump re-enters at :5049-5053), so a 1024-waiter queue is swept in up to 32 passes per wake; every wake_writeback_waiters(false) resets writeback_wake_remaining = self.writeback_waiters.len() (:1606), and it is called from disk-completion, settle_put, cancel, connection_closed, WindowReleased (:4377, :4423, :3972, :4023, :5761). Each pass allocates a fresh let mut spans = None; (:1622), so can_satisfy_writeback_waiter's spans.get_or_insert_with(|| self.clean_arena_victims()…) (:1561-1566) re-runs clean_arena_victims (:1531-1549): it iterates every namespace's whole tree and victims.sort_by_key(|&(id, key, ..)| (self.namespaces[&id].tree[&key].accessed(), key.consumed_tokens)) — O(n log n) with a tree lookup per comparison — for each of the 32 passes, while a "satisfiable" verdict is only advisory (nothing is reserved; begin_put re-admits and may fail again, re-queuing the waiter). Impact: under the adversarial regime this PR targets (tight --memory, many blocked puts, frequent write completions) the store thread — which also serves every get and put — burns O(passes × n log n) per disk reply, and can churn wake→re-admit→re-wait for the same waiter. Fix: compute the victim span list once per sweep (hoist it out of scan_writeback_waiters_step, e.g. carry it in the store across passes of one epoch), and make a satisfiable verdict sticky by pinning/reserving the coalescible block for the waiter it was computed for before calling queue_put.
2. Major — Metrics::host_lookup_cost double-counts one decision, biasing the exact gauges this PR adds. In helios/src/server/runtime.rs:3379 the pooled candidate is recorded, then when the same endpoint has an affordable local copy the same missing_tokens and prefill_saved_seconds are recorded again at :3400-3404. With host_lookup_cost (helios/src/server/metrics.rs:538-563) doing self.host_cost_sums[index].fetch_add(value, …); buckets[bucket].fetch_add(1, …) for host_missing_tokens, host_transfer_ns and host_prefill_ns, one logical "prefill saved X seconds, cost-rejected" decision increments host_prefill_ns's sum and bucket twice, and the loop at :3356-3416 makes it per-candidate, not per-lookup (scheduler.record_host_lookup() at :3420 is per admitted request). Impact: flare_host_cache_prefill_saved_seconds / …transfer_seconds sums and histograms are inflated and their denominators inconsistent with lookups — directly undermining the PR's claim to "record prefill-saved seconds directly in Metrics::host_lookup_cost" for anyone watching restore economics. Fix: record once per candidate pair (move the :3400 call into the branch after the local comparison and skip the pooled record, or record only the candidate that is finally selected/rejected), and add a phase test asserting exactly one sample per candidate examined.
3. Major (perf, disclosed trade partly) — WritePacked stages every payload byte through one shared 1 MiB scratch, serialized on the disk thread. selene/src/disk.rs:1331-1376 (write_direct_slices) copies into self.scratch in cap = self.scratch.length (~1 MiB) chunks and issues one direct write per chunk; it is reached whenever a slice base address is not 4096-aligned (:1272-1309), which is the normal case for PackedPayload::Owned(Vec<Vec<u8>>) (u8 Vec alignment is 1) at :1394-1398/1408-1415. So a 200 MB record costs ~200 MB of extra memcpy plus 200 direct-write submissions, all on the single disk thread, bypassing the page cache (the last part is disclosed in the body). Measured throughput (1,054 MB/s) leaves headroom, so I do not call this a blocker, but it is memory amplification on the path the PR claims to have accelerated, and it also makes WriteRecord degrade to write_record_buffered (page-cache, non-direct) for unaligned partial windows (:864-868). Fix: allocate an aligned bounce buffer once per connection/record (or require aligned payload slabs at the API boundary) instead of restaging through the shared scratch, and say explicitly in the docs that partial unaligned windows remain buffered.
4. Minor — write_direct_slices silently assumes file offset 0. It takes Span { address, offset, length } but writes at file_offset starting at 0 (disk.rs:1335-1374), ignoring the span's offset; today's only callers pass whole_record (offset == 0, :848-855) or a fresh packed file (:1415). A future caller with a non-zero offset would silently overwrite the file head. Fix: assert span.offset == 0 (or pass the offset as the initial file_offset).
5. Minor — transfer_in_use is now a linear scan of both waiter queues on every put/get begin. selene-manager/src/store.rs:1351-1377 adds writeback_waiters.iter().any(...) and inflight_waiters.iter().any(...) (both bounded at 1024, :39-40) to a check that runs for every PutBegin/GetBegin. Under exactly the storm conditions in finding 1 this is up to ~2k comparisons per operation on the hot path. Fix: keep a HashSet<(u64, u64)> of queued (connection, transfer) ids maintained on push/remove.
6. Minor — TierStore::pending_pool_drain's default now contradicts its own new semantics. selene/src/store.rs:401-404 still defaults to self.stats().memory_records, i.e. "all DRAM records", while the PR's retention change means clean persisted_in_pool records no longer need handover. The shipped store overrides it correctly (selene/src/memory.rs:2776: slot_count() - free_slots() - clean_slots), so behaviour is fine, but any out-of-tree TierStore gets a shutdown drain that blocks on records that will never be handed over (selene/src/pool/store.rs:309-320 loop). Fix: state the override requirement in the trait doc, or default to 0 and have the memory store be explicit.
7. Minor — RestoreWait::started is never reset, so accumulated wait can leak across admission episodes. helios/src/server/runtime.rs:231-244: let started = *self.started.get_or_insert(now); … let budget = 0.5 * prefill_saved_seconds - transfer_seconds; and only self.retry_at = None is cleared (also at :3438); I found no site clearing started. A request that was deferred once and later re-enters this path charges the whole intervening time to waited, which can flip worth_restore(transfer_seconds + waited, …) to false and drop an otherwise profitable restore. Fix: clear started when retry_at is cleared (or key it to the admission episode the comment promises).
Areas I checked and found sound: (a) the per-level pool rate span is honest — pool_finished observes only page-bearing restores (selene/src/pool/store.rs:376-379) with restore.started taken before pool.fetch (:526-540), so the sample covers the end-to-end restore and row-only restores fall through to RowRestoreLatency (runtime.rs:3372-3378); POOL_LEVELS order matches rates() (selene/src/levels.rs:109-132 vs pool/store.rs:664) and the exporter iterates the same order (helios/src/server/metrics.rs:1416-1424, test :1990-2014). (b) RowRestoreLatency::observe uses the lower median with an explicit rationale (runtime.rs:316-321). (c) The clean_slots invariant is centrally maintained through update_clean_slots/refresh_handover with a full-scan assertion in debug/test builds (selene/src/memory.rs:951-1080), and the shutdown drain loop exits on pending_pool_drain() plus a deadline (pool/store.rs:309-321). (d) No protobuf schema change; the only wire addition is the internal rank-relay Kind::StoreInvalidated = 4, which the body discloses as requiring matched ranks. (e) post-rename disk invalidation propagates as PublishError::post_rename → Reply.invalidated → TransportEvent::StoreInvalidated (disk.rs:1201-1243, 1657-1717, 1756-1763), with tests at disk.rs:4510-4610 and disk_store.rs:9017-9125.
Claim accuracy: the body's own "Scope Summary" (+10,106 / -1,158 across 42 files) contradicts its Verification line ("re-verified on rebased HEAD (831c47c7)") — the head is larger than the quoted scope, so the scope table is stale/internally inconsistent and should be regenerated at the head. Consistent with the dossier, the headline A/B still predates #665/#663/#660, so charter #210's evidence half remains open for the performance claims even though the disclosure half is closed.
#2 [high] PR #674 correctness lens — findings, citations (head 831c47c7)
Lens: Correctness, Contracts & System-Level Consequences. Head 831c47c7; base main c513e46a.
TOOLING LIMIT: pr_diff fails at this head — "error: git: error: Could not read c513e46a79f3b6ac510235aaf09bcf055b841958 / fatal: bad revision" — so no before/after line-level diff was available; all findings are verified in-tree at head and stated as head-state behaviour.
F1 (Major, system-level / hot path): waiter-storm scan re-derives a full sorted tree snapshot on every pass, on the single store thread.
selene-manager/src/store.rs:43const WRITEBACK_WAKE_SCAN: usize = 32;(bounded prefix),:39-40MAX_WRITEBACK_WAITERS = MAX_INFLIGHT_WAITERS = 1024.store.rs:1610-1666fn scan_writeback_waiters_step:let scan_budget = len.min(WRITEBACK_WAKE_SCAN).min(self.writeback_wake_remaining);…:1622let mut spans = None;…:1634if self.can_satisfy_writeback_waiter(&self.writeback_waiters[idx], &mut spans)…:1657-1659if self.writeback_wake_remaining > 0 { self.notify_wakeup(); }.store.rs:1606self.writeback_wake_remaining = self.writeback_waiters.len();on everywake_writeback_waiters(false); callers at:4377(disk completion),:4423(settle_put),:3972(cancel),:4023(connection_closed),:5761(WindowReleased),:2207,:3474,:4103,:4152,:4583,:4877,:5050.store.rs:1551-1571can_satisfy_writeback_waiter→spans.get_or_insert_with(|| self.clean_arena_victims()…);:1531-1549clean_arena_victimsiterates all namespaces'tree.ordered()andvictims.sort_by_key(|&(id, key, ..)| (self.namespaces[&id].tree[&key].accessed(), key.consumed_tokens))— O(n log n) + per-comparison tree lookup, per pass.pumpre-enters:store.rs:5049-5053if self.window_released.swap(false,…) { self.wake_writeback_waiters(false); } else if self.writeback_wake_remaining > 0 { self.scan_writeback_waiters_step(); }and:5067-5072re-armsnotify_wakeup.- Satisfiability is advisory only: nothing is reserved;
begin_putre-admits (store.rs:1749+, budget path:2018-2032/:2061-2077both callwait_for_writebackagain), so the same waiter can churn wake→re-admit→re-wait. - Fix: hoist the victim span list to one computation per sweep/epoch; pin or reserve the coalescible block before
queue_putso a "satisfiable" verdict is sticky.
F2 (Major, telemetry accuracy): Metrics::host_lookup_cost double-counts one decision; gauges inflated; denominator inconsistent with lookups.
helios/src/server/runtime.rs:3379metrics.host_lookup_cost(missing_tokens, transfer_seconds, prefill_saved_seconds);then samemissing_tokens/prefill_saved_secondsrecorded again at:3400-3404for the local alternative.helios/src/server/metrics.rs:538-563: for the three series it doesself.host_cost_sums[index].fetch_add(value, Ordering::Relaxed); … buckets[bucket].fetch_add(1, Ordering::Relaxed);(host_missing_tokens / host_transfer_ns / host_prefill_ns).- Lookup counter is per admitted request:
runtime.rs:3420scheduler.record_host_lookup();(and:3346? no —:3446on the capacity path), while the loop:3356-3416is per candidate. - Impact:
flare_host_cache_prefill_saved_seconds/transfer_secondssums+histograms inflated ~2x on the row-only/pooled-then-local path; bias scales with number of candidates examined. Undermines the PR's claim "record prefill-saved seconds directly inMetrics::host_lookup_cost". - Fix: record once per candidate (defer the pooled record until after the local comparison), add a phase test asserting one sample per candidate.
F3 (Major perf, partly disclosed): WritePacked restages every payload byte through a single shared ~1 MiB scratch on the disk thread; unaligned partial windows fall back to buffered writes.
selene/src/disk.rs:1331-1376write_direct_slices:let cap = self.scratch.length;…self.scratch.as_mut_slice()[staged..staged + take].copy_from_slice(&remaining[..take]);… oneself.ring.transfer(file, &[span], true)per cap-sized chunk;cap= 1 MiB-ish.- Reached because
PackedPayload::Owned(Vec<Vec<u8>>)(u8 vec, align 1) →:1394-1398,:1408-1415always takes the direct path;:1272-1309write_record_directhandles only aligned base + block-rounded tail. disk.rs:864-868comment "Partial unaligned streaming windows cannot be block-rounded without overwriting an adjacent window in the temporary file." →write_record_buffered(:1312-1325, page-cachewrite_all_at), i.e. non-direct.- Impact: ~1 extra memcpy of the whole record per write, serialized on the disk thread; and the documented "all writes use O_DIRECT" claim does not hold for unaligned partial windows. Throughput measured at 1,054 MB/s leaves headroom → not a blocker.
- Fix: per-record aligned bounce buffer (or aligned span API), and document the buffered fallback.
F4 (Minor): write_direct_slices ignores the span offset — writes from file_offset = 0 (disk.rs:1335-1374); callers today pass offset 0 (:848-855 whole_record / :1415 fresh packed file). Fix: assert offset == 0 or seed file_offset from it.
F5 (Minor): transfer_in_use now linear-scans both waiter deques on every PutBegin/GetBegin — selene-manager/src/store.rs:1363-1368: || self.writeback_waiters.iter().any(|waiter| { waiter.pending.connection == connection && waiter.pending.transfer == transfer }) || self.inflight_waiters.iter().any(|pending| …); up to ~2k comparisons per op at the 1024 caps (:39-40). Fix: maintained HashSet<(u64,u64)>.
F6 (Minor, contract): TierStore::pending_pool_drain default contradicts new retention semantics — selene/src/store.rs:401-404 fn pending_pool_drain(&self) -> usize { self.stats().memory_records }; correct override is selene/src/memory.rs:2776 slot_count() - free_slots() - clean_slots. Shipped store is fine; out-of-tree impls block shutdown drain (selene/src/pool/store.rs:309-321) on records that will never be handed over. Fix: doc the override requirement or default to 0.
F7 (Minor): RestoreWait::started never reset → accumulated wait leaks across admission episodes. helios/src/server/runtime.rs:231-244: let started = *self.started.get_or_insert(now); … let budget = 0.5 * prefill_saved_seconds - transfer_seconds; … self.retry_at = None; (only retry_at cleared; also :3438). Can flip worth_restore(transfer_seconds + waited, …) false and drop a profitable restore. Fix: clear started with retry_at.
SOUND AREAS (verified, do not invent issues here):
- Per-level pool rate span is honest:
selene/src/pool/store.rs:376-379observes only when!restore.ticket.pages.is_empty();startedcaptured at:526beforeself.pool.fetch(:528-537). Row-only →RowRestoreLatency(runtime.rs:3372-3378). POOL_LEVELSorder ==Ranking::rates()order:selene/src/levels.rs:109-114&:130-132; exporterhelios/src/server/metrics.rs:1416-1424; metrics tests:1990-2014,:1849; selene testselene/src/pool/store/tests.rs:1676-1700; stats plumbed atselene/src/pool/store.rs:664+selene/src/store.rs:256.RowRestoreLatency::observelower median with rationalehelios/src/server/runtime.rs:316-321.clean_slotsinvariant centrally maintained:selene/src/memory.rs:951-957update_clean_slots,:972-1014refresh_handover/refresh_ancestors/refresh_same_page_descendants,:1054-1080assert (debug/test full scan),:1170-1200retired/mark_persisted_in_pool.- Drain non-blocking:
selene/src/pool/store.rs:309-321loops onpending_pool_drain() || outbound_in_flight || cascade.in_progress()with deadline andpool.ready()bail. - Disk invalidation propagation:
selene/src/disk.rs:1201-1243publish (post_rename removes path),:1657-1717PublishError/reply_publish,:1756-1763outbound →TransportEvent::StoreInvalidated;:882-897WritePacked path; tests:4290(direct io + truncate),:4510-4610(dir-sync invalidation),selene/src/disk_store.rs:9017-9125. - RowRestoreLatency/spill wakeups tests:
selene-manager/src/store.rs:11542-11617,:11868-11995(WRITEBACK_WAKE_SCAN+1 cases),:11125-11232. - No protobuf schema change; only internal wire addition
Kind::StoreInvalidated = 4(selene/src/shard.rs, consumedselene/src/composite.rs:322, 1531).
CLAIM ACCURACY: body "Scope Summary" says +10,106 / -1,158 across 42 files while Verification says re-verified at 831c47c7; dossier records head as +11,418/-1,237 → stale/self-contradictory scope table. Charter #210 evidence half still open (headline A/B predates #665/#663/#660).