Skip to content

Readonly state#28190

Merged
elithrar merged 3 commits intoproductionfrom
sync-docs-pr-610
Feb 8, 2026
Merged

Readonly state#28190
elithrar merged 3 commits intoproductionfrom
sync-docs-pr-610

Conversation

@agents-git-bot
Copy link
Copy Markdown
Contributor

@agents-git-bot agents-git-bot bot commented Feb 8, 2026

Summary

Sync documentation for cloudflare/agents PR #610: Readonly state

This PR adds comprehensive documentation for the new readonly connections feature, which allows restricting certain WebSocket connections from modifying agent state while still allowing them to receive state updates and call RPC methods.

Changes

  • Added src/content/docs/agents/api-reference/readonly-connections.mdx
  • Documented server-side methods: shouldConnectionBeReadonly(), setConnectionReadonly(), isConnectionReadonly()
  • Documented client-side API: onStateUpdateError callback
  • Included usage examples for query parameters, RBAC, admin dashboards, and dynamic permissions
  • Explained behavior details including state synchronization and connection cleanup
  • Provided best practices for authentication, user feedback, and permission checks
  • Added migration guide for existing agents

Source

Test plan

  • Review documentation for accuracy and completeness
  • Verify all code examples are syntactically correct
  • Ensure links and references are properly formatted
  • Confirm adherence to Cloudflare docs style guide

Sync documentation for PR #610 from cloudflare/agents repository.

Adds comprehensive documentation for the new readonly connections feature,
which allows restricting WebSocket connections from modifying agent state
while still allowing them to receive state updates and call RPC methods.

Key additions:
- Server-side methods: shouldConnectionBeReadonly, setConnectionReadonly, isConnectionReadonly
- Client-side API: onStateUpdateError callback
- Usage examples for query parameters, RBAC, admin dashboards, and dynamic permissions
- Behavior details including state sync and connection cleanup
- Best practices for authentication, user feedback, and permission checks
- Migration guide for existing agents

Source PR: cloudflare/agents#610
@github-actions github-actions bot added the product:agents Build and deploy AI-powered Agents on Cloudflare that can act autonomously. label Feb 8, 2026
@github-actions github-actions bot added the size/l label Feb 8, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 8, 2026

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
/src/content/docs/agents/ @irvinebroque, @rita3ko, @elithrar, @thomasgauvin, @threepointone, @whoiskatrin, @cloudflare/pcx-technical-writing, @cloudflare/ai-agents, @cloudflare/dev-plat-leads

@elithrar
Copy link
Copy Markdown
Collaborator

elithrar commented Feb 8, 2026

/bonk review and address the build issues

Co-authored-by: elithrar <elithrar@users.noreply.github.com>
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Feb 8, 2026

Summary

The CI build failed with:

Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>? (74:5)

Root cause: The "Dynamic permission changes" example at readonly-connections.mdx:252-331 had a single TypeScriptExample code block containing both a TypeScript class (GameAgent with @callable() decorators and Agent<Env, GameState> generics) and a React component (GameComponent with JSX). The TypeScriptExample component strips TypeScript types using ts-blank-space then formats with prettier's babel parser. When the generics were stripped and the decorator syntax combined with JSX in the same code unit, prettier's parser failed to correctly parse the resulting JavaScript.

Fix: Split the single code block into two separate TypeScriptExample blocks:

  1. Server-side GameAgent class (```ts) - no JSX, decorators + generics only
  2. Client-side GameComponent function (```tsx) - JSX only, no decorators or generics

This follows the same pattern used elsewhere in the agents docs (e.g., routing.mdx uses tsx for JSX examples, client-sdk.mdx keeps JSX examples simple and separate).

github run

@elithrar
Copy link
Copy Markdown
Collaborator

elithrar commented Feb 8, 2026

/bonk still failing. Investigate the build issues and run astro check to make sure the touched file is still valid

TypeScriptExample uses ts-blank-space to strip TypeScript types, but
ts-blank-space doesn't understand JSX syntax — it misinterprets JSX
tags as generics, 'as' in JSX text as type assertions, and '!' as
non-null assertions. This caused:

1. GameComponent block: <div> tag blanked out entirely, breaking
   Prettier's babel parser with 'Adjacent JSX elements' error
2. EditButton block: !canEdit silently corrupted to canEdit in the
   generated JavaScript tab

Fix by removing the TypeScriptExample wrapper from these two JSX
blocks, using plain fenced tsx code blocks instead (matching the
pattern used in quick-start.mdx and guides/webhooks.mdx).
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Feb 8, 2026

Summary

The build was failing because two JSX code blocks were wrapped in <TypeScriptExample>, which processes code through ts-blank-space + Prettier's babel parser. This pipeline doesn't support JSX:

Root cause: ts-blank-space treats JSX syntax as TypeScript constructs:

  • <div> → interpreted as a generic type comparison, blanked out entirely
  • as Player in "Join as Player" → interpreted as as type assertion, blanked out
  • !canEdit → interpreted as non-null assertion operator, blanked out

Two blocks fixed in readonly-connections.mdx:

  1. GameComponent (was line ~294): The <div> tag being blanked caused Prettier to see adjacent closing JSX elements without matching openers → build-breaking parse error
  2. EditButton (was line ~418): disabled={!canEdit} silently became disabled={ canEdit} in the JavaScript tab — semantically wrong (inverted logic)

Fix: Removed the <TypeScriptExample> wrapper from both blocks, using plain ```tsx fenced code blocks instead. This follows the same pattern used in getting-started/quick-start.mdx and guides/webhooks.mdx for React component examples.

Validation:

  • astro check: 0 errors, 0 warnings
  • All 12 remaining <TypeScriptExample> blocks verified through the ts-blank-space + Prettier pipeline

github run

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 8, 2026

@elithrar elithrar merged commit 80079b4 into production Feb 8, 2026
9 checks passed
@elithrar elithrar deleted the sync-docs-pr-610 branch February 8, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:agents Build and deploy AI-powered Agents on Cloudflare that can act autonomously. size/l

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants