feat(v10/cloudflare): Rotate agent conversation id on chat clear - #22787
Open
JPeer264 wants to merge 1 commit into
Open
feat(v10/cloudflare): Rotate agent conversation id on chat clear#22787JPeer264 wants to merge 1 commit into
JPeer264 wants to merge 1 commit into
Conversation
Contributor
size-limit report 📦
|
JPeer264
force-pushed
the
jp/v10-backport-agent-conversation-id
branch
from
July 28, 2026 18:34
163c642 to
f34539e
Compare
JPeer264
marked this pull request as ready for review
July 28, 2026 18:39
JPeer264
requested review from
andreiborza and
isaacs
and removed request for
a team
July 28, 2026 18:39
| // surface. We shadow it with an own property so the original stays reachable on the prototype. | ||
| const originalEmit = obj._emit; | ||
|
|
||
| if (typeof originalEmit === 'function') { |
Contributor
There was a problem hiding this comment.
Bug: The conversation ID rotation relies on an unverified message:clear event name. If this name is incorrect, the feature will silently fail to work as intended.
Severity: MEDIUM
Suggested Fix
Verify the correct event name that is emitted by the Cloudflare agents package when a chat is cleared. This can be confirmed by inspecting the package's source code, reviewing the original PR #22720 that was backported, or by performing integration testing. Update the hardcoded 'message:clear' string if it is incorrect.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location:
packages/cloudflare/src/instrumentations/agents/instrumentChatAgentConversation.ts#L30
Potential issue: The instrumentation for `AIChatAgent` proxies the internal `_emit`
method to detect when a chat conversation is cleared. It listens for a `message:clear`
event to rotate the `__sentryConversationId`. However, it is unverified whether
`message:clear` is the correct event name emitted by the `@cloudflare/ai-chat` package.
If the actual event name is different, the ID rotation logic will never be triggered,
resulting in a silent failure of this feature. The application will not crash, but
conversation IDs will not be rotated as intended when a chat is cleared.
Did we get this right? 👍 / 👎 to inform future reviews.
logaretm
approved these changes
Jul 28, 2026
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.
Backport of: #22720