(test) usage_store: pace the concurrent-compaction race off progress, not the clock (issue #1492) #1500
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1500"
general
weight: 0.35
alexey-pelykh
Closes #1492.
[r1]: https://github.com/alexey-pelykh/sessiometer/pull/1500#pullrequestreview-5125329634
[r2]: https://github.com/alexey-pelykh/sessiometer/pull/1500#pullrequestreview-5125625250
Verdict: harness artifact, not a real race
Reproduced deliberately at four concurrent copies of the full suite: 16 failures in 120 observed
suite runs, and all 16 carried one signature. Verbatim from a failing run on the pre-change tree:
At
b38935d,src/usage_store.rs:1565is the appender thread'sappend_sample(..).unwrap()and:1579isappender.join().unwrap().The verdict does not rest on the absence of an
assert_eq!short count. That absence isstructural, not evidential, and this PR's first revision wrongly offered it as evidence: when the
appender panics,
is_finished()goes true, the compaction loop exits, andjoin().unwrap()re-panics — so the assertion is never evaluated. It could not have fired. The argument is instead:
1.
StoreLock::acquireis fail-closed and returns having written nothing — it isappend_sample's first statement and?-propagates, so the panic is at the acquire, before anyfile I/O. A
UsageStoreBusyappend is a refused write, not a lost one.2. The daemon cannot reach this: it compacts at most hourly, calling the two writers sequentially on
one poll loop, never in a busy loop.
3. Positively: the repaired test does reach its assertion, does go RED when either guard is
removed, and stays green across 120 loaded suite runs (below).
Repair
append_never_loses_a_sample_to_a_concurrent_compactioninsrc/usage_store.rsnow paces thecompactor off the appender's progress:
sync_channelrendezvous fixes one compaction pass per append, so each writer queuesbehind at most one of the other's critical sections rather than a whole run of them.
append is issued inside the rewrite's read-modify-write rather than merely near it.
Both arms of that wait are events — an unavailable lock (probed with a zero budget, so it never
blocks) or a counted completion — so there is no interval to tune and no arm that can hang.
That is a structural bound on what is waited for; the margin it leaves is finite and load-dependent
rather than unbounded. Instrumenting
StoreLock::acquirewith a per-acquire retry counter (excludingthe zero-budget probe, which "exhausts" by construction), the worst single contended acquire consumed
1 of the 100-retry budget unloaded, 7 alongside three concurrent suites, 31 alongside seven —
growing with load, never exhausted.
Nothing is weakened: the
assert_eq!,N = 50and bothunwraps are untouched, so afail-closed refusal from either writer still fails the test loudly. No
#[ignore], no appender retryloop, no
--test-threadspin, no widened tolerance. Bytes 1–1557 of the file are byte-identical tob38935d, so both productionStoreLock::acquirecall sites and every other production symbol areuntouched by construction rather than by inspection.
Detection
Alternating the append timing is load-bearing, not decoration — neither timing alone covers both
guards. Measured 40 runs per cell against builds with one guard removed in turn (the pre-#188 race,
from each side), on the exact committed artifact:
| guard removed from | early only | late only | alternating (this PR) | sleep-paced (pre-change) |
|---|---|---|---|---|
|
compact_and_roll| 40/40 | 0/40 | 40/40 | 40/40 ||
append_sample| 27/40 | 40/40 | 40/40 | 40/40 |An early-only append wins the post-rendezvous race by microseconds and never enters the rewrite
window; a late-only append waits out a compactor that does not lock, so it never overlaps either.
This PR's first revision was the early only column, and its 27/40 is the regression round 1 caught.
The table is kept in-band in the test's own comment, so it travels with the code.
Detection is preserved, not traded: the same 40/40 on both guards as the sleep-paced predecessor,
without its failure rate. Unmutated, the committed artifact is 0/40 isolated and 0/120 under load.
The price is runtime: ~1.6 s isolated against the predecessor's ~0.24 s, because an appender that
waits for a pass to be underway then queues behind it. Suite wall time is unchanged (~5 s either
way), so it is not a CI cost — and the waiting is the exercise, which the code comment says in-band
so a later reader does not optimise it away.
Residual rate
Instrument — four concurrent full suites per iteration, all four observed:
| tree | observed suites | failures of this test |
|---|---|---|
| pre-change (
b38935d) | 120 | 16 (13.3%), all 16 the appender-busy signature || this PR | 120 | 0 |
The starvation needs concurrent filesystem pressure — each compaction pass does two
fsync+renameatomic writes — which is why it does not reproduce on a single suite (0 in 60), noron the test alone under CPU load (0 in 100), nor unloaded (0 in 100). That is why the original
observation looked unreproducible.
Review dispositions (round 2)
| # | Finding | Disposition |
|---|---|---|
| 🟡 1 | The liveness bound's stated magnitude was wrong by ~3 orders ("sub-millisecond critical section running 2 s"); true headroom ~3× | Fixed. Re-measured independently (1 / 7 / 31 of 100 retries at 0 / 3 / 7 concurrent suites, never exhausted) and the comment now states the measured margin instead of an absolute. The claim was inherited from the production doc comments at
:113/:121, which the measurement also falsifies — filed as #1502, out of scope here since both are byte-identical to base || 🟡 2 | The
let _ = tick_tx.send(())rationale was false, and the pacing turned it into a measured regression: a spuriousNotFoundfrom the detached appender in 28/30 fault-injected runs vs base's 1/30 | Fixed, and further than suggested. Reproduced independently (27/30 vs base 0/30). Rather than only correcting the rationale, the appender nowbreaks when the receiver is gone — that can only happen while the main thread unwinds, so nothing is lost. Re-measured 0/30, with detection re-verified 40/40 on both mutants afterwards || 🟢 3 | The rewrite dropped the one cost the first revision disclosed | Fixed. Re-derived (0.24 s → 1.59 s median, ≈6.6×; suite wall time unchanged) and restored to both the comment and the commit body, with the "don't optimise the waiting away" warning |
| 🟢 4 | The "settle any samples appended after the last concurrent compaction" comment is stale — the rendezvous orders the last append before the last in-loop pass | Fixed. The call is kept (idempotent) but now documented for what it actually is: a free idempotence check, settling nothing |
| 🟢 5 | The probe arm reads the very guard under test; were the lock a no-op it would degenerate to the late timing | Fixed. Named in-band, with the alternation identified as what covers it, so a future editor does not simplify to that branch alone |
Round 2 also independently reproduced the detection table by fetching this PR's deleted round-1
commit and measuring it directly — landing on exactly the published 27/40 — and re-derived the
residual rate at 14/120 → 0/120 against the claimed 16/120 → 0/120 (same signature, machine-dependent
rate).
Gates
src/puts this in therustfilter, sotest,msrvanddenyare owed; all were re-runlocally against the committed artifact after every change above.
cargo fmt --all --check;cargo clippy --all-targets --all-features -- -D warnings(sourcestouched first — the run reportsChecking sessiometer, so it linted rather than replaying a stale fingerprint);RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --document-private-items;cargo build --verbose;cargo test --verbose(2353 passed, 0 failed).msrv:cargo +1.87.0 buildandcargo +1.87.0 test(2353 passed, 0 failed).
deny: both halves —./scripts/check-no-security-framework.sh(70 packages checked) and
cargo deny check advisories sources licenses.Out of scope, filed separately
paths::tests::terminal_env_a_shell_local_path_entry_is_not_consulted_when_the_harvest_succeedsfailed 6 times across 480 observed suite runs on both trees, with an unrelated signature (a launchd
re-exec child asserting
claudePATH precedence).STORE_LOCK_MAX_WAITandSTORE_LOCK_RETRY's doc comments call the sections they guard"sub-millisecond"; measured ~620 ms under load. Both are byte-identical to base, so pre-existing.