fix(active-memory): keep search queries UTF-16 safe (#102621)

Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
lzyyzznl
2026-07-09 19:41:38 +08:00
committed by GitHub
parent 7222e3e1ea
commit 5497662408
2 changed files with 26 additions and 1 deletions
+25
View File
@@ -5097,6 +5097,31 @@ describe("active-memory plugin", () => {
expect(prompt).not.toContain("Recent conversation tail:");
});
it("keeps a whole code point when the bounded search query crosses an emoji", async () => {
api.pluginConfig = {
agents: ["main"],
queryMode: "message",
};
plugin.register(api as unknown as OpenClawPluginApi);
const prefix = "a".repeat(479);
await hooks.before_prompt_build(
{
prompt: `${prefix}😀tail`,
messages: [],
},
{
agentId: "main",
trigger: "user",
sessionKey: "agent:main:main",
messageProvider: "webchat",
},
);
const query = lastEmbeddedPrompt().match(/Bounded memory search query:\n([^\n]*)/u)?.[1];
expect(query).toBe(prefix);
});
it("sends a bounded latest-message query instead of channel metadata to memory search", async () => {
api.pluginConfig = {
agents: ["main"],
+1 -1
View File
@@ -2711,7 +2711,7 @@ function normalizeSearchQueryText(text: string): string {
function clampSearchQuery(text: string): string {
const normalized = text.replace(/\s+/g, " ").trim();
return normalized.length > MAX_ACTIVE_MEMORY_SEARCH_QUERY_CHARS
? normalized.slice(0, MAX_ACTIVE_MEMORY_SEARCH_QUERY_CHARS).trim()
? truncateUtf16Safe(normalized, MAX_ACTIVE_MEMORY_SEARCH_QUERY_CHARS).trim()
: normalized;
}