Skip to content

fix(tracing): Strip runtime turn context from observable input messages#404

Open
sergical wants to merge 1 commit into
mainfrom
fix/strip-runtime-context-from-observable-messages
Open

fix(tracing): Strip runtime turn context from observable input messages#404
sergical wants to merge 1 commit into
mainfrom
fix/strip-runtime-context-from-observable-messages

Conversation

@sergical
Copy link
Copy Markdown
Member

@sergical sergical commented May 22, 2026

Summary

  • Strips <runtime-turn-context> content parts from user messages before serializing to gen_ai.input.messages on gen_ai.chat spans.
  • Unwraps <current-instruction> to extract just the user's actual text.
  • Strips <thread-background>, <session-context>, <turn-context> blocks so prior assistant responses don't bleed into user messages.

After this change, the Conversations view shows clean user messages instead of internal runtime metadata.

Context

The Sentry Conversations view reads gen_ai.input.messages from gen_ai.chat spans and extracts user messages via messages.findLast(m => m.role === 'user'). Junior's user messages contained:

  1. A <runtime-turn-context> content part with skills, config, and capabilities (separate content part — now dropped)
  2. XML wrappers around the user text: <thread-background> (prior conversation history including assistant responses), <session-context>, <turn-context>, and <current-instruction> (now unwrapped/stripped)

The runtime context is still available via gen_ai.system_instructions on the span, so no observability is lost.

Test plan

  • Unit test: verifies all XML blocks are stripped and only user instruction text remains
  • Existing traced-stream tests pass (9/9)
  • Typecheck passes
  • Verify clean user messages in Conversations view after deploy

🤖 Generated with Claude Code

@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
junior-docs Ready Ready Preview, Comment May 22, 2026 7:18pm

Request Review

…input messages

The `gen_ai.input.messages` attribute on `gen_ai.chat` spans included
internal runtime metadata and XML wrapper blocks as part of user message
content. The Sentry Conversations view reads this attribute and renders
it as the user message.

Clean user messages before serializing to `gen_ai.input.messages`:
1. Drop `<runtime-turn-context>` content parts (skills, config, capabilities).
2. Unwrap `<current-instruction>` to extract the actual user text.
3. Strip `<thread-background>`, `<session-context>`, `<turn-context>` blocks
   so prior assistant responses don't bleed into user messages.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dcramer
Copy link
Copy Markdown
Member

dcramer commented May 22, 2026

im not totally understanding of the problem

i dont want the messages being sent to sentry to be at all different than the actual messages sent upstream, but if we have a giant xml tag wrapping everything thats probably some minor cleanup to be done (i havent hand audited the prompt)

@sergical
Copy link
Copy Markdown
Member Author

sergical commented May 22, 2026

maybe a non issue, when i look at it, i see duplication between content on subsequent user turns via the xml tags, but idk if thats just the expected ux or we can clean it up a bit 🤷
CleanShot 2026-05-22 at 15 44 17@2x
Mostly created as a draft to share with Ogi and see what their feedback is like

@dcramer
Copy link
Copy Markdown
Member

dcramer commented May 22, 2026

do you mean in the thread transcript bits? if there is i def think this is more of a bug in the context gathering than a need for a change in reporting

definitely the reporting should never falsify records

@dcramer dcramer marked this pull request as ready for review May 22, 2026 21:40
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