Skip to content

Fix duplicate initial Agent state frames#1509

Merged
threepointone merged 1 commit into
mainfrom
fix-agent-initial-state-sync
May 12, 2026
Merged

Fix duplicate initial Agent state frames#1509
threepointone merged 1 commit into
mainfrom
fix-agent-initial-state-sync

Conversation

@threepointone
Copy link
Copy Markdown
Contributor

@threepointone threepointone commented May 12, 2026

Summary

  • Prevent duplicate initial CF_AGENT_STATE frames during Agent WebSocket connection setup by temporarily excluding only the connecting socket from lazy state-initialization broadcasts.
  • Preserve lazy initialization broadcasts for any other existing protocol-enabled clients.
  • Add a patch changeset for agents and protocol regression coverage for both the duplicate-frame case and the existing-client broadcast edge case.

Test plan

  • npm run test:workers -w agents -- src/tests/protocol-messages.test.ts
  • npm run test:react -w agents -- src/react-tests/useAgent.test.tsx -t "should update state property on client setState"
  • npm run test:react -w agents -- src/react-tests/useAgent.test.tsx
  • npx oxfmt --check packages/agents/src/index.ts packages/agents/src/tests/protocol-messages.test.ts packages/agents/src/tests/agents/protocol-messages.ts
  • ReadLints on edited files

Made with Cursor


Open in Devin Review

Avoid sending stale initial state twice during WebSocket connection setup by excluding the connecting socket from lazy initialization broadcasts and then sending it one explicit state frame. This prevents client-originated setState updates from being overwritten by a late initial-state message while preserving broadcasts for other protocol clients.

Adds protocol regression coverage for both the connecting-client duplicate frame case and the existing-client lazy initialization broadcast edge case.

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

changeset-bot Bot commented May 12, 2026

🦋 Changeset detected

Latest commit: f7c3466

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

This PR includes changesets to release 1 package
Name Type
agents Patch

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

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 12, 2026

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1509

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1509

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1509

hono-agents

npm i https://pkg.pr.new/hono-agents@1509

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1509

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1509

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1509

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1509

commit: f7c3466

@threepointone threepointone merged commit 4aa4176 into main May 12, 2026
4 checks passed
@threepointone threepointone deleted the fix-agent-initial-state-sync branch May 12, 2026 11:45
@github-actions github-actions Bot mentioned this pull request May 12, 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