Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(sessions): decode Unicode escapes in truncated I/O preview (#17519)

Nikita Kabardin8c70edf53e9f
diff --git a/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.clienttest.tsx b/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.clienttest.tsx
index 33c7cb9e21..553b8a8ca1 100644
--- a/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.clienttest.tsx
+++ b/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.clienttest.tsx
@@ -4,6 +4,7 @@ import { describe, expect, it, vi } from "vitest";
import { SessionConversationTimelineTrace } from "@/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace";
import { prepareSessionTimelineObservations } from "@/src/features/sessions/SessionConversationTimeline/fns/prepareSessionTimelineObservations";
+import { MarkdownContextProvider } from "@/src/features/theming/useMarkdownContext";
type TraceProps = ComponentProps<typeof SessionConversationTimelineTrace>;
type Observation = Extract<
@@ -136,4 +137,60 @@ describe("SessionConversationTimelineTrace", () => {
screen.queryByRole("button", { name: /tools: tool/i }),
).not.toBeInTheDocument();
});
+
+ it("decodes Unicode escapes in truncated observation previews", () => {
+ const truncated = prepareSessionTimelineObservations([
+ {
+ ...observation("gen", null, "GENERATION", new Date(0)),
+ input: '{"text":"\\u4f60\\u597d"}',
+ output: "\\u4f60\\u597d",
+ inputTruncated: true,
+ outputTruncated: true,
+ },
+ ]);
+
+ render(
+ <MarkdownContextProvider>
+ <SessionConversationTimelineTrace
+ trace={{ ...trace, observationCount: 1 }}
+ turnNumber={1}
+ state={{ type: "loaded", observations: truncated }}
+ onOpenTrace={vi.fn()}
+ onOpenObservation={vi.fn()}
+ scrollTarget={null}
+ />
+ </MarkdownContextProvider>,
+ );
+
+ expect(screen.getAllByText(/你好/).length).toBeGreaterThan(0);
+ expect(screen.queryByText(/\\u4f60\\u597d/)).not.toBeInTheDocument();
+ });
+
+ it("decodes Unicode escapes in full (non-truncated) timeline message text", () => {
+ // Modern timeline hydrates full I/O via sessionBatchIO without truncation
+ // flags; plain-string output still carries literal \uXXXX from storage.
+ const loaded = prepareSessionTimelineObservations([
+ {
+ ...observation("gen", null, "GENERATION", new Date(0)),
+ input: '[{"role":"user","content":"hi"}]',
+ output: "\\u4f60\\u597d world",
+ },
+ ]);
+
+ render(
+ <MarkdownContextProvider>
+ <SessionConversationTimelineTrace
+ trace={{ ...trace, observationCount: 1 }}
+ turnNumber={1}
+ state={{ type: "loaded", observations: loaded }}
+ onOpenTrace={vi.fn()}
+ onOpenObservation={vi.fn()}
+ scrollTarget={null}
+ />
+ </MarkdownContextProvider>,
+ );
+
+ expect(screen.getByText(/你好 world/)).toBeInTheDocument();
+ expect(screen.queryByText(/\\u4f60\\u597d/)).not.toBeInTheDocument();
+ });
});
diff --git a/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.tsx b/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.tsx
index 9d2d6d7fc4..4a60d1feac 100644
--- a/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.tsx
+++ b/web/src/features/sessions/SessionConversationTimeline/components/SessionConversationTimelineTrace/SessionConversationTimelineTrace.tsx
@@ -37,6 +37,7 @@ import { type RouterOutputs } from "@/src/utils/api";
import { formatIntervalSeconds } from "@/src/utils/dates";
import { cn } from "@/src/utils/tailwind";
import { getLevelColors } from "@/src/components/level-colors";
+import { decodeUnicodeEscapesOnly } from "@/src/utils/unicode";
type EventObservation = RouterOutputs["events"]["all"]["observations"][number];
type EventObservationIO = RouterOutputs["events"]["batchIO"][number];
@@ -127,10 +128,15 @@ function SessionTimelineStatusIndicator({
);
}
-const toPreviewText = (value: unknown) =>
- typeof value === "string"
- ? value
- : (JSON.stringify(value, undefined, 2) ?? String(value));
+const toPreviewText = (value: unknown) => {
+ const text =
+ typeof value === "string"
+ ? value
+ : (JSON.stringify(value, undefined, 2) ?? String(value));
+ // Match PrettyJsonView / SessionObservationIO: decode \uXXXX so truncated
+ // previews show CJK and other non-ASCII characters instead of raw escapes.
+ return decodeUnicodeEscapesOnly(text, true);
+};
const hasPreviewValue = (value: unknown) =>
value !== null && value !== undefined && value !== "";
diff --git a/web/src/features/sessions/SessionConversationTimeline/components/SessionTimelinePart/SessionTimelinePart.tsx b/web/src/features/sessions/SessionConversationTimeline/components/SessionTimelinePart/SessionTimelinePart.tsx
index 3f56b9fb50..0caef2597c 100644
--- a/web/src/features/sessions/SessionConversationTimeline/components/SessionTimelinePart/SessionTimelinePart.tsx
+++ b/web/src/features/sessions/SessionConversationTimeline/components/SessionTimelinePart/SessionTimelinePart.tsx
@@ -11,6 +11,7 @@ import { LangfuseMediaView } from "@/src/components/ui/LangfuseMediaView";
import { MarkdownView } from "@/src/components/ui/MarkdownViewer";
import { PrettyJsonView } from "@/src/components/ui/PrettyJsonView";
import { getSafeImageUrl, getSafeLinkUrl } from "@/src/components/ui/safe-url";
+import { decodeUnicodeEscapesOnly } from "@/src/utils/unicode";
function SessionTimelineReasoning({ part }: { part: ReasoningPart }) {
const content = part.content;
@@ -22,7 +23,10 @@ function SessionTimelineReasoning({ part }: { part: ReasoningPart }) {
variant="plain"
alignment="row"
>
- <MarkdownView markdown={content.text} className="px-0 py-0" />
+ <MarkdownView
+ markdown={decodeUnicodeEscapesOnly(content.text, true)}
+ className="px-0 py-0"
+ />
</SessionTimelineCollapsiblePart>
);
}
@@ -116,7 +120,10 @@ export function SessionTimelinePart({
{part.refusal ? (
<span className="text-dark-red text-[11px] font-bold">Refusal</span>
) : null}
- <MarkdownView markdown={part.text} className="px-0 py-0" />
+ <MarkdownView
+ markdown={decodeUnicodeEscapesOnly(part.text, true)}
+ className="px-0 py-0"
+ />
</div>
);
}
diff --git a/web/src/features/sessions/SessionObservationIO.clienttest.tsx b/web/src/features/sessions/SessionObservationIO.clienttest.tsx
index 2bb4eef6f9..0a53405c3f 100644
--- a/web/src/features/sessions/SessionObservationIO.clienttest.tsx
+++ b/web/src/features/sessions/SessionObservationIO.clienttest.tsx
@@ -116,6 +116,18 @@ describe("SessionObservationIO", () => {
expect(screen.getByText(/2\.5M characters/i)).toBeInTheDocument();
});
+ it("decodes Unicode escapes in the truncated I/O preview", () => {
+ renderComponent({
+ ...baseObservation,
+ input: '{"text":"\\u4f60\\u597d"}',
+ inputLength: 2_500_000,
+ inputTruncated: true,
+ } as SessionTraceObservation);
+
+ expect(screen.getByText(/你好/)).toBeInTheDocument();
+ expect(screen.queryByText(/\\u4f60\\u597d/)).not.toBeInTheDocument();
+ });
+
it("opens the trace view at the observation", () => {
const { onOpenInTraceView } = renderComponent({
...baseObservation,
diff --git a/web/src/features/sessions/SessionObservationIO.tsx b/web/src/features/sessions/SessionObservationIO.tsx
index ab8a61a4c6..d3c953dbcf 100644
--- a/web/src/features/sessions/SessionObservationIO.tsx
+++ b/web/src/features/sessions/SessionObservationIO.tsx
@@ -13,6 +13,7 @@ import { downloadJsonFile } from "@/src/features/sessions/actions/downloadSessio
import { showErrorToast } from "@/src/features/notifications/showErrorToast";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import { compactNumberFormatter } from "@/src/utils/numbers";
+import { decodeUnicodeEscapesOnly } from "@/src/utils/unicode";
import { parseJsonIfString } from "@langfuse/shared";
export type SessionTraceObservation =
@@ -52,20 +53,23 @@ const TruncatedIOSection = ({
truncated: boolean;
}) => {
const text = typeof value === "string" ? value : JSON.stringify(value);
- const shown =
+ // Character counts stay on the raw slice; decode only the displayed value so
+ // \uXXXX escapes match PrettyJsonView / LargeStringFallback (and stay bounded).
+ const rawShown =
text.length > PREVIEW_DISPLAY_CHARS
? text.slice(0, PREVIEW_DISPLAY_CHARS)
: text;
+ const shown = decodeUnicodeEscapesOnly(rawShown, true);
return (
<div className="flex flex-col gap-1">
<div className="text-muted-foreground flex flex-wrap items-center gap-2 text-xs">
<span className="font-bold">{label}</span>
- {(truncated || shown.length < text.length) && (
+ {(truncated || rawShown.length < text.length) && (
<span>
{compactNumberFormatter(Math.max(fullLength, text.length), 1)}{" "}
characters — showing the first{" "}
- {compactNumberFormatter(shown.length, 1)}
+ {compactNumberFormatter(rawShown.length, 1)}
</span>
)}
</div>