Skip to content

Add partysocket terminal close reconnect predicate#409

Merged
threepointone merged 2 commits into
mainfrom
fix/partysocket-terminal-reconnect
Jun 23, 2026
Merged

Add partysocket terminal close reconnect predicate#409
threepointone merged 2 commits into
mainfrom
fix/partysocket-terminal-reconnect

Conversation

@threepointone

Copy link
Copy Markdown
Collaborator

Summary

  • Add shouldReconnectOnClose to ReconnectingWebSocket options so callers can classify a close event as terminal before automatic reconnect scheduling.
  • Preserve existing reconnect-by-default behavior when the predicate is omitted or returns true.
  • Add reconnect tests for terminal close suppression, default behavior, and explicit reconnect() unsealing after a predicate-stopped close.

Why

Cloudflare Agents needs to distinguish transient WebSocket disconnects from terminal close codes such as policy/auth failures. Today consumers can observe shouldReconnect, but cannot prevent the underlying PartySocket retry loop from continuing on a terminal server close. This PR adds a small upstream hook at the point where the close event is still available and before _connect() is scheduled.

Test plan

  • npm run check:test -- src/tests/reconnecting.test.ts from packages/partysocket passed: 49 tests.
  • npm run build -w partysocket && npm run check:test -w partysocket passed: package build plus 13 test files / 325 tests.
  • npm run check:lint passed.
  • npm run check:type passed.

Known check caveat

  • Root npm run check currently stops in check:repo on an existing Sherif workspace version mismatch for the partyserver dependency (^0.5.8 in fixtures vs ^0.5.7 in packages). That appears unrelated to this PR.
  • Root npm run check:format currently reports pre-existing formatting drift in packages/partyserver/CHANGELOG.md. Formatting it would add unrelated changelog churn, so this PR leaves that file untouched.

Made with Cursor

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3b10005

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
partysocket Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

hono-party

npm i https://pkg.pr.new/cloudflare/partykit/hono-party@409

partyfn

npm i https://pkg.pr.new/cloudflare/partykit/partyfn@409

partyserver

npm i https://pkg.pr.new/cloudflare/partykit/partyserver@409

partysocket

npm i https://pkg.pr.new/cloudflare/partykit/partysocket@409

partysub

npm i https://pkg.pr.new/cloudflare/partykit/partysub@409

partysync

npm i https://pkg.pr.new/cloudflare/partykit/partysync@409

partytracks

npm i https://pkg.pr.new/cloudflare/partykit/partytracks@409

partywhen

npm i https://pkg.pr.new/cloudflare/partykit/partywhen@409

y-partyserver

npm i https://pkg.pr.new/cloudflare/partykit/y-partyserver@409

commit: 3b10005

@threepointone threepointone merged commit 580d9bd into main Jun 23, 2026
6 checks passed
@threepointone threepointone deleted the fix/partysocket-terminal-reconnect branch June 23, 2026 08:43
@github-actions github-actions Bot mentioned this pull request Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant