Skip to content

Commit eb05889

Browse files
committed
fix(agents): keep tool/command display truncation UTF-16 safe
Replace raw .slice(0, N) with truncateUtf16Safe from @openclaw/normalization-core/utf16-slice across 4 agent modules: - tool-search: compactDirectoryDescription @177-code-unit boundary - gateway-tool: restart reason @200-code-unit boundary - openai-transport-stream: redacted payload/event @8000/2000 - command/attempt-execution: ACP diagnostic text @240 All sites truncate user-visible or agent-generated text where emoji/CJK supplementary characters can be split mid-surrogate.
1 parent 3901094 commit eb05889

4 files changed

Lines changed: 193 additions & 44 deletions

File tree

src/agents/command/attempt-execution.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
normalizeOptionalLowercaseString,
77
type FastMode,
88
} from "@openclaw/normalization-core/string-coerce";
9+
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
910
import { sanitizeForLog } from "../../../packages/terminal-core/src/ansi.js";
1011
import { ACP_TURN_TIMEOUT_DETAIL_CODE } from "../../acp/control-plane/manager.turn-timeout.js";
1112
import { formatAcpErrorChain } from "../../acp/runtime/errors.js";
@@ -1023,7 +1024,11 @@ function resolveAcpLifecycleEndFields(
10231024
resultStatus,
10241025
);
10251026
if (terminalReason === "timed_out") {
1026-
return { aborted: true, stopReason: "timeout", status: "timed_out" } as const;
1027+
return {
1028+
aborted: true,
1029+
stopReason: "timeout",
1030+
status: "timed_out",
1031+
} as const;
10271032
}
10281033
if (terminalReason === "cancelled") {
10291034
return { aborted: true, stopReason: "stop", status: "cancelled" } as const;
@@ -1162,7 +1167,7 @@ function resolvePresentProxyEnvKeys(env: NodeJS.ProcessEnv = process.env): strin
11621167
}
11631168

11641169
function sanitizeAcpDiagnosticText(value: string): string {
1165-
return redactSensitiveText(value).replace(/\s+/g, " ").trim().slice(0, 240);
1170+
return truncateUtf16Safe(redactSensitiveText(value).replace(/\s+/g, " ").trim(), 240);
11661171
}
11671172

11681173
function acpRuntimeEventDiagnostics(event: AcpRuntimeEvent): Record<string, unknown> {
@@ -1303,7 +1308,11 @@ export function emitAcpLifecycleError(params: {
13031308
params.terminalOutcome === "blocked"
13041309
? ({ livenessState: "blocked" } as const)
13051310
: terminalReason === "timed_out"
1306-
? ({ aborted: true, stopReason: "timeout", status: "timed_out" } as const)
1311+
? ({
1312+
aborted: true,
1313+
stopReason: "timeout",
1314+
status: "timed_out",
1315+
} as const)
13071316
: resolveAgentRunAbortLifecycleFields(params.abortSignal);
13081317
const emit = params.auditOnly ? emitAgentAuditEvent : emitAgentEvent;
13091318
emit({

0 commit comments

Comments
 (0)