Skip to content

Commit 2b20af4

Browse files
alex-poorclaude
andcommitted
Write up the test that asserted its own mistake
Three assertions in a row assumed one counter could bound another. The reason they could not is worth stating once: every counter in this replicator counts events, not things — received per store, live per p2panda increment, sent per topic. Fine for "is anything happening", useless for "how many". The fix asks the store instead. And it matters beyond one test: the CI added this morning runs diaswarm-net, and a 50% flake there teaches people to re-run rather than read. It passed its first two CI runs by luck. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent cd1b5b1 commit 2b20af4

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

‎docs/migration.md‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,3 +2716,46 @@ adb before they could be collected. Left unattributed rather than guessed at.
27162716
**What this still does not measure:** anything overnight, anything in doze,
27172717
anything off-LAN, and the tail. Twelve minutes of a plugged-in phone on wifi is
27182718
the easiest case there is.
2719+
2720+
### 🐛 A test was asserting the mistake it was written to catch
2721+
2722+
Found while extracting `share::carry_share` for the desktop peer
2723+
([D29](decisions.md)). `two_process.rs` had:
2724+
2725+
```rust
2726+
assert!(got <= sent, "the follower counted {got} pushed arrivals from a
2727+
publisher that pushed {sent}")
2728+
```
2729+
2730+
added deliberately to catch a transport diagnostic that over-reports — the
2731+
defect four versions of the live counter had. **It is not an invariant.** `sent`
2732+
is what `broadcast` returned, which is the number of *topics* published on;
2733+
`got` is p2panda's `received_live_operations`, measured at one increment per
2734+
event on one build and two on another. Neither counts operations, so neither
2735+
bounds the other. It failed about **one run in two**, only when the whole file
2736+
ran, which reads exactly like load flakiness — and it was already there before
2737+
any of today's work.
2738+
2739+
**Two further attempts failed for the same underlying reason**, which is the
2740+
part worth keeping:
2741+
2742+
| attempt | why it was wrong |
2743+
|---|---|
2744+
| `live <= sent` | different units, as above |
2745+
| `received <= ops`, ops read at first push | compared a late follower reading against an early publisher one |
2746+
| `received <= ops`, both late | `received` counts *store events* and counts one operation twice if it arrives on two sessions |
2747+
2748+
> **Every counter in this replicator counts events, not things.** `received`
2749+
> per store, `live` per p2panda increment, `sent` per topic. That is fine for
2750+
> "is anything happening" and useless for "how many", and three assertions in a
2751+
> row were built on the assumption that one of them could bound another.
2752+
2753+
**The fix asks the store.** `keyspeer` now reports `segments` via
2754+
`get_log_size`, and the ceiling is that a follower cannot *hold* more operations
2755+
of a subject than its publisher created — distinct things on both sides. **3/3
2756+
stable**, against 1-in-2 before.
2757+
2758+
⚠️ **And it would have started failing on `main`.** The crates CI added earlier
2759+
the same day runs `diaswarm-net`; a 50% flake there is worse than no test,
2760+
because it teaches everyone to re-run rather than read. It passed its first two
2761+
CI runs by luck.

0 commit comments

Comments
 (0)