Skip to content

feat(v10/cloudflare): Rotate agent conversation id on chat clear - #22787

Open
JPeer264 wants to merge 1 commit into
jp/v10-backport-instrument-agentfrom
jp/v10-backport-agent-conversation-id
Open

feat(v10/cloudflare): Rotate agent conversation id on chat clear#22787
JPeer264 wants to merge 1 commit into
jp/v10-backport-instrument-agentfrom
jp/v10-backport-agent-conversation-id

Conversation

@JPeer264

Copy link
Copy Markdown
Member

Backport of: #22720

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.76 kB added added
@sentry/browser - with treeshaking flags 26.2 kB added added
@sentry/browser (incl. Tracing) 46.6 kB added added
@sentry/browser (incl. Tracing + Span Streaming) 48.39 kB added added
@sentry/browser (incl. Tracing, Profiling) 51.36 kB added added
@sentry/browser (incl. Tracing, Replay) 85.85 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.48 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 90.56 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 103.21 kB added added
@sentry/browser (incl. Feedback) 44.93 kB added added
@sentry/browser (incl. sendFeedback) 32.55 kB added added
@sentry/browser (incl. FeedbackAsync) 37.69 kB added added
@sentry/browser (incl. Metrics) 28.84 kB added added
@sentry/browser (incl. Logs) 29.07 kB added added
@sentry/browser (incl. Metrics & Logs) 29.77 kB added added
@sentry/react 29.56 kB added added
@sentry/react (incl. Tracing) 48.87 kB added added
@sentry/vue 33.19 kB added added
@sentry/vue (incl. Tracing) 48.56 kB added added
@sentry/svelte 27.79 kB added added
CDN Bundle 30.16 kB added added
CDN Bundle (incl. Tracing) 48.56 kB added added
CDN Bundle (incl. Logs, Metrics) 31.73 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 49.86 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 71 kB added added
CDN Bundle (incl. Tracing, Replay) 86.06 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.37 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 91.86 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 93.13 kB added added
CDN Bundle - uncompressed 89.91 kB added added
CDN Bundle (incl. Tracing) - uncompressed 146.79 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.62 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 150.77 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 219.38 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.02 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 269.99 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.73 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 283.68 kB added added
@sentry/nextjs (client) 51.41 kB added added
@sentry/sveltekit (client) 47.02 kB added added
@sentry/core/server 80.44 kB added added
@sentry/core/browser 66.78 kB added added
@sentry/node-core 63.26 kB added added
@sentry/node 125.9 kB added added
@sentry/node (incl. diagnostics channel injection) 151.33 kB added added
@sentry/node/import (ESM hook with diagnostics-channel injection) 70.03 kB added added
@sentry/node/light 51.42 kB added added
@sentry/node - without tracing 74.95 kB added added
@sentry/aws-serverless 84.22 kB added added
@sentry/cloudflare (withSentry) - minified 199.31 kB added added
@sentry/cloudflare (withSentry) 490.07 kB added added

@JPeer264
JPeer264 force-pushed the jp/v10-backport-agent-conversation-id branch from 163c642 to f34539e Compare July 28, 2026 18:34
@JPeer264
JPeer264 marked this pull request as ready for review July 28, 2026 18:39
@JPeer264
JPeer264 requested a review from a team as a code owner July 28, 2026 18:39
@JPeer264
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') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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.

2 participants