Skip to content

Invalidate query cache on disconnect to fix stale auth tokens#28084

Open
agents-git-bot[bot] wants to merge 3 commits intoproductionfrom
sync-docs-pr-839
Open

Invalidate query cache on disconnect to fix stale auth tokens#28084
agents-git-bot[bot] wants to merge 3 commits intoproductionfrom
sync-docs-pr-839

Conversation

@agents-git-bot
Copy link
Contributor

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

Summary

Documents the automatic query cache invalidation behavior when using async query functions with the useAgent React hook. This documentation update corresponds to cloudflare/agents#839.

Changes

  • Added comprehensive documentation on using async query functions with useAgent
  • Documented automatic cache invalidation on WebSocket disconnect
  • Explained how this prevents authentication failures from stale cached tokens
  • Documented the cacheTtl option for customizing cache duration

Problem

When using useAgent with an async query function for authentication, cached query results were reused on reconnect even if tokens had expired. This caused authentication failures after disconnect/reconnect cycles.

Solution

The SDK now automatically invalidates the query cache when the WebSocket connection closes, ensuring fresh authentication tokens are fetched on reconnect. This documentation helps developers understand this behavior.

Related to cloudflare/agents#836


Source PR: cloudflare/agents#839
Synced from: cloudflare/agents repository

github-actions bot and others added 3 commits February 4, 2026 12:16
Updates documentation to reflect that useAgent automatically invalidates
the query cache when the WebSocket connection closes. This ensures that
async query functions (e.g., for fetching auth tokens) are re-executed
on reconnect, providing fresh tokens after network interruptions.

Changes:
- Added missing query, queryDeps, cacheTtl, and other parameters to UseAgentOptions type
- Added dedicated section on authentication with async query functions
- Added client-side authentication example in calling-agents.mdx
- Documented automatic token refresh behavior on reconnection

Related to cloudflare/agents#839
Extends the useAgent return type documentation to include:
- agent: The agent class name in kebab-case
- name: The agent instance name
- identified: Whether agent identity has been received
- ready: Promise that resolves when identity is received
- call: Method for calling Agent methods with RPC
- stub: Stub object for direct Agent method calls

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Documents the cache invalidation behavior when WebSocket connections close,
ensuring users understand that async query functions are re-executed on reconnect.

This change corresponds to PR #839 in cloudflare/agents which fixes stale
auth token issues by invalidating the query cache on disconnect.

Adds documentation for:
- Using static and async query parameters for authentication
- Cache invalidation behavior on connection close
- cacheTtl option for controlling cache duration

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@github-actions github-actions bot added product:agents Build and deploy AI-powered Agents on Cloudflare that can act autonomously. size/m labels Feb 4, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 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

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/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants