fix(frontend): render tool message body in tracing beautified view#4484
Conversation
When a chat span's `role: "tool"` message had a JSON-string `content` that
parsed to an array of envelopes the renderer didn't recognize (e.g. the
`[{response: [{type: "text", text: ...}]}]` shape some tool integrations
emit), `getMessageContentDisplay` consumed the array as "parts" but
extracted no text or structured parts, leaving the bubble blank.
Add a fallback inside `getMessageContentDisplay`: when parts processing
yields nothing usable, route the original payload through `getMessageText`
so `text` is repopulated. The existing `parsedContent` branch in
`MessageNodeRow` then JSON-parses it and renders the tool result via
`RecursiveNode` + `simplifyValue`.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughA single fallback guard was added to ChangesMessage Content Display Fallback
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Railway Preview Environment
|
Symptom
In the Tracing Drawer's Beautified view, a chat span containing a
role: \"tool\"message would show the role label bubble but no body — even whencontentwas clearly populated.Reproducing trace (the user's example): a
toolmessage whosecontentis a JSON-stringified array of{response: [{type: \"text\", text: \"...\"}, ...]}envelopes (the retrieval result returned from a custom vector-store tool). Nothing rendered under the bubble.Root cause
In
web/oss/src/components/DrillInView/BeautifiedJsonView.tsx:getMessageContentDisplaycallsgetMessageContentParts. Becausecontentwas a JSON-stringified array,tryParseJsonStringsucceeded and returned the parsed array asparts.{response: [...]}had no recognized envelope (type: \"text\",type: \"tool-result\", etc.) and no top-leveltext/contentstring — sogetStructuredMessagePartandgetMessagePartTextreturnednull.getMessageContentDisplayreturned{text: \"\", structuredParts: []}— the raw string was discarded.MessageNodeRow,parsedContentshort-circuits on emptytext, and the body's!hasText && !hasToolCalls && !hasStructuredPartsguard returnednull.Fix
One added fallback inside
getMessageContentDisplay: when parts processing produces no text and no structured parts, route the originalcontentthroughgetMessageText. That repopulatestextwith the raw JSON string. The existingparsedContentbranch inMessageNodeRowthen JSON-parses it and renders the result viaRecursiveNode+simplifyValue(which already unwraps the inner{type: \"text\", text: \"...\"}parts into readable strings).Before / after
Test plan
role: \"tool\"message whosecontentis a JSON-stringified array of unknown envelopes (e.g. RAG retrieval result). Switch to Beautified view. Body now renders.tool_callsstill renders the tool-call list.tool-resultenvelope ({type: \"tool-result\", output: {...}}) still hits the structured-parts path (not the new fallback).Notes
BeautifiedJsonView.tsxlives in the app layer (web/oss/src/components/DrillInView/) and has no existing unit-test suite, so this was verified by code reading + lint; no test was added.