← Back to Pull requests

(test) usage_store: pace the concurrent-compaction race off progress, not the clock (issue #1492) #1500

Closed
unknown closed this pull request without merging on Sep 06, 2026 15:58 UTC
View on GitHub
unknown unknown commented on Sep 06, 2026 12:12 UTC
Author

Closes #1492.

Two review rounds, both acted on. [Round 1][r1] falsified this PR's original detection claim —

it had measured one mutant and generalised; the symmetric mutant showed a real regression. The

repair changed in response and the branch was rewritten so the false claim does not reach main

through squash-merge. [Round 2][r2] returned 0 critical / 2 warnings / 3 suggestions and

re-derived every published number rather than reading it. All five are dispositioned below.

[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:

---- usage_store::tests::append_never_loses_a_sample_to_a_concurrent_compaction stdout ----

thread '<unnamed>' (203546238) panicked at src/usage_store.rs:1565:79:
called `Result::unwrap()` on an `Err` value: UsageStoreBusy

thread 'usage_store::tests::append_never_loses_a_sample_to_a_concurrent_compaction' (203546160) panicked at src/usage_store.rs:1579:25:
called `Result::unwrap()` on an `Err` value: Any { .. }

At b38935d, src/usage_store.rs:1565 is the appender thread's append_sample(..).unwrap() and
:1579 is appender.join().unwrap().

The verdict does not rest on the absence of an assert_eq! short count. That absence is
structural, 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, and join().unwrap()
re-panics — so the assertion is never evaluated. It could not have fired. The argument is instead:

1. StoreLock::acquire is fail-closed and returns having written nothing — it is
append_sample's first statement and ?-propagates, so the panic is at the acquire, before any
file I/O. A UsageStoreBusy append 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_compaction in src/usage_store.rs now paces the
compactor off the appender's progress:

  • A capacity-0 sync_channel rendezvous fixes one compaction pass per append, so each writer queues

  • behind at most one of the other's critical sections rather than a whole run of them.
  • The appender holds alternate appends until the released pass is demonstrably underway, so the

  • 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::acquire with a per-acquire retry counter (excluding
    the 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 = 50 and both unwraps are untouched, so a
    fail-closed refusal from either writer still fails the test loudly. No #[ignore], no appender retry
    loop, no --test-threads pin, no widened tolerance. Bytes 1–1557 of the file are byte-identical to
    b38935d
    , so both production StoreLock::acquire call sites and every other production symbol are
    untouched 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:

    cargo test --no-run
    BIN=$(ls -t target/debug/deps/sessiometer-* | grep -v '\.d$' | head -1)
    mkdir -p .tmp/measure && rm -f .tmp/measure/*.log
    for i in $(seq 1 30); do
      for j in 1 2 3 4; do "$BIN" > ".tmp/measure/run-$i-$j.log" 2>&1 & done
      wait
    done
    ls .tmp/measure/*.log | wc -l                                   # observed suites
    grep -L '^test result: ok' .tmp/measure/*.log                   # the failing ones
    

    | 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+rename atomic writes — which is why it does not reproduce on a single suite (0 in 60), nor
    on 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 spurious NotFound from 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 now breaks 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 the rust filter, so test, msrv and deny are owed; all were re-run
    locally against the committed artifact after every change above. cargo fmt --all --check;
    cargo clippy --all-targets --all-features -- -D warnings (sources touched first — the run reports
    Checking 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 build and cargo +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

  • #1501 — paths::tests::terminal_env_a_shell_local_path_entry_is_not_consulted_when_the_harvest_succeeds

  • failed 6 times across 480 observed suite runs on both trees, with an unrelated signature (a launchd
    re-exec child asserting claude PATH precedence).
  • #1502** — STORE_LOCK_MAX_WAIT and STORE_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.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: alexey-pelykh Review duration: 225m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%