Notes tests: wait for the room's answer, not a quiet period #31

Closed
kayg wants to merge 0 commits from issue/31-fuzz-converge into dev
Owner

Closes #31

Root cause (plain words)

It was the test, not the room. Nothing was lost or dropped.

A room writes each incoming update to history (with an fsync) before passing it on to the other clients. In CI the disk was busy (the web job ran Playwright beside it), so the room built up a backlog of updates waiting on fsync. The test's settle() stopped listening after ~20 ms without messages, which was shorter than that backlog. The final notes.get went through the room's queue behind the backlog, so it saw everything, while the clients had already stopped listening. That's why the failing client had its own late tokens but none of the other clients' last two rounds.

Proof

  • With a simulated slow disk (a temporary 30 ms sleep per history commit, not committed), the old test failed on its first run with the same shape as CI.
  • With the fix and the same slow disk: 200/200 on 4 loaded cores.

Fix

settle() now waits on an explicit answer, never on a quiet period:

  • Client::sync() sends sync step 1 and waits for the server's step 2. The room handles one client's messages in order, so that answer proves everything the client sent is applied, and it carries everything the server has.
  • settle_all() does two passes over all clients, so every client matches the server. The fuzz test and the delete-vs-typing test use it.
  • A 30 s limit only turns a hang into a clear failure ("the server never answered" / "the server dropped this client").

Results

  • Fuzz test: 200/200 runs, 8 in parallel on 4 cores with CPU burners (real code).
  • Whole notes suite: 30/30 under the same load. It now runs in ~1 s instead of ~12 s (no sleeps).
  • fmt, clippy -D warnings, full workspace tests green.

Note for later (not changed here)

Collaborators see each other's typing only after that fsync. On a slow disk, that's the disk's latency per update. y-websocket servers pass updates on first and persist after. We could do the same: fan out at once, keep saving the file only after history is durable, and keep API answers waiting for durability. That's worth its own issue, since it touches durability.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T

Closes #31 ## Root cause (plain words) It was the test, not the room. Nothing was lost or dropped. A room writes each incoming update to history (with an fsync) **before** passing it on to the other clients. In CI the disk was busy (the web job ran Playwright beside it), so the room built up a backlog of updates waiting on fsync. The test's `settle()` stopped listening after ~20 ms without messages, which was shorter than that backlog. The final `notes.get` went through the room's queue **behind** the backlog, so it saw everything, while the clients had already stopped listening. That's why the failing client had its own late tokens but none of the other clients' last two rounds. ## Proof - With a simulated slow disk (a temporary 30 ms sleep per history commit, not committed), the old test failed on its first run with the same shape as CI. - With the fix and the same slow disk: 200/200 on 4 loaded cores. ## Fix `settle()` now waits on an explicit answer, never on a quiet period: - `Client::sync()` sends sync step 1 and waits for the server's step 2. The room handles one client's messages in order, so that answer proves everything the client sent is applied, and it carries everything the server has. - `settle_all()` does two passes over all clients, so every client matches the server. The fuzz test and the delete-vs-typing test use it. - A 30 s limit only turns a hang into a clear failure ("the server never answered" / "the server dropped this client"). ## Results - Fuzz test: 200/200 runs, 8 in parallel on 4 cores with CPU burners (real code). - Whole notes suite: 30/30 under the same load. It now runs in ~1 s instead of ~12 s (no sleeps). - `fmt`, `clippy -D warnings`, full workspace tests green. ## Note for later (not changed here) Collaborators see each other's typing only after that fsync. On a slow disk, that's the disk's latency per update. y-websocket servers pass updates on first and persist after. We could do the same: fan out at once, keep saving the file only after history is durable, and keep API answers waiting for durability. That's worth its own issue, since it touches durability. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Notes tests: wait for the room's answer, never for a quiet period
All checks were successful
CI / rust (pull_request) Successful in 27s
0e7c2f8333
The fuzz test failed once in CI ("client and server differ"): a client
lacked the other clients' last two rounds. Nothing was lost. A room
writes each update to history (fsync) before passing it on, and on a busy
disk that backlog outlasted the test's settle(), which gave up after
~20 ms without messages. The final notes.get queued behind the backlog
and saw everything; the clients had stopped listening.

settle() is now a round trip through the sync protocol: send sync step 1
and wait for the server's step 2. The room handles a client's messages in
order, so the answer proves everything the client sent is applied and
carries everything the server has. settle_all() does two passes over all
clients so everyone matches the server. A 30 s limit only turns a hang
into a clear failure.

Reproduced with a simulated slow disk (30 ms per history commit): the old
test failed every time; the new one passed 200/200 on 4 loaded cores.
Without the simulation: 200/200 fuzz runs and 30/30 full notes suites
under load. The notes suite also drops from ~12 s to ~1 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Author
Owner

Reviewed by Claude: root cause is test-only (settle() relied on 20 ms of silence while room fan-out waited on fsync under CI disk load). Settling now waits on an explicit sync step 2 answer. 200/200 under simulated slow disk. Merging.

Reviewed by Claude: root cause is test-only (settle() relied on 20 ms of silence while room fan-out waited on fsync under CI disk load). Settling now waits on an explicit sync step 2 answer. 200/200 under simulated slow disk. Merging.
Author
Owner

Closing: this branch is already fully contained in dev (it landed through a merge train). Branch cleanup, 2026-10-15.

Closing: this branch is already fully contained in `dev` (it landed through a merge train). Branch cleanup, 2026-10-15.
kayg closed this pull request 2026-10-15 08:35:39 +00:00
All checks were successful
CI / rust (pull_request) Successful in 27s

Pull request closed

Sign in to join this conversation.
No reviewers
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!31
No description provided.