mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 17:50:45 +00:00
fix(active-memory): skip payload-less memory_search toolResults in tr… (openclaw#68773)
Verified: - pnpm install --frozen-lockfile - pnpm test extensions/active-memory/index.test.ts - pnpm exec oxfmt --check --threads=1 extensions/active-memory/index.ts extensions/active-memory/index.test.ts CHANGELOG.md - git diff --check origin/main..HEAD - gh pr checks 68773 --repo openclaw/openclaw --required Co-authored-by: SimbaKingjoe <126222269+SimbaKingjoe@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -1101,6 +1101,54 @@ describe("active-memory plugin", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("skips newest memory_search toolResult entries that carry no debug payload", async () => {
|
||||
const sessionKey = "agent:main:transcript-debug";
|
||||
hoisted.sessionStore[sessionKey] = { sessionId: "s-main", updatedAt: 0 };
|
||||
|
||||
runEmbeddedPiAgent.mockImplementationOnce(async (params: { sessionFile: string }) => {
|
||||
const lines = [
|
||||
JSON.stringify({
|
||||
message: {
|
||||
role: "toolResult",
|
||||
toolName: "memory_search",
|
||||
details: { debug: { backend: "qmd", hits: 3 } },
|
||||
},
|
||||
}),
|
||||
JSON.stringify({
|
||||
message: {
|
||||
role: "toolResult",
|
||||
toolName: "memory_search",
|
||||
details: {},
|
||||
},
|
||||
}),
|
||||
];
|
||||
await fs.writeFile(params.sessionFile, `${lines.join("\n")}\n`, "utf8");
|
||||
return { payloads: [{ text: "wings are fine." }] };
|
||||
});
|
||||
|
||||
await hooks.before_prompt_build(
|
||||
{ prompt: "debug transcript bug", messages: [] },
|
||||
{ agentId: "main", trigger: "user", sessionKey, messageProvider: "webchat" },
|
||||
);
|
||||
|
||||
const updater = hoisted.updateSessionStore.mock.calls.at(-1)?.[1] as
|
||||
| ((store: Record<string, Record<string, unknown>>) => void)
|
||||
| undefined;
|
||||
const store = {
|
||||
[sessionKey]: { sessionId: "s-main", updatedAt: 0 },
|
||||
} as Record<string, Record<string, unknown>>;
|
||||
updater?.(store);
|
||||
const entries = store[sessionKey]?.pluginDebugEntries as
|
||||
| { pluginId: string; lines: string[] }[]
|
||||
| undefined;
|
||||
const debugLine = entries?.[0]?.lines.find((line) =>
|
||||
line.startsWith("🔎 Active Memory Debug:"),
|
||||
);
|
||||
expect(debugLine).toBeDefined();
|
||||
expect(debugLine).toContain("backend=qmd");
|
||||
expect(debugLine).toContain("hits=3");
|
||||
});
|
||||
|
||||
it("replaces stale structured active-memory lines on a later empty run", async () => {
|
||||
const sessionKey = "agent:main:stale-active-memory-lines";
|
||||
hoisted.sessionStore[sessionKey] = {
|
||||
|
||||
@@ -1234,7 +1234,7 @@ async function readActiveMemorySearchDebug(
|
||||
continue;
|
||||
}
|
||||
const details = asRecord(message.details);
|
||||
const debug = asRecord(details?.debug) ?? {};
|
||||
const debug = asRecord(details?.debug);
|
||||
const warning = normalizeOptionalString(details?.warning);
|
||||
const action = normalizeOptionalString(details?.action);
|
||||
const error = normalizeOptionalString(details?.error);
|
||||
|
||||
Reference in New Issue
Block a user