swipe-rows: a stale list read can't flip a pin back or bring a deleted note back (#587) #591

Closed
kayg wants to merge 0 commits from issue/400-swipe-flake into dev
Owner

Fixes #587.

What was failing

swipe-rows.spec.ts failed about 1 in 10 on webkit-390 (Pin / Unpin, Delete, Trash Restore). I took traces of it on plain dev (webkit-390, --repeat-each 8: 4 failures) and it is three different things, one of them a real bug.

1. Real bug: a stale list read flips a pin back (Pin test) and brings a deleted note back (Delete test)

The server writes its note list a moment after it announces a change (the notes worker waits 50 ms, longer under load). The app re-reads the newest page 250 ms after every event, and that read can still show the note as it was:

  • Pin. In the trace, notes.pin answered, the file already said calternal-pinned: true (notes.peek), and the notes.list that followed still said "pinned": false. The app put it in the index, so the pin icon went away and the row said "Pin" again. The next tap on "Unpin" then sent {"pinned": true} (togglePin flips what it sees), so the note ended up pinned. Nothing corrects it: no later event follows.
  • Delete. After notes.delete, the notes.list that followed still listed the note, and the row came back (never corrected either). #448 already guards reads that began before the delete event; this one began after it.

Both are real for a person on a slow server, not only for the test.

Fix (apps/web/src/lib/notes.svelte.ts):

  • a pin this device asked for wins over a list read until the list agrees with it (or 15 s pass; a failed pin clears it);
  • a deletion wins over a list read for 15 s, not only over reads that began before it (a notes.created for the note, which is what Undo and Restore send, still lets it back at once).

Two new tests make every notes.list read stale and fail without the fix (checked on chromium-390 and webkit-390).

2. Test race: a swipe landed on the other row (Delete test, chromium and webkit)

The server lists a new note at once with "No text yet" and a rough time, then again with both right. The second list sorts the two notes the other way and the rows slide past each other (FLIP, 320 ms). The test had checked that nothing was animating, but the second list had not arrived yet; the swipe was then measured and touched while the rows crossed, and the finger landed on the other row (screencast of the failing trace: the open row is the one the test did not name). Now openList waits until every row has its final text and nothing moves, the row is measured and touched in one go (so the list can't move in between), and the swipe throws if another row is on top.

3. Not the app: the WebKit this runs on crashes (Trash test, Delete test)

The "Restore" click that timed out, a transform stuck at -210px, and a row count that never changed are all the page crashing: the crash event fires, and the traces stop. It happens right after a notes.deleted or notes.created journal entry, with the toast on screen. It does not happen on chromium (0 in 280). It also happens with tracing off (11 crashes in 100 runs of the Delete test), with backdrop-filter off, and on unchanged dev. ci/README.md already says this WebKit draws the glass in software. I could not find the trigger. One lead: making a tapped Delete shut its row without the spring (so the row is not animating when it is removed) dropped the crashes from 11 in 100 to 3 in 90, but that changes how a tap feels, so I did not include it.

Test-side, the Undo tap now waits until the toast has finished opening (its glass is as wide as its words): before that the button is half clipped and nobody could press it.

Checked

  • chromium-390, swipe-rows --repeat-each 20: 280 passed, 0 failed.
  • webkit-390, swipe-rows --repeat-each 20: 254 passed, 6 failed, all six "Target crashed" / "Page crashed" (3 Delete, 3 Trash). No assertion failed.
  • touch-select, list-chrome, phone-bars (E2E_MATRIX=sample, all four projects): 193 passed, 1 failed (list-chrome "Filter is equidistant ... pinned, 390 wide", webkit-390: 7.7 px off once; 25 of 25 on a re-run, and that test pins on the server, so it never reaches this code).
  • svelte-check: 0 errors.
  • iPhone simulator (iOS Safari, scripted touch events through Web Inspector): swipe opens the row, Pin pins, and the note is still pinned 3 s later with every list read forced to say "not pinned"; swipe again, Unpin unpins.

🤖 Generated with Claude Code

https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk

Fixes #587. ## What was failing `swipe-rows.spec.ts` failed about 1 in 10 on webkit-390 (Pin / Unpin, Delete, Trash Restore). I took traces of it on plain `dev` (webkit-390, `--repeat-each 8`: 4 failures) and it is three different things, one of them a real bug. ### 1. Real bug: a stale list read flips a pin back (Pin test) and brings a deleted note back (Delete test) The server writes its note list a moment after it announces a change (the notes worker waits 50 ms, longer under load). The app re-reads the newest page 250 ms after every event, and that read can still show the note as it was: - **Pin.** In the trace, `notes.pin` answered, the file already said `calternal-pinned: true` (`notes.peek`), and the `notes.list` that followed still said `"pinned": false`. The app put it in the index, so the pin icon went away and the row said "Pin" again. The next tap on "Unpin" then sent `{"pinned": true}` (`togglePin` flips what it sees), so the note ended up pinned. Nothing corrects it: no later event follows. - **Delete.** After `notes.delete`, the `notes.list` that followed still listed the note, and the row came back (never corrected either). #448 already guards reads that began before the delete event; this one began after it. Both are real for a person on a slow server, not only for the test. Fix (`apps/web/src/lib/notes.svelte.ts`): - a pin this device asked for wins over a list read until the list agrees with it (or 15 s pass; a failed pin clears it); - a deletion wins over a list read for 15 s, not only over reads that began before it (a `notes.created` for the note, which is what Undo and Restore send, still lets it back at once). Two new tests make every `notes.list` read stale and fail without the fix (checked on chromium-390 and webkit-390). ### 2. Test race: a swipe landed on the other row (Delete test, chromium and webkit) The server lists a new note at once with "No text yet" and a rough time, then again with both right. The second list sorts the two notes the other way and the rows slide past each other (FLIP, 320 ms). The test had checked that nothing was animating, but the second list had not arrived yet; the swipe was then measured and touched while the rows crossed, and the finger landed on the other row (screencast of the failing trace: the open row is the one the test did not name). Now `openList` waits until every row has its final text and nothing moves, the row is measured and touched in one go (so the list can't move in between), and the swipe throws if another row is on top. ### 3. Not the app: the WebKit this runs on crashes (Trash test, Delete test) The "Restore" click that timed out, a transform stuck at `-210px`, and a row count that never changed are all the page crashing: the `crash` event fires, and the traces stop. It happens right after a `notes.deleted` or `notes.created` journal entry, with the toast on screen. It does not happen on chromium (0 in 280). It also happens with tracing off (11 crashes in 100 runs of the Delete test), with `backdrop-filter` off, and on unchanged `dev`. `ci/README.md` already says this WebKit draws the glass in software. I could not find the trigger. One lead: making a tapped Delete shut its row without the spring (so the row is not animating when it is removed) dropped the crashes from 11 in 100 to 3 in 90, but that changes how a tap feels, so I did not include it. Test-side, the Undo tap now waits until the toast has finished opening (its glass is as wide as its words): before that the button is half clipped and nobody could press it. ## Checked - chromium-390, `swipe-rows` `--repeat-each 20`: 280 passed, 0 failed. - webkit-390, `swipe-rows` `--repeat-each 20`: 254 passed, 6 failed, all six "Target crashed" / "Page crashed" (3 Delete, 3 Trash). No assertion failed. - touch-select, list-chrome, phone-bars (`E2E_MATRIX=sample`, all four projects): 193 passed, 1 failed (list-chrome "Filter is equidistant ... pinned, 390 wide", webkit-390: 7.7 px off once; 25 of 25 on a re-run, and that test pins on the server, so it never reaches this code). - svelte-check: 0 errors. - iPhone simulator (iOS Safari, scripted touch events through Web Inspector): swipe opens the row, Pin pins, and the note is still pinned 3 s later with every list read forced to say "not pinned"; swipe again, Unpin unpins. 🤖 Generated with [Claude Code](https://claude.ai/code) https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
The server writes its note list a moment after it announces a change. The app re-reads the list
a quarter of a second after every event, and under load that read can still show the note as it
was: a note just pinned came back unpinned (and the next tap on "Unpin" pinned it again), and a
note just deleted came back as a row. Neither was ever corrected, as no later event follows.

- A pin this device asked for wins over a list read until the list agrees or 15 s pass.
- A deletion wins over a list read for 15 s, not only over reads that began before it (a
  notes.created for it, an undo or a restore, still lets it back at once).
- swipe-rows.spec: two tests that make every list read stale (they fail without the fix); the
  rows are measured and touched in one go and the test waits until every row has its final text
  and nothing slides (the second list sorts the two notes the other way, and the rows pass over
  each other, so a swipe could land on the other note); Undo is tapped once the toast is open.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
swipe-rows.spec: a list read still going when the test ends is let go (#587)
Some checks failed
CI / server (pull_request) Successful in 28s
CI / web (pull_request) Failing after 43s
CI / rust (pull_request) Successful in 4m16s
d5ac53882d
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Author
Owner

Landed in train AJ, #633.

Landed in train AJ, #633.
kayg closed this pull request 2026-10-19 18:00:01 +00:00
Some checks failed
CI / server (pull_request) Successful in 28s
CI / web (pull_request) Failing after 43s
CI / rust (pull_request) Successful in 4m16s

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!591
No description provided.