Skip to content

Commit bb1fa40

Browse files
lsr911steipete
andauthored
fix(memory-host): use truncateUtf16Safe for QMD stderr context truncation (#102547)
* fix(memory-host): use truncateUtf16Safe for QMD stderr context truncation * test(memory): cover UTF-16-safe qmd stderr summary --------- Co-authored-by: Peter Steinberger <[email protected]>
1 parent 4cc9200 commit bb1fa40

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

packages/memory-host-sdk/src/host/qmd-query-parser.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ complete`,
6060
expect(parseQmdQueryJson("", "[qmd] warning: no results found\n")).toStrictEqual([]);
6161
});
6262

63+
it("keeps bounded stderr context UTF-16 safe", () => {
64+
const prefix = "a".repeat(116);
65+
const stderr = `${prefix}😀${"b".repeat(120)}`;
66+
67+
expect(() => parseQmdQueryJson("", stderr)).toThrow(
68+
`qmd query returned invalid JSON: stdout empty (stderr: ${prefix}...)`,
69+
);
70+
});
71+
6372
it("does not treat arbitrary non-marker text as no-results output", () => {
6473
expect(() =>
6574
parseQmdQueryJson("warning: search completed; no results found for this query", ""),

packages/memory-host-sdk/src/host/qmd-query-parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Memory Host SDK module implements qmd query parser behavior.
2+
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
23
import { formatErrorMessage } from "./error-utils.js";
34
import { normalizeLowercaseStringOrEmpty } from "./string-utils.js";
45

@@ -81,7 +82,7 @@ function isQmdNoResultsLine(line: string): boolean {
8182

8283
/** Bound stderr context included in parse errors. */
8384
function summarizeQmdStderr(raw: string): string {
84-
return raw.length <= 120 ? raw : `${raw.slice(0, 117)}...`;
85+
return raw.length <= 120 ? raw : `${truncateUtf16Safe(raw, 117)}...`;
8586
}
8687

8788
/** Parse and normalize a strict qmd JSON array payload. */

0 commit comments

Comments
 (0)