Invalidate query cache on disconnect to fix stale auth tokens#28084
Open
agents-git-bot[bot] wants to merge 3 commits intoproductionfrom
Open
Invalidate query cache on disconnect to fix stale auth tokens#28084agents-git-bot[bot] wants to merge 3 commits intoproductionfrom
agents-git-bot[bot] wants to merge 3 commits intoproductionfrom
Conversation
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>
Contributor
|
This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Documents the automatic query cache invalidation behavior when using async query functions with the
useAgentReact hook. This documentation update corresponds to cloudflare/agents#839.Changes
useAgentcacheTtloption for customizing cache durationProblem
When using
useAgentwith 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