Skip to content

Commit 6f1c389

Browse files
committed
fix(cron): preserve UTF-16 boundaries in exec tails
1 parent 0e1e077 commit 6f1c389

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎src/cron/run-diagnostics.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,27 @@ describe("cron run diagnostics", () => {
192192
});
193193
});
194194

195+
it("keeps failed exec output tails valid at UTF-16 boundaries", () => {
196+
const diagnostics = createCronRunDiagnosticsFromAgentResult(
197+
{
198+
payloads: [
199+
{
200+
toolName: "exec",
201+
details: {
202+
status: "completed",
203+
exitCode: 2,
204+
aggregated: `x😀${"y".repeat(1_999)}`,
205+
},
206+
},
207+
],
208+
},
209+
{ nowMs: () => 123 },
210+
);
211+
212+
expect(diagnostics?.summary).toBe("y".repeat(1_999));
213+
expect(diagnostics?.entries[0]?.message).toBe(`${"y".repeat(999)}…`);
214+
});
215+
195216
it("does not capture harmless successful exec output", () => {
196217
const result = {
197218
payloads: [

‎src/cron/run-diagnostics.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** Builds bounded, redacted diagnostics for cron run logs and UI surfaces. */
22
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
3-
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
3+
import { sliceUtf16Safe, truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
44
import { isToolAllowedByPolicyName } from "../agents/tool-policy-match.js";
55
import { normalizeToolName as normalizePolicyToolName } from "../agents/tool-policy.js";
66
import { getReplyPayloadMetadata } from "../auto-reply/reply-payload.js";
@@ -87,7 +87,7 @@ function tailText(value: string, maxChars: number): string {
8787
}
8888
// Exec output often ends with the actionable failure; keep the tail when
8989
// bounding diagnostic text for run logs and control surfaces.
90-
return value.slice(value.length - maxChars);
90+
return sliceUtf16Safe(value, -maxChars);
9191
}
9292

9393
function normalizeDiagnosticMessage(value: unknown): { message?: string; truncated?: boolean } {

0 commit comments

Comments
 (0)