:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(llma): Cleanup from previous PR (#61104)
Marcel Poelkerf22f56c6892e
diff --git a/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.test.ts b/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.test.tsindex 1cc3258be809..66a75c5e2da4 100644--- a/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.test.ts+++ b/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.test.ts@@ -120,20 +120,20 @@ describe('unrenderableContentKinds', () => {})})-describe('buildStreamItems — scaffold detection + grouping', () => {+describe('buildStreamItems — internal tag detection + grouping', () => {const userText = (text: string): CompatMessage => ({ role: 'user', content: text })- const userTypedScaffold = (text: string): CompatMessage => ({+ const userTypedInternal = (text: string): CompatMessage => ({role: 'user',content: [{ type: 'text', text }] as unknown as CompatMessage['content'],})const assistant = (text: string): CompatMessage => ({ role: 'assistant', content: text })- it('returns plain bubbles for a non-scaffold conversation', () => {+ it('returns plain bubbles for a conversation with no internal tags', () => {const items = buildStreamItems([userText('Hi there'), assistant('Hello')])expect(items.map((i) => i.kind)).toEqual(['bubble', 'bubble'])})- it('groups a single scaffold-only user message into a one-pill group', () => {+ it('groups a single internal-tag-only user message into a one-pill group', () => {const items = buildStreamItems([userText('<system_reminder>foo</system_reminder>')])expect(items).toHaveLength(1)expect(items[0].kind).toBe('internal-group')@@ -143,13 +143,13 @@ describe('buildStreamItems — scaffold detection + grouping', () => {}})- it('groups consecutive scaffold messages into a single pill', () => {- // Four scaffold messages, then the user's real question.+ it('groups consecutive internal tag messages into a single pill', () => {+ // Four internal tag messages, then the user's real question.const items = buildStreamItems([- userTypedScaffold('<system_reminder>foo</system_reminder>'),- userTypedScaffold('<system_reminder>\nbar\n</system_reminder>'),- userTypedScaffold('<voice_mode>off</voice_mode>'),- userTypedScaffold('<attached_context>\nbaz\n</attached_context>'),+ userTypedInternal('<system_reminder>foo</system_reminder>'),+ userTypedInternal('<system_reminder>\nbar\n</system_reminder>'),+ userTypedInternal('<voice_mode>off</voice_mode>'),+ userTypedInternal('<attached_context>\nbaz\n</attached_context>'),userText('what changed?'),assistant('looking into it...'),])@@ -163,9 +163,9 @@ describe('buildStreamItems — scaffold detection + grouping', () => {}})- it('breaks grouping when a bubble interrupts the scaffold run', () => {- // [scaffold, bubble, scaffold] should produce TWO groups, not one — the- // pill marks chronological position, not "all scaffolds ever".+ it('breaks grouping when a bubble interrupts the internal tag run', () => {+ // [internal, bubble, internal] should produce TWO groups, not one — the+ // pill marks chronological position, not "all internal tags ever".const items = buildStreamItems([userText('<system_reminder>a</system_reminder>'),userText('first question'),@@ -175,22 +175,22 @@ describe('buildStreamItems — scaffold detection + grouping', () => {expect(items.map((i) => i.kind)).toEqual(['internal-group', 'bubble', 'internal-group', 'bubble'])})- it('does not classify an assistant-role wrapper as scaffold (models can emit `<system_reminder>` in output)', () => {+ it('does not classify an assistant-role wrapper as internal (models can emit `<system_reminder>` in output)', () => {const items = buildStreamItems([userText('hi'),- // Unusual but legal: an assistant reply that contains a scaffold-looking wrapper. Render it.+ // Unusual but legal: an assistant reply that contains an internal-tag-looking wrapper. Render it.{ role: 'assistant', content: '<system_reminder>foo</system_reminder>' },])expect(items.map((i) => i.kind)).toEqual(['bubble', 'bubble'])})- it('does not classify a wrapper-plus-extra-text user message as scaffold', () => {+ it('does not classify a wrapper-plus-extra-text user message as internal', () => {// User wrote actual text — we'd lose information by hiding it.const items = buildStreamItems([userText('foo <system_reminder>bar</system_reminder> baz')])expect(items.map((i) => i.kind)).toEqual(['bubble'])})- it('does not classify unrelated wrapper tags as scaffold', () => {+ it('does not classify unrelated wrapper tags as internal', () => {// `<thinking>` and friends are not in the allowlist — models can emit them as visible content.const items = buildStreamItems([userText('<thinking>foo</thinking>'),@@ -200,12 +200,12 @@ describe('buildStreamItems — scaffold detection + grouping', () => {expect(items.map((i) => i.kind)).toEqual(['bubble', 'bubble', 'bubble'])})- it('drops `system`-role messages entirely (HIDDEN_ROLES) before scaffold classification', () => {+ it('drops `system`-role messages entirely (HIDDEN_ROLES) before internal tag classification', () => {const items = buildStreamItems([{ role: 'system', content: 'You are an assistant.' }, userText('hello')])expect(items.map((i) => i.kind)).toEqual(['bubble'])})- it('keeps a single scaffold sandwiched between bubbles intact (no merging across bubbles)', () => {+ it('keeps a single internal tag message sandwiched between bubbles intact (no merging across bubbles)', () => {const items = buildStreamItems([userText('first'),userText('<system_reminder>x</system_reminder>'),@@ -278,7 +278,7 @@ describe('buildStreamItems — internal messages (thinking, tool_result) collapsexpect(items.map((i) => i.kind)).toEqual(['bubble', 'internal-group', 'bubble', 'internal-group', 'bubble'])})- it('coalesces a scaffold + thinking + tool_result run into a single pill', () => {+ it('coalesces an internal tag + thinking + tool_result run into a single pill', () => {const items = buildStreamItems([userText('<system_reminder>be concise</system_reminder>'),thinking('let me think'),@@ -349,47 +349,48 @@ describe('buildStreamItems — internal messages (thinking, tool_result) collapsit('preserves the role of the first hidden message on the group (alignment is label-based; role kept for analytics)', () => {const items = buildStreamItems([thinking('first reasoning step')])- expect(items).toHaveLength(1)+ expect(items.map((i) => i.kind)).toEqual(['internal-group'])if (items[0].kind === 'internal-group') {expect(items[0].role).toBe('assistant (thinking)')}})- it('groups Anthropic typed tool_result parts under the `tool_result` label (renders agent-side)', () => {- const userToolResultBlob: CompatMessage = {- role: 'user',- content: [- { type: 'tool_result', tool_use_id: 't1', content: 'row 1' },- { type: 'tool_result', tool_use_id: 't2', content: 'row 2' },- ] as unknown as CompatMessage['content'],- }- const items = buildStreamItems([userToolResultBlob])- if (items[0].kind === 'internal-group') {- expect(items[0].labels.every((l) => l === 'tool_result')).toBe(true)- }- })-- it('groups custom function-shape user-role tool_result under the `tool_result` label', () => {- const userFunctionResult: CompatMessage = {- role: 'user',- content: [- {- type: 'function',- tool_name: 'fetch_account_context',- content: '<current_account_data>...</current_account_data>',- },- ] as unknown as CompatMessage['content'],- }- const items = buildStreamItems([userFunctionResult])- if (items[0].kind === 'internal-group') {- expect(items[0].labels).toEqual(['tool_result'])- }- })-- it('groups scaffold tags under their tag-name label (renders user-side)', () => {- const items = buildStreamItems([{ role: 'user', content: '<system_reminder>foo</system_reminder>' }])+ it.each<[name: string, message: CompatMessage, expectedLabels: string[]]>([+ [+ 'Anthropic typed tool_result parts (renders agent-side)',+ {+ role: 'user',+ content: [+ { type: 'tool_result', tool_use_id: 't1', content: 'row 1' },+ { type: 'tool_result', tool_use_id: 't2', content: 'row 2' },+ ] as unknown as CompatMessage['content'],+ },+ ['tool_result'],+ ],+ [+ 'custom function-shape user-role tool_result',+ {+ role: 'user',+ content: [+ {+ type: 'function',+ tool_name: 'fetch_account_context',+ content: '<current_account_data>...</current_account_data>',+ },+ ] as unknown as CompatMessage['content'],+ },+ ['tool_result'],+ ],+ [+ 'internal tags under their tag-name label (renders user-side)',+ { role: 'user', content: '<system_reminder>foo</system_reminder>' },+ ['system_reminder'],+ ],+ ])('groups a single message into one internal-group: %s', (_, message, expectedLabels) => {+ const items = buildStreamItems([message])+ expect(items.map((i) => i.kind)).toEqual(['internal-group'])if (items[0].kind === 'internal-group') {- expect(items[0].labels).toEqual(['system_reminder'])+ expect(items[0].labels).toEqual(expectedLabels)}})})diff --git a/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.tsx b/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.tsxindex 0c88d52ae632..d818e9ff187d 100644--- a/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.tsx+++ b/products/ai_observability/frontend/ConversationDisplay/TranscriptBubbleStream.tsx@@ -14,7 +14,7 @@ import {extractInternalContent,extractText,extractTextContent,- getScaffoldTagName,+ getInternalTagName,isInternalToolResultUserMessage,isToolStepItem,} from '../utils'@@ -76,7 +76,7 @@ export function captureUnrenderableMessageOnce(message: CompatMessage, seen: Set// An item in the rendered transcript stream. Bubbles render as `MessageTemplate`s.// Internal groups render as a single collapsed pill where the hidden messages// would have sat — preserving chronological position without polluting the chat.-// "Internal" covers framework prompt scaffolds, model reasoning/thinking parts,+// "Internal" covers framework prompt tag wrappers, model reasoning/thinking parts,// and tool-call results — anything the user didn't write and didn't ask to see.type StreamItem =| { kind: 'bubble'; message: CompatMessage; text: string; nonText: boolean }@@ -95,9 +95,9 @@ function getInternalLabel(message: CompatMessage): string | undefined {if (message.role === INTERNAL_TOOL_RESULT_ROLE) {return 'tool_result'}- const scaffoldTag = getScaffoldTagName(message)- if (scaffoldTag !== undefined) {- return scaffoldTag+ const internalTag = getInternalTagName(message)+ if (internalTag !== undefined) {+ return internalTag}if (isInternalToolResultUserMessage(message)) {return 'tool_result'@@ -169,7 +169,7 @@ export function buildStreamItems(messages: CompatMessage[]): StreamItem[] {* right, everything else (assistant, tool responses, etc.) on the left. Skips* `system` and `available tools` pseudo-messages; their context is implicit in* the assistant's reply and reachable via the per-turn "Show steps" panel.- * Framework prompt-scaffold messages (e.g. `<system_reminder>...`) are collapsed.+ * Framework prompt tag-wrapper messages (e.g. `<system_reminder>...`) are collapsed.** Deliberately minimal otherwise: no headers, no per-message expand toggles, no* metadata row, no playground button. The Trace page's `ConversationMessagesDisplay`diff --git a/products/ai_observability/frontend/utils.test.ts b/products/ai_observability/frontend/utils.test.tsindex ee353f843aa1..317ed75b7d88 100644--- a/products/ai_observability/frontend/utils.test.ts+++ b/products/ai_observability/frontend/utils.test.ts@@ -8,7 +8,7 @@ import {costContextFromTrace,formatAiErrorForDisplay,formatLLMEventTitle,- getScaffoldTagName,+ getInternalTagName,getSessionID,getSessionStartTimestamp,getToolNamesCalled,@@ -17,7 +17,7 @@ import {isEmptyJSONStructure,isInternalToolResultUserMessage,isLangChainMessage,- isInternalScaffoldMessage,+ isInternalTagMessage,isTextContentItem,isToolResult,isToolStepItem,@@ -1153,9 +1153,9 @@ describe.each(IMPLS)('AI observability utils [$name]', ({ normalizeMessage, norm})})- describe('getScaffoldTagName / isInternalScaffoldMessage', () => {+ describe('getInternalTagName / isInternalTagMessage', () => {// The shape these tests pin: typed-parts content with a single text item- // whose entire body is a balanced scaffold wrapper.+ // whose entire body is a balanced internal tag wrapper.const typedParts = (text: string): CompatMessage['content'] =>[{ type: 'text', text }] as unknown as CompatMessage['content']@@ -1175,15 +1175,15 @@ describe.each(IMPLS)('AI observability utils [$name]', ({ normalizeMessage, norm],['flat string with voice_mode', '<voice_mode>off</voice_mode>', 'voice_mode'],[- 'multi-line scaffold body',+ 'multi-line internal tag body','<system_reminder>\nyou are an agent\nmode: foo\n</system_reminder>','system_reminder',],['leading/trailing whitespace tolerated', ' \n<voice_mode>off</voice_mode>\n ', 'voice_mode'],])('returns the tag name for: %s', (_, body, expected) => {const message: CompatMessage = { role: 'user', content: body }- expect(getScaffoldTagName(message)).toBe(expected)- expect(isInternalScaffoldMessage(message)).toBe(true)+ expect(getInternalTagName(message)).toBe(expected)+ expect(isInternalTagMessage(message)).toBe(true)})it('matches the typed-parts shape (single text item)', () => {@@ -1191,7 +1191,7 @@ describe.each(IMPLS)('AI observability utils [$name]', ({ normalizeMessage, normrole: 'user',content: typedParts('<system_reminder>be concise</system_reminder>'),}- expect(getScaffoldTagName(message)).toBe('system_reminder')+ expect(getInternalTagName(message)).toBe('system_reminder')})it('matches the {type, content: string} wrapper shape (Vercel SDK legacy)', () => {@@ -1202,18 +1202,18 @@ describe.each(IMPLS)('AI observability utils [$name]', ({ normalizeMessage, normcontent: '<system-reminder>foo</system-reminder>',} as unknown as CompatMessage['content'],}- expect(getScaffoldTagName(message)).toBe('system-reminder')+ expect(getInternalTagName(message)).toBe('system-reminder')})// ---- negative cases: role gate ----- it('returns undefined for an assistant-role message even with a scaffold wrapper', () => {+ it('returns undefined for an assistant-role message even with an internal tag wrapper', () => {// Models can legitimately emit `<system_reminder>` in their reply. Don't hide.const message: CompatMessage = {role: 'assistant',content: '<system_reminder>foo</system_reminder>',}- expect(getScaffoldTagName(message)).toBeUndefined()+ expect(getInternalTagName(message)).toBeUndefined()})it('returns undefined for a system-role message (system messages are filtered upstream anyway)', () => {@@ -1221,7 +1221,7 @@ describe.each(IMPLS)('AI observability utils [$name]', ({ normalizeMessage, normrole: 'system',content: '<system_reminder>foo</system_reminder>',}- expect(getScaffoldTagName(message)).toBeUndefined()+ expect(getInternalTagName(message)).toBeUndefined()})// ---- negative cases: allowlist gate ----@@ -1239,8 +1239,8 @@ describe.each(IMPLS)('AI observability utils [$name]', ({ normalizeMessage, norm['HTML structural <code>', '<code>print("hi")</code>'],])('returns undefined for non-allowlisted tag: %s', (_, body) => {const message: CompatMessage = { role: 'user', content: body }- expect(getScaffoldTagName(message)).toBeUndefined()- expect(isInternalScaffoldMessage(message)).toBe(false)+ expect(getInternalTagName(message)).toBeUndefined()+ expect(isInternalTagMessage(message)).toBe(false)})// ---- negative cases: shape gate ----@@ -1251,7 +1251,7 @@ describe.each(IMPLS)('AI observability utils [$name]', ({ normalizeMessage, normrole: 'user',content: 'foo <system_reminder>bar</system_reminder>',}- expect(getScaffoldTagName(message)).toBeUndefined()+ expect(getInternalTagName(message)).toBeUndefined()})it('returns undefined when text content has trailing text after the wrapper', () => {@@ -1259,7 +1259,7 @@ describe.each(IMPLS)('AI observability utils [$name]', ({ normalizeMessage, normrole: 'user',content: '<system_reminder>foo</system_reminder> bar',}- expect(getScaffoldTagName(message)).toBeUndefined()+ expect(getInternalTagName(message)).toBeUndefined()})it('returns undefined when content has two sibling wrappers (multi-block, not single)', () => {@@ -1268,11 +1268,11 @@ describe.each(IMPLS)('AI observability utils [$name]', ({ normalizeMessage, normcontent: '<system_reminder>foo</system_reminder>\n<voice_mode>off</voice_mode>',}// Conservative — coalescing multi-wrapper bodies is out of scope.- expect(getScaffoldTagName(message)).toBeUndefined()+ expect(getInternalTagName(message)).toBeUndefined()})it('returns undefined for typed-parts with more than one item', () => {- // Two text items, even if each is itself a scaffold wrapper. The renderer+ // Two text items, even if each is itself an internal tag wrapper. The renderer// would lose information if we collapsed this; keep it visible.const message: CompatMessage = {role: 'user',@@ -1281,7 +1281,7 @@ describe.each(IMPLS)('AI observability utils [$name]', ({ normalizeMessage, norm{ type: 'text', text: '<voice_mode>off</voice_mode>' },] as unknown as CompatMessage['content'],}- expect(getScaffoldTagName(message)).toBeUndefined()+ expect(getInternalTagName(message)).toBeUndefined()})it('returns undefined for typed-parts with a non-text item (image, tool_use, …)', () => {@@ -1289,14 +1289,14 @@ describe.each(IMPLS)('AI observability utils [$name]', ({ normalizeMessage, normrole: 'user',content: [{ type: 'image_url', image_url: { url: 'x' } }] as unknown as CompatMessage['content'],}- expect(getScaffoldTagName(message)).toBeUndefined()+ expect(getInternalTagName(message)).toBeUndefined()})// ---- negative cases: case-sensitivity + tag-mismatch guards ----- it('returns undefined for uppercase tag names (scaffold tags are lowercase by convention)', () => {+ it('returns undefined for uppercase tag names (internal tags are lowercase by convention)', () => {const message: CompatMessage = { role: 'user', content: '<System_Reminder>foo</System_Reminder>' }- expect(getScaffoldTagName(message)).toBeUndefined()+ expect(getInternalTagName(message)).toBeUndefined()})it('returns undefined when open and close tag names differ', () => {@@ -1305,13 +1305,13 @@ describe.each(IMPLS)('AI observability utils [$name]', ({ normalizeMessage, normrole: 'user',content: '<system_reminder>foo</voice_mode>',}- expect(getScaffoldTagName(message)).toBeUndefined()+ expect(getInternalTagName(message)).toBeUndefined()})it('returns undefined for empty content', () => {- expect(getScaffoldTagName({ role: 'user', content: '' })).toBeUndefined()- expect(getScaffoldTagName({ role: 'user', content: [] })).toBeUndefined()- expect(getScaffoldTagName({ role: 'user', content: null as unknown as string })).toBeUndefined()+ expect(getInternalTagName({ role: 'user', content: '' })).toBeUndefined()+ expect(getInternalTagName({ role: 'user', content: [] })).toBeUndefined()+ expect(getInternalTagName({ role: 'user', content: null as unknown as string })).toBeUndefined()})it('handles typed-parts content with a multi-line attached_context wrapper', () => {@@ -1319,7 +1319,7 @@ describe.each(IMPLS)('AI observability utils [$name]', ({ normalizeMessage, normrole: 'user',content: typedParts('<attached_context>\nfoo\n\nbar: baz\nqux: 123\n</attached_context>'),}- expect(getScaffoldTagName(message)).toBe('attached_context')+ expect(getInternalTagName(message)).toBe('attached_context')})})diff --git a/products/ai_observability/frontend/utils.ts b/products/ai_observability/frontend/utils.tsindex 0869eaf85ea0..0cdc46522f16 100644--- a/products/ai_observability/frontend/utils.ts+++ b/products/ai_observability/frontend/utils.ts@@ -499,9 +499,9 @@ export function isAnthropicToolCallMessage(output: unknown): output is Anthropicreturn !!output && typeof output === 'object' && 'type' in output && output.type === 'tool_use'}-// There are more tags that point to an internal-only scaffold message, but these are the most common+// There are more tags that point to an internal-only message, but these are the most common// ones, i.e. the ones we can most confidently hide by default.-const SCAFFOLD_TAG_ALLOWLIST: ReadonlySet<string> = new Set([+const INTERNAL_TAG_ALLOWLIST: ReadonlySet<string> = new Set(['system-reminder','system_reminder','system_reminder_message',@@ -511,7 +511,7 @@ const SCAFFOLD_TAG_ALLOWLIST: ReadonlySet<string> = new Set([// Regex for the case where an entire message body consists of exactly one balanced XML wrapper.// We don't accept content that contains multiple top-level wrappers nor leading/trailing text-const SCAFFOLD_WRAPPER_REGEX = /^\s*<([a-z][a-z0-9_-]*)>[\s\S]*?<\/\1>\s*$/+const INTERNAL_WRAPPER_REGEX = /^\s*<([a-z][a-z0-9_-]*)>[\s\S]*?<\/\1>\s*$/// Reduces content to a single text body (flat string, single typed-parts text part,// or legacy `{content: string}`); returns `undefined` for multi-part / unknown shapes.@@ -531,10 +531,10 @@ function extractSoleTextContent(content: CompatMessage['content']): string | undreturn undefined}-// Returns the matched scaffold tag iff `message` is a user-role message whose entire-// content is one balanced wrapper from `SCAFFOLD_TAG_ALLOWLIST` (e.g.+// Returns the matched internal tag iff `message` is a user-role message whose entire+// content is one balanced wrapper from `INTERNAL_TAG_ALLOWLIST` (e.g.// `<system_reminder>foo</system_reminder>`)-export function getScaffoldTagName(message: CompatMessage): string | undefined {+export function getInternalTagName(message: CompatMessage): string | undefined {if (message.role !== 'user') {return undefined}@@ -542,16 +542,16 @@ export function getScaffoldTagName(message: CompatMessage): string | undefined {if (!body) {return undefined}- const match = SCAFFOLD_WRAPPER_REGEX.exec(body)+ const match = INTERNAL_WRAPPER_REGEX.exec(body)if (!match) {return undefined}const tag = match[1]- return SCAFFOLD_TAG_ALLOWLIST.has(tag) ? tag : undefined+ return INTERNAL_TAG_ALLOWLIST.has(tag) ? tag : undefined}-export function isInternalScaffoldMessage(message: CompatMessage): boolean {- return getScaffoldTagName(message) !== undefined+export function isInternalTagMessage(message: CompatMessage): boolean {+ return getInternalTagName(message) !== undefined}// Matches tool-result-shaped content {type: 'function', tool_name: string, content: ...}`