Skip to content

Commit e39e628

Browse files
lsr911steipete
andauthored
fix(active-memory): use truncateUtf16Safe for log value truncation (#102551)
* fix(active-memory): use truncateUtf16Safe for log value truncation * fix(active-memory): use truncateUtf16Safe for log value truncation * test(active-memory): cover UTF-16-safe log limits --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent fc5a4de commit e39e628

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

extensions/active-memory/index.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4812,13 +4812,14 @@ describe("active-memory plugin", () => {
48124812
).not.toEqual([]);
48134813
});
48144814

4815-
it("caps active-memory log field lengths", async () => {
4815+
it("caps active-memory log field lengths without splitting surrogate pairs", async () => {
48164816
api.pluginConfig = {
48174817
agents: ["main"],
48184818
logging: true,
48194819
};
48204820
plugin.register(api as unknown as OpenClawPluginApi);
4821-
const hugeSession = `agent:main:${"x".repeat(500)}`;
4821+
const sessionPrefix = `agent:main:${"x".repeat(288)}`;
4822+
const hugeSession = `${sessionPrefix}😀tail`;
48224823

48234824
await hooks.before_prompt_build(
48244825
{ prompt: "what wings should i order? long log value", messages: [] },
@@ -4836,7 +4837,8 @@ describe("active-memory plugin", () => {
48364837
const startLine = infoLines.find((line: string) => line.includes(" start timeoutMs="));
48374838
const line = requireNonEmptyString(startLine, "active memory start log line missing");
48384839
expect(line.length).toBeLessThan(500);
4839-
expect(line).toContain("...");
4840+
expect(line).toContain(`session=${sessionPrefix}...`);
4841+
expect(line).not.toMatch(/[\uD800-\uDFFF]/u);
48404842
});
48414843

48424844
it("uses a canonical agent session key when only sessionId is available", async () => {

extensions/active-memory/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ function toSingleLineLogValue(value: unknown): string {
14341434
.replace(/\s+/g, " ")
14351435
.trim();
14361436
return singleLine.length > MAX_LOG_VALUE_CHARS
1437-
? `${singleLine.slice(0, MAX_LOG_VALUE_CHARS)}...`
1437+
? `${truncateUtf16Safe(singleLine, MAX_LOG_VALUE_CHARS)}...`
14381438
: singleLine;
14391439
}
14401440

0 commit comments

Comments
 (0)