Skip to content

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

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

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
@dcramer
Copy link
Copy Markdown
Member

dcramer commented May 23, 2026

Superseded by #412. The replacement keeps GenAI span messages faithful to the actual model transcript and removes non-causal prompt context at assembly time instead of cleaning span payloads for display.

@dcramer dcramer closed this May 23, 2026
dcramer added a commit that referenced this pull request May 23, 2026
Keep model-visible prompt context causal and non-duplicative. This
supersedes GH-404 by fixing prompt assembly instead of cleaning span
payloads for display.

**Runtime Context**

User turns keep causal runtime identifiers in `<runtime-turn-context>`,
including `gen_ai.conversation.id` and the active `trace_id`, so the bot
can correlate its own turn with telemetry and debug data. Internal model
names, synthetic channel labels, Slack capability summaries,
thinking-level routing metadata, runtime version, and duplicate sandbox
paths are no longer exposed in the prompt.

**Prompt Shape**

Empty capabilities, context, runtime, and loaded-skill blocks are
omitted instead of emitted as placeholder markup. When thread background
is needed, it remains a top-level sibling block next to the current
instruction.

**Thread History**

When Pi history already carries prior messages, the fresh prompt
continues to omit the Slack transcript background so previous user
messages are not duplicated.

Supersedes GH-404

---------

Co-authored-by: OpenAI GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <gpt-5-codex@openai.com>
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