fix: AI Conversations input/output correlation (0.2.11 + 0.2.12)#24
Merged
Conversation
Synthetic user-line triples for client-only slash commands (/model, /clear) inflated transcript-reader's real-turn index, drifting off-by-N from the collector's turnIndex. With UserPromptSubmit lacking prompt_id, ordinal fallback returned the wrong turn — early turns lost outputs entirely, later turns carried earlier turns' responses. Pre-pass now marks any prompt_id with <local-command-*> content as client-only and skips those user lines (plus isMeta:true). Also accept camelCase promptId as defense-in-depth. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
7192022 to
e8f2529
Compare
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
Two related fixes to make Sentry AI Conversations show the right input/output pair per turn.
Stophook now closes the current turn so the transcript JSONL flush race doesn't dropgen_ai.output.messages; late-flush retry now triggers whenrecordOutputsis on andresponseisnull; synthesized sessions refuse ordinal matches.transcript-reader's real-turn index with whatUserPromptSubmitactually counts.0.2.12 root cause
Claude Code's transcript records client-only slash commands (
/model,/clear) as a synthetic user-line triple (<local-command-caveat>+<command-name>+<local-command-stdout>), but never firesUserPromptSubmitfor them. The transcript reader was treating each of those lines as a real turn, so the collector'sturnIndex(incremented perUserPromptSubmit) drifted off-by-N from transcript ordinals. RealUserPromptSubmithook events don't carryprompt_id, soselectTurnfell back to ordinal — and the ordinal pointed to the wrong transcript turn.Visible symptoms (conversation
9763be13-…, span9d1cb6a39ecde5ba):gen_ai.input.messagesset, nogen_ai.output.messages,claude_code.usage_extraction.status = turn_had_no_usagegen_ai.output.messagespresent but it was an earlier turn's responseFix
src/transcript-reader.ts: pre-pass marks everyprompt_idthat has any<local-command-*>content as client-only; main loop skipsisMeta:truelines, client-only-pid lines, and bare<local-command-*>lines.src/server.ts+src/types.ts: accept camelCasepromptIdonUserPromptSubmitevents as defense-in-depth alongsideprompt_id.Test plan
tests/transcript-reader.test.tsreproduces the off-by-N with a/modelsynthetic triple followed by two real prompts; passes after the fix.tsc --noEmitclean./modelmid-conversation and confirm in Sentry AI Conversations that each turn's input matches its output.🤖 Generated with Claude Code