Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(openclaw): preserve heartbeat-looking user messages (#2660)
Eurakaxun5179a79d9765
diff --git a/examples/openclaw-plugin/tests/ut/context-engine-afterTurn.test.ts b/examples/openclaw-plugin/tests/ut/context-engine-afterTurn.test.tsindex f756ef148..25b96fc75 100644--- a/examples/openclaw-plugin/tests/ut/context-engine-afterTurn.test.ts+++ b/examples/openclaw-plugin/tests/ut/context-engine-afterTurn.test.ts@@ -572,7 +572,7 @@ describe("context-engine afterTurn()", () => {expect(assistantParts.map(p => p.text).join(" ")).toContain("Here is context");});- it("skips heartbeat messages from being stored", async () => {+ it("stores heartbeat-looking messages when host does not flag the turn", async () => {const { engine, client } = makeEngine();const messages = [@@ -587,7 +587,35 @@ describe("context-engine afterTurn()", () => {prePromptMessageCount: 0,});- expect(client.addSessionMessage).not.toHaveBeenCalled();+ expect(client.addSessionMessage).toHaveBeenCalledTimes(2);+ expect(client.addSessionMessage.mock.calls[0][1]).toBe("user");+ const userParts = client.addSessionMessage.mock.calls[0][2] as Array<{ text?: string }>;+ expect(userParts.map(p => p.text).join(" ")).toContain("HEARTBEAT.md");+ });++ it("stores normal user messages that mention heartbeat artifacts", async () => {+ const { engine, client } = makeEngine();++ const messages = [+ {+ role: "user",+ content:+ "Please explain why HEARTBEAT.md appeared in the logs and whether HEARTBEAT_OK means success.",+ },+ { role: "assistant", content: "HEARTBEAT_OK is the heartbeat acknowledgement token." },+ ];++ await engine.afterTurn!({+ sessionId: "s1",+ sessionFile: "",+ messages,+ prePromptMessageCount: 0,+ });++ expect(client.addSessionMessage).toHaveBeenCalledTimes(2);+ expect(client.addSessionMessage.mock.calls[0][1]).toBe("user");+ const userParts = client.addSessionMessage.mock.calls[0][2] as Array<{ text?: string }>;+ expect(userParts.map(p => p.text).join(" ")).toContain("HEARTBEAT.md");});it("skips heartbeat via isHeartbeat flag", async () => {diff --git a/examples/openclaw-plugin/text-utils.ts b/examples/openclaw-plugin/text-utils.tsindex 972879509..9e651ec84 100644--- a/examples/openclaw-plugin/text-utils.ts+++ b/examples/openclaw-plugin/text-utils.ts@@ -44,14 +44,9 @@ function looksLikeMetadataJsonBlock(content: string): boolean {return matchedKeys.size >= 3;}-const HEARTBEAT_RE = /\bHEARTBEAT(?:\.md|_OK)\b/;const TOOL_PLACEHOLDER_RE = /^\s*\[tool(?::\s*|Use:\s*)[^\]]+\]\s*$/i;export function sanitizeUserTextForCapture(text: string): string {- // 过滤 HEARTBEAT 健康检查消息- if (HEARTBEAT_RE.test(text)) {- return "";- }// Drop legacy synthetic tool placeholders before they reach memory extraction.if (TOOL_PLACEHOLDER_RE.test(text)) {return "";