Repository navigation
Commit 7dbf92c
fix: keep WebSocket binaryType + close handling stable across compat dates
Three related WebSocket fixes so PartyServer behaves identically on every
Worker compatibility date, plus the tooling to prove it. All changes are
no-ops on older dates and corrective on newer ones (backward compatible).
1. Pin binaryType to "arraybuffer" for non-hibernating connections.
On compat dates >= 2026-03-17 the `websocket_standard_binary_type` flag
flips the default server-side `binaryType` from "arraybuffer" to "blob",
so binary frames arrived as `Blob` instead of `ArrayBuffer` on the
in-memory accept path. Every PartyServer consumer (and frameworks built
on it, e.g. Cloudflare Agents / @cloudflare/voice) has always received
`ArrayBuffer`, so it is pinned back in `InMemoryConnectionManager.accept`.
The Hibernation API is unaffected (it always delivers `ArrayBuffer`).
2. Accept non-hibernating connections in half-open mode.
`accept({ allowHalfOpen: true })` (with a try/catch fallback to bare
accept() for older runtimes) keeps PartyServer's manual close handshake
in control on compat dates >= 2026-04-07, where `web_socket_auto_reply_to_close`
would otherwise auto-tear-down a tunneled DO socket and surface a spurious
retryable "Network connection lost." rejection.
3. Stop reporting transport-teardown errors via onError.
A retryable "Network connection lost." / "WebSocket peer disconnected"
error that fires on an already CLOSING/CLOSED connection is the socket
going away during the close handshake, not an application error. New
`transport-errors.ts` (`isBenignTeardownError`, structured `retryable`-first
detection so it stays correct under `enhanced-error-serialization` >=
2026-04-21) suppresses it in both the in-memory `handleErrorFromClient`
and hibernating `webSocketError` paths. Genuine mid-connection (OPEN)
errors still reach onError.
Verification:
- Bumped wrangler ^4.86.0 -> ^4.100.0 so local `wrangler dev` runs compat
dates through 2026-06-11 (older workerd capped at 2026-05-03).
- New `BinaryTypeProbe` DO + `compat-binarytype.test.ts` + parametrized
`vitest.compat.config.ts` lock the ArrayBuffer contract across dates; the
`test:compat-matrix` script runs it at 2026-01-28 / 03-24 / 04-07 / 04-21
and is wired into PR CI. The gate is non-vacuous (reports "blob" without
the pin, "arraybuffer" with it).
- 6 new `transport-errors.test.ts` unit tests cover the suppression predicate.
- Full suite: 86 unit tests pass; typecheck, lint, format clean.
Changeset: patch -> 0.5.7.
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent aeba44f commit 7dbf92c
16 files changed
Lines changed: 559 additions & 24 deletions
File tree
- .changeset
- .github/workflows
- fixtures/alarm-restart-e2e
- packages/partyserver
- scripts
- src
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
135 | 135 | | |
136 | 136 | | |
137 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments