enhance(websocket): improve client synchronization - #38847
Open
silverwind wants to merge 4 commits into
Open
Conversation
State reached the client over two channels with no order between them, so a push could be lost or overwritten. The server subscribed to the user's topic only after the handshake completed, and publishers skip topics without subscribers, so anything fired in that window was discarded. The client compensated by reconciling over a separate HTTP request on connect, whose answer could arrive after a newer push and overwrite it. Closing an issue then left the navbar stopwatch running. Subscribe before the handshake and hand the connection its current state as the first frames, so the socket is the only source and the client no longer reconciles. Also stop logging an error when a queued notification finds its issue gone, which is expected once its repository has been deleted. Assisted-by: Claude Code:claude-opus-5
The router had to decode a logout payload to decide which connection may receive it, so generic transport code knew one event's constant, struct and wire JSON. The broker payload now carries the target session in its header, making per-session delivery a transport concern and leaving the router with an opaque payload it forwards or drops. Each event now owns its constant, payload, builder and publisher in a single file, with the generic file holding transport only, so adding an event touches one file. The SharedWorker keeps the last message per event type and replays it to a tab attaching to an already-open socket, which the server cannot reach because it sees one connection per worker rather than one per tab. Assisted-by: Claude Code:claude-opus-5
Member
Author
|
More cleanup done, description is updated. |
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.
Between when HTML is written and the websocket has connected, there is a short time window where clients miss state updates, which is the cause of this flake.
Now we send the state to all websocket clients as the first message and frontend has a cache in the worker to replay the last event per type to new tabs.
This also removes the previous hacky fetch-based reconcillation when opening tabs.
Also refactor the backend to contain all code for a event in a single file, so adding a new event is a single file addition in backend.