Repository navigation
fix(client): preserve data during replay suppression - #4723
Closed
joshdchang wants to merge 1 commit into
Closed
joshdchang wants to merge 1 commit into
joshdchang wants to merge 1 commit into
Conversation
joshdchang
marked this pull request as ready for review
July 15, 2026 21:43
Contributor
|
Thanks for the fix, @joshdchang — suppressing only the To land it I've rebased your commit onto current
Closing this in favour of #4782. |
alco
added a commit
that referenced
this pull request
Sep 1, 2026
…ient (#4782) Supersedes #4723 by @joshdchang, rebased on `main` with follow-up commits. Josh's original commit is preserved as-is. ## Problem When a fresh `ShapeStream` enters replay mode (the up-to-date tracker holds a recent cursor for the shape) and the first up-to-date it sees carries that same cursor, `ReplayingState` requested suppression of the *whole batch*: `#onMessages` returned before publishing anything. A batch of `[insert, …, up-to-date]` therefore lost its rows while the stream's offset still advanced past them. ## Fix - Represent the transition as `suppressUpToDate` instead of `suppressBatch`. The snapshot-tracker filtering runs as usual and only the duplicate `up-to-date` control message is removed before notifying subscribers. - Apply the `global_last_seen_lsn` bookkeeping for a suppressed up-to-date before dropping it, so suppression affects delivery to subscribers only, not snapshot retirement. - Document the invariant as C9 in the client `SPEC.md`. The original PR also skipped the subscriber callback when the filtered batch was empty. That applied outside replay mode as well (a batch whose changes were all rejected by the snapshot tracker previously published an empty array), so it is not included here; the pre-existing behaviour is kept. ## Reachability The suppression branch cannot fire against a conforming server: `electric-cursor` is only set on `live=true` responses, the client only sends `live=true` from `LiveState`, and `ReplayingState` is only entered around a non-live request. The first up-to-date a replaying stream sees therefore never carries a cursor. The state-machine semantics were still wrong and are fixed here; the C9 test and spec entry are annotated as pinning the invariant with a synthetic cursor header rather than describing a server scenario. Whether the replay mechanism should exist at all is left for a follow-up. Fixes #4722. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01PCuaAMyknYeVkfWMkyGuuS --------- Co-authored-by: joshdchang <joshchang04@gmail.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
up-to-datecontrol message while the tracker advances to the live cursorRoot cause
The replay transition was represented as
suppressBatch, and the client returned before publishing the entire response. A valid replay response can contain both data messages and the duplicateup-to-datemarker, so this discarded rows together with the marker.Fix
Represent the transition as
suppressUpToDate, run the normal snapshot-tracker filtering, and remove onlyup-to-datemessages before notifying subscribers. The client still avoids an empty subscriber callback when the response contains only the suppressed marker.Fixes #4722.
Verification
mainbefore the fix and passes after itcorepack pnpm exec vitest --config vitest.unit.config.ts --run(438 tests)corepack pnpm run typecheckcorepack pnpm run stylecheckgit diff --check