Train AZ: notes history and Saved you can trust (#652) #672

Closed
kayg wants to merge 0 commits from train/2026-10-22az into dev
Owner

Train AZ ran the full suite (run az2, dev c2b7a1a + 9f8131a): fmt, clippy, workspace tests, build, svelte-check, every Playwright project. Rust all green. Browser: admin 42+1, cr1440 331, cr390 254+208+2, wk1440 139+190+1, wk390 153 / 187+1 / 125, small 19. The failures were re-run 3x each on this head: refusal-performance (chromium-390, webkit-390) and task-check:29 = 18/18 passed; review4-signout:242 (webkit-1440) = 12/12 passed; admin-contrast is a known intermittent. Run az1 failed on the known storage_startup lock race (test-only, fix in progress on #664).

Contents (#652): Saved means durably in history (receipts), temporary errors retry quietly, permanent size refusals show and clear once a fitting state is covered (incl. undo, offline), per-tab sign-out leases, Saved doesn't wait on collaborators, bounded queues, history order kept through failed writes, refusal path without per-key re-encodes or whole-note re-uploads, MessageChannel receipt drain, a closed note keeps its receipt wait (no false sign-out warning), real-server test suite in CI. Merged with #664 (bounded shutdown).

Independent review: 10 rounds; final verdicts merge on 325ecc3, 1f78184 (delta) and 9f8131a (merge resolution). Known open: one 0.5-1.4 s stall when undoing a 65 MiB paste.

🤖 Generated with Claude Code

https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk

Train AZ ran the full suite (run az2, dev c2b7a1a + 9f8131a): fmt, clippy, workspace tests, build, svelte-check, every Playwright project. Rust all green. Browser: admin 42+1, cr1440 331, cr390 254+208+2, wk1440 139+190+1, wk390 153 / 187+1 / 125, small 19. The failures were re-run 3x each on this head: refusal-performance (chromium-390, webkit-390) and task-check:29 = 18/18 passed; review4-signout:242 (webkit-1440) = 12/12 passed; admin-contrast is a known intermittent. Run az1 failed on the known storage_startup lock race (test-only, fix in progress on #664). Contents (#652): Saved means durably in history (receipts), temporary errors retry quietly, permanent size refusals show and clear once a fitting state is covered (incl. undo, offline), per-tab sign-out leases, Saved doesn't wait on collaborators, bounded queues, history order kept through failed writes, refusal path without per-key re-encodes or whole-note re-uploads, MessageChannel receipt drain, a closed note keeps its receipt wait (no false sign-out warning), real-server test suite in CI. Merged with #664 (bounded shutdown). Independent review: 10 rounds; final verdicts merge on 325ecc3, 1f78184 (delta) and 9f8131a (merge resolution). Known open: one 0.5-1.4 s stall when undoing a 65 MiB paste. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
kayg added 31 commits 2026-10-22 18:12:31 +00:00
Return each transaction's source error to every failed batch member instead
of canceling replies and losing the cause. Keep the transaction phase and
SQLite extended code in server details, including captured test output.

Retain failed server and outside edits in the existing history retry queue.
Keep peers synchronized with the applied changes and withhold Saved until
their history is durable. Check typing backpressure before applying a new
diff so a failed earlier write cannot leave it outside that queue.

Keep job reports limited to catalogue messages, including older stored
reports. Add deterministic storage, transaction and protocol regressions.

Refs: #652
- A note's typed changes go to the history writer at once again, so
  changes waiting together share one transaction. Order through failures
  comes from a per-note lane: after a failed batch every later batch of
  the note fails without writing, and the room resends everything not yet
  durable as one batch in a new generation.
- Save checks are cumulative: each commit answers, per connection, the
  newest check it covers (bounded at 16 per connection), so steady typing
  on a slow disk never starves Saved.
- The client's status is about this device's own edits (and other tabs');
  collaborators' changes only gate the replay base, confirmed with one
  check per pause (300 ms quiet, at most every 2 s), not one per change.
- Tabs forward another tab's update only when that tab is offline.
- A note with no local edits opens saved: the local copy keeps an
  unconfirmed-edit marker in the same transaction as the edit.
- A retried API edit sends its changed event once it is durable.
- The real-SyncClient bridge writes replies over 64 KiB in full (Bun
  1.4.2 stalls console.log there); its two tests run without --ignored
  and skip only where Bun is absent and not required.
- Ports the second review's ordering and recovery reproductions as tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
- A tab counts another tab's edit as saved only when that tab announces
  its server receipt ("durable up to my edit n") over the note's
  BroadcastChannel. If that doesn't come within 2 s (stuck socket, closed
  tab) the tab sends the edit itself and waits for its own receipt; a
  reconnect's step 2 covers held sibling edits too. Tabs still don't
  re-send each other's updates otherwise.
- Room messages over the 1 MiB socket limit go in pieces (`+<room>`
  frames, then the last for `<room>`); the server joins them up to
  64 MiB. Larger changes are never sent: they stay unsaved and the status
  says they are too large; the server answers `too_large` if a client sends
  one anyway, skipping the whole message.
- The local copy's unconfirmed-edit marker is now an empty Yjs update
  under the key `dirty@<ms>`, so clients from before read it as a no-op.
  A frozen round-2 LocalCopy test opens and compacts such a copy.
- Signing out warns when this device holds a collaborator's change the
  server hasn't confirmed (`heldSince`, written down only after 2 s
  without a receipt), as well as for its own unsent edits.
- Tests: the review's R3-TAB reproduction, 1.2 MB and 10 MB pastes end to
  end (history, other tab, collaborator), piece reassembly and refusal,
  rollback, held-change sign-out warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
The page that signs out (and one told by another tab or by the server)
is replaced by a reload only some time later. Until then it could still
open or write a note's local copy while the next page deletes them, which
left a note database behind after sign-out (signout.spec.ts:221 on
webkit-390). `stopNotes()` closes every open note and refuses to open
more; the wipe and remote sign-out paths call it before reloading.
Closing a local copy now writes not-yet-confirmed IndexedDB writes to the
write-ahead list first. The sign-out spec waits up to 30 s for its own
server to start on a loaded host instead of 5 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Centralize observed-edit coverage and permanent refusals in one client
receipt authority. Persist recovery obligations before replacing a local
copy, and retain a canonical replay update across tab close and reload.
Keep confirmed IME text out of duplicate replay paths.

Bound chunk assembly, room queues and history retries by bytes and time,
and reject stale membership frames and incomplete sync steps. Freeze
sibling editors and guard direct Yjs undo/redo before sign-out. Retain warnings for refused or held work. Show refusal words inside the editor viewport.

Keep the review reproductions as permanent regressions and add a
10,000-case interleaving model. Document the receipt invariant in ADR 0020.

Refs #652
Round 7 performance fixes for the review of d1b8c08:

- P1: a too-large state is not encoded again until deletions could have
  made it fit. The client keeps a lower bound on its size (text length, or
  the last oversized encoding / pasted text minus at most 64 bytes per
  deleted unit), so typing or collaborator packets next to a refused 65 MiB
  paste no longer re-encode and re-compact the note; reconnects skip the
  step-2 encode too.
- P2: each refusal gets one complete resubmission; later edits travel as
  ordinary updates. A refused packet held behind IME is resent on its own
  once applied instead of triggering another full copy.
- P3: the receipt drain yields through MessageChannel tasks instead of a
  setTimeout chain, and server coverage is tracked as Yjs ids and deletes
  only (sync/coverage.ts), so a whole-note proof no longer re-applies the
  note into a shadow document.

Tests: refusal-performance (unit + browser), coverage, and the model now
uses the server's 1500-byte limit on the client too, with undo/redo,
sign-out during backoff, a full-state byte budget and a "fits => Saved"
liveness oracle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
The 50,000-trial runs found two model gaps, not client faults:
- The model server dropped an input whose prerequisites were missing (it
  changed nothing yet, so it never reached the log), then acknowledged it.
  The real room journals parked inputs (crates/notes pipeline.rs
  apply_typed); the model now does too.
- A held packet resent unchanged on its own was counted as a full-state
  copy by the byte budget. Packets the tab received are now excluded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
A round passes when none of its callbacks reaches 16 ms. d1b8c08 still
fails every test (re-encodes take hundreds of ms in every round).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
A packet that waited behind IME across a reconnect went out again as a
complete-state copy. Like a held refused packet, it now goes on its own
when it fits; only an oversized one waits for the complete state. Found
by the 50,000-trial model's byte budget (two full copies, no refusal).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
- review4-signout "refusal" test follows round 6: a refusal stays while
  no receipt covers the current state (a receipt for a check sent before
  it is delivered late and must not clear it; it survives a reload while
  receipts are held), then clears and Saved returns in both tabs once a
  covering receipt arrives. room_error uses a permanent code: temporary
  ones retry quietly by contract. Frames' message tags are read correctly.
- signout "online" test looks for #663's __Host-calternal_session cookie.
- The old-name session test hands its new page to the fixture, whose
  WebKit offline() otherwise used the closed one.
- The remote-session context ignores the test proxy's certificate (WebKit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Review 7:
- N1: after a never-sent paste, the next key leaves the room a gap, so it
  asks for a resend and holds save checks until a sync step 2 fills it. The
  complete-state retry went as an ordinary update, which never releases
  them: "Too large to save" forever. Every complete state now goes as a
  step 2 (the room keeps its rule: only a step 2 that leaves nothing
  missing is the resend). A resend the room asked for while edits were
  held behind IME is answered with another step 2 once they apply.
- The class: the JS test room and the model's server now implement the
  real room's gap rule (test-server/resync.ts: follows_on, has_missing,
  resync, one held check, released only by a step 2). With it the model
  found the IME case above. New packages/editor/integration/real-server
  suite runs paste/type/undo/offline/reconnect/two-device sequences
  against the real binary, and CI runs it.
- N2: the size bound counts a paste's full UTF-8 size, so the first
  backspace next to a CJK paste no longer encodes the note.
- The receipt drain no longer yields after its last item.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Found by the model once its server followed the real gap rule: a sibling
edit forwarded while held behind IME was refused by the room for a gap;
the room asked for a resend; the step 2 answer could only hold what was
applied here, yet it satisfied the room, whose held check then retired
the forwarded edit: Saved without the edit on the server. Pre-existing
(d1b8c08 and 1208bfb fail the new test too). Now a resend request marks
edits still behind IME unsubmitted; once applied they travel again (as a
step 2 while the room waits, on their own otherwise).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
The faithful model, with every receipt-drain step forced to yield, found
a second form of the same race: a sibling edit forwarded while the room
was already waiting for a resend is refused without a new request; the
next step 2 (built from applied state, without it) released the held
check, which retired the forwarded edit. Now an edit's own packet sent
while a resend is owed counts only if it is applied here (the step 2
sent before the next check holds it); otherwise it travels again once
applied. Only edits a resend request unsubmitted are resent on apply, so
a sibling's edits still wait for their owner as before. The model now
forces drain yields in every trial.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Review 8, R8-1: any save answer cleared the owed resend, but the room
(real and test doubles) still answers checks queued before the gap while
it waits. In that window (note too large, no step 2 sent), a sibling edit
forwarded while behind IME lost its "send again" mark and was retired by
the answer to a check after a step 2 that lacked it. Now only an answer
to a check sent after a step 2 (or a later one) ends the wait. New unit
test drives that window: Saved early before, not after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Root cause of the webkit-390 review4-signout:131 flake (product, not test).
Instrumented runs (4 of 32 failed) showed the held marker for the daily
note was written by NoteSession.destroy() 132-175 ms after the server's
change arrived, when the fixture navigated on; the receipt itself was not
slow. The marker was never cleared (the note stayed closed), so the
sign-out 11-15 s later warned about a change long durable. A real user
leaving a note right after a collaborator change would see the same
spurious warning.

The close still writes the marker at once (the device may hold the last
copy if the page goes), but the client now lingers, without editor or
local copy, until the receipt arrives (at most 30 s), then the marker is
cleared by compare-and-clear (MetaStore.clearHeld). Reopening the note
or signing out ends the wait. A lingering client reports only held
changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Second cause of the webkit-390 review4-signout:131 flake (test, not
product). Instrumented runs: in every hang the Sign out handler never ran
(0 of its marks), while in passing runs it ran at once. The test set the
hash to account settings and clicked Sign out immediately; the passkey
list above the button loads after the page shows ("Looking…" first) and
pushes the button down, so on a slow phone-sized WebKit the click landed
where the button had been. A shared accountReady() waits for the list
(bounded, for offline cases) before every such click in the sign-out
specs. (A CodeMirror "update in progress" console error seen in the
failing traces also occurs in every passing run: unrelated.)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
This host's ephemeral range starts at 1024, so freePort() can return a
Fetch "bad port"; a sign-out test got 1723 and WebKit refused it with
ERR_UNSAFE_PORT. Skip those ports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Merge origin/dev (#664 bounded shutdown) into issue/652-signout-flake
Some checks failed
CI / web (pull_request) Failing after 1m8s
CI / server (pull_request) Successful in 2m2s
CI / rust (pull_request) Failing after 5m23s
9f8131aa8c
Conflicts resolved so the #652 write paths keep #664's guarantees:
- History: the bounded writer queue, byte budgets and receipts of #652
  now sit behind #664's closable HistoryWriter. Every enqueue (plain,
  lazy, sized and the grouped room batches) goes through one send()
  that refuses once shutdown closed the queue; shutdown joins the thread.
- Rooms: the byte-bounded room queue of #652 with #664's joined actor
  task and Shutdown command (zero queue weight, so it is never blocked
  by payload budgets); the refused handle uses the same queue type.
- Bulk: the completed-job retry runs as Home background work (#664,
  joined at shutdown) and still retries when the queued write failed.
- Room join keeps #664's Notes::enter with #652's byte-bounded input.

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

Closing: this PR's head commit is already in dev (checked 26 Oct, against dev a779a46). The train landed it by merging directly into dev.

Closing: this PR's head commit is already in `dev` (checked 26 Oct, against dev `a779a46`). The train landed it by merging directly into dev.
kayg closed this pull request 2026-10-26 11:18:04 +00:00
Some checks failed
CI / web (pull_request) Failing after 1m8s
CI / server (pull_request) Successful in 2m2s
CI / rust (pull_request) Failing after 5m23s

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