fix(ws-server): don't apply a gapped changeset after rejecting it#3
Open
silviot wants to merge 1 commit into
Open
fix(ws-server): don't apply a gapped changeset after rejecting it#3silviot wants to merge 1 commit into
silviot wants to merge 1 commit into
Conversation
InboundStream.receiveChanges detected a gap (the incoming changeset's `since` is ahead of our applied `#lastSeen`) and sent RejectChanges — but had no `return`, so it fell through and applied the non-contiguous batch anyway, advancing `#lastSeen` and the durable crsql_tracked_peers cursor past the gap. The server then believed it had everything from that peer and never re-requested the missing range, so the peer's committed changes were silently and permanently lost on the server and on every other peer. This is the inbound/apply twin of the OutboundStream.reset() stub bug. Add `return;` after rejectChanges, mirroring the client InboundStream which returns immediately after rejecting. The missing range is then recovered when the sender re-streams from the server's (unadvanced) last-seen. Adds InboundStream.test.ts covering the gapped (rejected, not applied) and contiguous (applied) paths. Co-authored-by: Claude Opus 4.8 (1M context) <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.
Bug
InboundStream.receiveChanges(server) detects a gap — the incoming changeset'ssinceis ahead ofthe version we have actually applied (
#lastSeen) — and sendsRejectChanges, but there is noreturn. It falls through and applies the non-contiguous batch anyway, then advances#lastSeenand the durable
crsql_tracked_peerscursor past the gap.The server then believes it has received everything from that peer and never re-requests the
missing range, so the peer's committed changes are silently and permanently lost on the server and
on every other peer — "converged but not actually synced" divergence. This is the inbound/apply twin
of the
OutboundStream.reset()stub that was fixed in the outbound direction.The client's
InboundStreamalready does the right thing: itreturns immediately after rejecting(and reverts
#lastSeenson apply failure).This was reproduced against the shipped
@vlcn.io/ws-serverartefact (vlcn.io-ws-server-0.2.2):a gapped changeset is applied (
applied.length === 1) while a reject is also sent.Fix
return;afterrejectChanges. The server keeps#lastSeenat the pre-gap value, so the missingrange is recovered when the sender re-streams from the server's last-seen (e.g. on the next
StartStreaming/ reconnect).Adds
InboundStream.test.ts(mirroringOutboundStream.test.ts) covering the gapped path (rejected,not applied) and the contiguous path (applied).
Notes / follow-ups
the client to honour an inbound
RejectChanges— todayws-client'sWebSocketTransportthrows ontags.RejectChanges, so server→client gap-recovery for the upload direction is dead.Tracked separately.
librocco/main(the branch the librocco0.2.2tarball is built from).mainhas thesame missing
returnand should get the same fix.apps/sync-server/src/ws-server-reject-recovery.test.ts.Co-authored-by: Claude Opus 4.8 (1M context) noreply@anthropic.com