Skip to content

fix: handle options change and reconnects#330

Merged
threepointone merged 2 commits intocloudflare:mainfrom
msutkowski:ms/socket-issues
Feb 22, 2026
Merged

fix: handle options change and reconnects#330
threepointone merged 2 commits intocloudflare:mainfrom
msutkowski:ms/socket-issues

Conversation

@msutkowski
Copy link
Contributor

@msutkowski msutkowski commented Feb 17, 2026

We were running into a bug that'd cause a thundering herd style issue when using agents. Basically, our chat interface allows you to switch between N conversations -- but we have an additional single use token query parameter used to authorize the websocket connection. When the websocket failed or we switch between different conversations (and thus, new connections) it used the stale token which made the reconnection fail and caused cascading useEffect related issues. We have applied this change as a patch in our project and things work as expected 🎉. The only real issue might be is if someone was relying on the faulty behavior that exists.

If necessary, I can try to create an isolated reproduction with the same token exchange mechanics that we use.

A little follow up a few hours later: there is a race condition with query when using useAgent -- if you pass a promise to query, it'll try to resolve, but the websocket will try connect with stale options before react has a chance to update things, causing typical useEffect 💣s .

@changeset-bot
Copy link

changeset-bot bot commented Feb 17, 2026

🦋 Changeset detected

Latest commit: bf6c446

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

This PR includes changesets to release 1 package
Name Type
partyserver 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

@threepointone
Copy link
Collaborator

I added a few more tests and guards, thanks for this pr. will land once ci passes.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 22, 2026

Open in StackBlitz

hono-party

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

partyfn

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

partyserver

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

partysocket

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

partysub

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

partysync

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

partytracks

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

partywhen

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

y-partyserver

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

commit: bf6c446

msutkowski and others added 2 commits February 22, 2026 17:26
Replace wrangler migration entries from `new_classes` to `new_sqlite_classes` across fixtures and READMEs and add a changeset documenting that partyserver now relies on SQLite-backed Durable Objects (synchronous storage). Update use-socket logic to track option changes while disabled, ensure correct socket creation/cleanup on re-enable and StrictMode/HMR, and always connect replacement sockets. Expand tests in partysocket to cover these re-enable, token-refresh, cleanup, and wire-level scenarios. Breaking: Durable Object namespaces must use `new_sqlite_classes` when deployed.
@@ -0,0 +1,11 @@
---
"partyserver": minor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lemme see if I can workaround this

@msutkowski
Copy link
Contributor Author

I added a few more tests and guards, thanks for this pr. will land once ci passes.

Thanks @threepointone! FWIW, the general agents implementation around DOs is so nice 🎉

@threepointone threepointone merged commit b82fd4d into cloudflare:main Feb 22, 2026
3 checks passed
@github-actions github-actions bot mentioned this pull request Feb 22, 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.

2 participants