Skip to content

Commit 6f6c802

Browse files
fix(infra): keep restart log tails UTF-16 safe (#103757)
1 parent 022dd9d commit 6f6c802

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/infra/restart-sentinel.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@ describe("restart sentinel", () => {
341341
expect(trimmed?.startsWith("…")).toBe(true);
342342
});
343343

344+
it("keeps trimmed log tails UTF-16 safe", () => {
345+
expect(trimLogTail("prefix🤖tail", 5)).toBe("…tail");
346+
});
347+
344348
it("formats restart messages without volatile timestamps", () => {
345349
const payloadA = {
346350
kind: "restart" as const,

src/infra/restart-sentinel.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { readFile, rm } from "node:fs/promises";
33
import path from "node:path";
44
import { isRecord as isPlainRecord } from "@openclaw/normalization-core/record-coerce";
5+
import { sliceUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
56
import { formatCliCommand } from "../cli/command-format.js";
67
import { resolveStateDir } from "../config/paths.js";
78
import type { DB as OpenClawStateKyselyDatabase } from "../state/openclaw-state-db.generated.js";
@@ -372,5 +373,5 @@ export function trimLogTail(input?: string | null, maxChars = 8000) {
372373
if (text.length <= maxChars) {
373374
return text;
374375
}
375-
return `…${text.slice(text.length - maxChars)}`;
376+
return `…${sliceUtf16Safe(text, text.length - maxChars)}`;
376377
}

0 commit comments

Comments
 (0)