Skip to content

Commit 5497662

Browse files
lzyyzznlsteipete
andauthored
fix(active-memory): keep search queries UTF-16 safe (#102621)
Co-authored-by: Peter Steinberger <[email protected]>
1 parent 7222e3e commit 5497662

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

extensions/active-memory/index.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5097,6 +5097,31 @@ describe("active-memory plugin", () => {
50975097
expect(prompt).not.toContain("Recent conversation tail:");
50985098
});
50995099

5100+
it("keeps a whole code point when the bounded search query crosses an emoji", async () => {
5101+
api.pluginConfig = {
5102+
agents: ["main"],
5103+
queryMode: "message",
5104+
};
5105+
plugin.register(api as unknown as OpenClawPluginApi);
5106+
const prefix = "a".repeat(479);
5107+
5108+
await hooks.before_prompt_build(
5109+
{
5110+
prompt: `${prefix}😀tail`,
5111+
messages: [],
5112+
},
5113+
{
5114+
agentId: "main",
5115+
trigger: "user",
5116+
sessionKey: "agent:main:main",
5117+
messageProvider: "webchat",
5118+
},
5119+
);
5120+
5121+
const query = lastEmbeddedPrompt().match(/Bounded memory search query:\n([^\n]*)/u)?.[1];
5122+
expect(query).toBe(prefix);
5123+
});
5124+
51005125
it("sends a bounded latest-message query instead of channel metadata to memory search", async () => {
51015126
api.pluginConfig = {
51025127
agents: ["main"],

extensions/active-memory/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2711,7 +2711,7 @@ function normalizeSearchQueryText(text: string): string {
27112711
function clampSearchQuery(text: string): string {
27122712
const normalized = text.replace(/\s+/g, " ").trim();
27132713
return normalized.length > MAX_ACTIVE_MEMORY_SEARCH_QUERY_CHARS
2714-
? normalized.slice(0, MAX_ACTIVE_MEMORY_SEARCH_QUERY_CHARS).trim()
2714+
? truncateUtf16Safe(normalized, MAX_ACTIVE_MEMORY_SEARCH_QUERY_CHARS).trim()
27152715
: normalized;
27162716
}
27172717

0 commit comments

Comments
 (0)