Skip to content

Commit 259d8a3

Browse files
authored
Merge 73b475b into 2ba622c
2 parents 2ba622c + 73b475b commit 259d8a3

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/tui/tui-event-handlers.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,3 +2664,14 @@ describe("tui-event-handlers: streaming watchdog", () => {
26642664
handlers.dispose?.();
26652665
});
26662666
});
2667+
2668+
describe("abort diagnostic truncation", () => {
2669+
it("does not split surrogate pairs", async () => {
2670+
const { truncateUtf16Safe } = await import("@openclaw/normalization-core/utf16-slice");
2671+
const content = "x".repeat(158) + "🚀tail";
2672+
const bad = content.slice(0, 159);
2673+
expect(bad.endsWith("\uD83D")).toBe(true);
2674+
const good = truncateUtf16Safe(content, 159);
2675+
expect(good).toBe("x".repeat(158));
2676+
});
2677+
});

src/tui/tui-event-handlers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// Handles TUI keyboard, paste, backend, and command events.
21
import { normalizeLowercaseStringOrEmpty } from "@openclaw/normalization-core/string-coerce";
32
import { classifyFailoverReason, isAuthErrorMessage } from "../agents/embedded-agent-helpers.js";
43
import { parseAgentSessionKey } from "../sessions/session-key-utils.js";
54
import { formatRawAssistantErrorForUi } from "../shared/assistant-error-format.js";
5+
// Handles TUI keyboard, paste, backend, and command events.
6+
import { truncateUtf16Safe } from "../utils.js";
67
import {
78
asString,
89
extractTextFromMessage,
@@ -53,7 +54,7 @@ function formatAbortDiagnostic(value: string | undefined): string | undefined {
5354
return undefined;
5455
}
5556
return diagnostic.length > MAX_ABORT_DIAGNOSTIC_LENGTH
56-
? `${diagnostic.slice(0, MAX_ABORT_DIAGNOSTIC_LENGTH - 1)}…`
57+
? `${truncateUtf16Safe(diagnostic, MAX_ABORT_DIAGNOSTIC_LENGTH - 1)}…`
5758
: diagnostic;
5859
}
5960

0 commit comments

Comments
 (0)