feat(transport): adopt v3 WebSocket subprotocol#124
Closed
infinia-yzl wants to merge 1 commit into
Closed
Conversation
clockworklabs/SpacetimeDB 2.2.0 introduced a v3 WebSocket transport
(PR #4761) with subprotocol identifier `v3.bsatn.spacetimedb`. v3
keeps the v2 ClientMessage / ServerMessage schema intact — the only
on-the-wire change is that a single WebSocket payload may contain
one OR more BSATN-encoded v2 messages concatenated back to back.
Senders may coalesce as they please; receivers decode sequentially
until end-of-buffer.
The existing BSATNDeserializer.process_bytes_and_extract_messages
already loops decoding messages from the incoming buffer until
empty, so the receive-side semantics work for free on v3. The send
side keeps sending one logical message per frame, still valid v3.
Verified manually against a SpacetimeDB 2.2.0 server:
curl -s -i -N \
-H "Connection: Upgrade" -H "Upgrade: websocket" \
-H "Sec-WebSocket-Version: 13" \
-H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" \
-H "Sec-WebSocket-Protocol: v3.bsatn.spacetimedb" \
-H "Authorization: Bearer <token>" \
http://localhost:3333/v1/database/<name>/subscribe
returns `HTTP/1.1 101 Switching Protocols` with
`sec-websocket-protocol: v3.bsatn.spacetimedb` and proceeds with
normal message dispatch (IdentityToken delivered immediately).
Also verified end-to-end via integration tests in a downstream
project: anonymous connect + subscribe + iter() round-trip, plus an
overlapping-subscription audit (subscribe narrow, then subscribe
wide; assert on_insert fires exactly once for the new row and zero
additional times for the already-cached row — analogous to the
Unreal SDK fix in #4903).
2 tasks
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
Flips the WebSocket subprotocol identifier from
v2.bsatn.spacetimedbtov3.bsatn.spacetimedbto opt into the v3 transport introduced in clockworklabs/SpacetimeDB 2.2.0 (PR clockworklabs/SpacetimeDB#4761).Why this works as a one-line change
v3 is not a new message schema. It reuses the v2
ClientMessage/ServerMessagevalues as-is. The only on-the-wire change is that a single WebSocket payload may now contain one OR more BSATN-encoded v2 messages concatenated back to back. Senders may coalesce as they please; receivers must decode sequentially until end-of-buffer.The existing
BSATNDeserializer.process_bytes_and_extract_messagesalready loops decoding messages from the incoming buffer until empty, so the receive-side semantics work for free. The send side keeps sending one logical message per frame, which is still valid v3 — a future optimization is to coalesce client-side sends, deliberately not part of this PR.Verification
Server handshake responds with
101 Switching Protocols+sec-websocket-protocol: v3.bsatn.spacetimedb:End-to-end verified in a downstream project via integration tests against a live SpacetimeDB 2.2.0 dev DB:
iter()round-trip ✓on_insertfires exactly once for the new row, zero additional times for the cached row — analogous to the Unreal SDK fix in fix(unreal): suppress spurious OnInsert on overlapping subscription refcount bump clockworklabs/SpacetimeDB#4903) ✓Test plan
Notes for reviewers
version: String = "v1"on line 10 is the HTTP path prefix (/v1/database/...), unrelated to the WebSocket subprotocol version — leaving untouched.🤖 Generated with Claude Code