Flaky: auth reliability_review counter_concurrent_mutations_drift_and_restart (count off by ~137 under load) #1119

Closed
opened 2026-11-14 00:39:29 +00:00 by kayg · 2 comments
Owner

Found while unblocking #894 (which has no crates/auth changes).

First run of cargo test --workspace --locked -j4 --no-fail-fast on #894 76e79ea8a (dev-01, other slot jobs running) failed once:

crates/auth/tests/reliability_review.rs:282:5
assertion `left == right` failed
  left: 16577
 right: 16440

--repeat by hand, 10 runs each of cargo test -p calternal-auth --test reliability_review counter_concurrent_mutations_drift_and_restart: #894 10/10 passed, dev 796d80cba 10/10 passed. So it does not block (flaky rule), but the counter can drift from the recount under concurrent mutations plus restart when the host is busy. Needs a look at what the test's expected count races with.

Found while unblocking #894 (which has no `crates/auth` changes). First run of `cargo test --workspace --locked -j4 --no-fail-fast` on #894 `76e79ea8a` (dev-01, other slot jobs running) failed once: ``` crates/auth/tests/reliability_review.rs:282:5 assertion `left == right` failed left: 16577 right: 16440 ``` `--repeat` by hand, 10 runs each of `cargo test -p calternal-auth --test reliability_review counter_concurrent_mutations_drift_and_restart`: #894 10/10 passed, dev `796d80cba` 10/10 passed. So it does not block (flaky rule), but the counter can drift from the recount under concurrent mutations plus restart when the host is busy. Needs a look at what the test's expected count races with.
Author
Owner

Cause and fix (stability lane, 15 Nov)

Cause (product bug in fsio::usage). Usage::recount walks the Home without a lock. A directory read is not a snapshot: when a file is renamed while the walk is in that folder, the walk can list both names and publish the file twice (from and to, 137 bytes each, exactly the left 16577 / right 16440 of this issue). The rename_safely that follows calls usage::moved, which took from out of the table but added to's size without taking out the size to already had, so the file stayed counted twice until the next recount (60 s later). Overcount of one 137-byte file = this failure (and #1021, same test, same +137).

Fix (PR below). moved now uses the size that files.insert returns for the destination and takes it out of the total. A move onto an untracked name is unchanged; no new lock, no extra IO, no extra walk.

Red test (deterministic, no timing). a_move_onto_a_name_the_walk_already_counted_counts_the_file_once publishes both names (what the half-seen rename leaves), then rename_safely. Commit 2eaf7a4f7 (test only), dev-02, cargo test -p calternal-fsio usage: FAILS, left: 274, right: 137. Commit 97b5d7e80 (with the fix): passes.

Gates (dev-02, one ~/bin/slot job): cargo test -j4 --locked -p calternal-fsio 54 passed; cargo test -j4 --locked -p calternal-auth all green (incl. counter_concurrent_mutations_drift_and_restart).

Not reproduced by brute force: 240 runs of the auth test, 6 at a time, on idle dev-02: 240 passed. The race is a rare readdir interleaving, which is why the red test sets the half-seen state directly.

Perf statement: the change is in moved() (rename path of fsio), one HashMap::insert that already ran now has its return value used. No change on typing, list scroll or note open.

## Cause and fix (stability lane, 15 Nov) **Cause (product bug in `fsio::usage`).** `Usage::recount` walks the Home without a lock. A directory read is not a snapshot: when a file is renamed while the walk is in that folder, the walk can list both names and publish the file twice (`from` and `to`, 137 bytes each, exactly the `left 16577 / right 16440` of this issue). The `rename_safely` that follows calls `usage::moved`, which took `from` out of the table but **added** `to`'s size without taking out the size `to` already had, so the file stayed counted twice until the next recount (60 s later). Overcount of one 137-byte file = this failure (and #1021, same test, same +137). **Fix (PR below).** `moved` now uses the size that `files.insert` returns for the destination and takes it out of the total. A move onto an untracked name is unchanged; no new lock, no extra IO, no extra walk. **Red test (deterministic, no timing).** `a_move_onto_a_name_the_walk_already_counted_counts_the_file_once` publishes both names (what the half-seen rename leaves), then `rename_safely`. Commit `2eaf7a4f7` (test only), dev-02, `cargo test -p calternal-fsio usage`: **FAILS, `left: 274, right: 137`**. Commit `97b5d7e80` (with the fix): passes. **Gates** (dev-02, one `~/bin/slot` job): `cargo test -j4 --locked -p calternal-fsio` 54 passed; `cargo test -j4 --locked -p calternal-auth` all green (incl. `counter_concurrent_mutations_drift_and_restart`). **Not reproduced by brute force:** 240 runs of the auth test, 6 at a time, on idle dev-02: 240 passed. The race is a rare readdir interleaving, which is why the red test sets the half-seen state directly. **Perf statement:** the change is in `moved()` (rename path of `fsio`), one `HashMap::insert` that already ran now has its return value used. No change on typing, list scroll or note open.
Author
Owner

Fixed by #1164, now on dev. Closing.

Fixed by #1164, now on dev. Closing.
kayg closed this issue 2026-11-16 00:53:17 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal#1119
No description provided.