Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(openclaw-plugin): authenticate auto-recall health precheck (#2384)

MaojiaSheng57b2e2a00e51
diff --git a/examples/openclaw-plugin/auto-recall.ts b/examples/openclaw-plugin/auto-recall.ts
index 04037ad59..83489f1b1 100644
--- a/examples/openclaw-plugin/auto-recall.ts
+++ b/examples/openclaw-plugin/auto-recall.ts
@@ -199,7 +199,7 @@ export async function buildAutoRecallContext(params: {
return { memoryCount: 0, estimatedTokens: 0 };
}
- const precheck = await quickRecallPrecheck(cfg.baseUrl);
+ const precheck = await quickRecallPrecheck(client, agentId);
if (!precheck.ok) {
verbose?.(`openviking: skipping auto-recall because precheck failed (${precheck.reason})`);
return { memoryCount: 0, estimatedTokens: 0 };
diff --git a/examples/openclaw-plugin/client.ts b/examples/openclaw-plugin/client.ts
index a0b5d03dd..4e607d4fc 100644
--- a/examples/openclaw-plugin/client.ts
+++ b/examples/openclaw-plugin/client.ts
@@ -362,8 +362,8 @@ export class OpenVikingClient {
}
}
- async healthCheck(): Promise<void> {
- await this.request<{ status: string }>("/health");
+ async healthCheck(agentId?: string, requestTimeoutMs?: number): Promise<void> {
+ await this.request<{ status: string }>("/health", {}, agentId, requestTimeoutMs);
}
private async getRuntimeIdentity(agentId?: string): Promise<RuntimeIdentity> {
diff --git a/examples/openclaw-plugin/process-manager.ts b/examples/openclaw-plugin/process-manager.ts
index d2b4fc8a0..0dcb12431 100644
--- a/examples/openclaw-plugin/process-manager.ts
+++ b/examples/openclaw-plugin/process-manager.ts
@@ -1,3 +1,5 @@
+import type { OpenVikingClient } from "./client.js";
+
export function withTimeout<T>(promise: Promise<T>, timeoutMs: number, timeoutMessage: string): Promise<T> {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs);
@@ -14,30 +16,24 @@ export function withTimeout<T>(promise: Promise<T>, timeoutMs: number, timeoutMe
});
}
-export async function quickHealthCheck(baseUrl: string, timeoutMs: number): Promise<boolean> {
- const controller = new AbortController();
- const timer = setTimeout(() => controller.abort(), timeoutMs);
+export async function quickHealthCheck(
+ client: OpenVikingClient,
+ agentId: string | undefined,
+ timeoutMs: number,
+): Promise<boolean> {
try {
- const response = await fetch(`${baseUrl}/health`, {
- method: "GET",
- signal: controller.signal,
- });
- if (!response.ok) {
- return false;
- }
- const body = (await response.json().catch(() => ({}))) as { status?: string };
- return body.status === "ok";
+ await client.healthCheck(agentId, timeoutMs);
+ return true;
} catch {
return false;
- } finally {
- clearTimeout(timer);
}
}
export async function quickRecallPrecheck(
- baseUrl: string,
+ client: OpenVikingClient,
+ agentId?: string,
): Promise<{ ok: true } | { ok: false; reason: string }> {
- const healthOk = await quickHealthCheck(baseUrl, 500);
+ const healthOk = await quickHealthCheck(client, agentId, 500);
if (healthOk) {
return { ok: true };
}
diff --git a/examples/openclaw-plugin/tests/ut/context-engine-assemble.test.ts b/examples/openclaw-plugin/tests/ut/context-engine-assemble.test.ts
index 212313eae..a4b6fa3b1 100644
--- a/examples/openclaw-plugin/tests/ut/context-engine-assemble.test.ts
+++ b/examples/openclaw-plugin/tests/ut/context-engine-assemble.test.ts
@@ -47,6 +47,7 @@ function makeEngine(
) {
const logger = makeLogger();
const client = {
+ healthCheck: vi.fn().mockResolvedValue(undefined),
getSessionContext: vi.fn().mockResolvedValue(contextResult),
find: vi.fn().mockResolvedValue({ memories: [], resources: [], total: 0 }),
read: vi.fn().mockResolvedValue(""),
@@ -73,6 +74,7 @@ function makeEngine(
return {
engine,
client: client as unknown as {
+ healthCheck: ReturnType<typeof vi.fn>;
getSessionContext: ReturnType<typeof vi.fn>;
find: ReturnType<typeof vi.fn>;
read: ReturnType<typeof vi.fn>;
@@ -85,78 +87,68 @@ function makeEngine(
describe("context-engine assemble()", () => {
it("prepends auto-recall to the latest user message during transformContext", async () => {
- vi.stubGlobal(
- "fetch",
- vi.fn().mockResolvedValue({
- ok: true,
- json: async () => ({ status: "ok" }),
- }),
- );
- try {
- const { engine, client } = makeEngine(
- {
- latest_archive_overview: "This OV context must not be rebuilt during transformContext.",
- pre_archive_abstracts: [],
- messages: [
- {
- id: "stored-current-user",
- role: "user",
- created_at: "2026-04-30T00:00:00Z",
- parts: [{ type: "text", text: "stale stored prompt" }],
- },
- ],
- estimatedTokens: 12,
- stats: makeStats(),
- },
- {
- cfgOverrides: {
- autoRecall: true,
- recallPreferAbstract: true,
+ const { engine, client } = makeEngine(
+ {
+ latest_archive_overview: "This OV context must not be rebuilt during transformContext.",
+ pre_archive_abstracts: [],
+ messages: [
+ {
+ id: "stored-current-user",
+ role: "user",
+ created_at: "2026-04-30T00:00:00Z",
+ parts: [{ type: "text", text: "stale stored prompt" }],
},
+ ],
+ estimatedTokens: 12,
+ stats: makeStats(),
+ },
+ {
+ cfgOverrides: {
+ autoRecall: true,
+ recallPreferAbstract: true,
},
- );
- client.find
- .mockResolvedValueOnce({
- memories: [
- {
- uri: "viking://user/default/memories/rust-pref",
- level: 2,
- category: "preferences",
- abstract: "User prefers Rust for backend tasks.",
- score: 0.93,
- },
- ],
- total: 1,
- })
- .mockResolvedValueOnce({ memories: [], total: 0 });
-
- const sourceMessages = [
- { role: "user", content: "[Session History Summary]\nOlder archive summary." },
- { role: "assistant", content: [{ type: "text", text: "Previous answer." }] },
- { role: "user", content: "what backend language should we use?" },
- ];
-
- const result = await engine.assemble({
- sessionId: "session-transform",
- messages: sourceMessages,
- });
-
- expect(client.getSessionContext).not.toHaveBeenCalled();
- expect(result.messages).toHaveLength(sourceMessages.length);
- expect(result.messages[0]).toBe(sourceMessages[0]);
- expect(result.messages[1]).toBe(sourceMessages[1]);
- expect(result.messages[2]?.role).toBe("user");
- expect(result.messages[2]?.content).toMatch(/^<relevant-memories>/);
- expect(result.messages[2]?.content).toContain("Source: openviking-auto-recall");
- expect(result.messages[2]?.content).toContain(
- "<uri>viking://user/default/memories/rust-pref</uri>",
- );
- expect(result.messages[2]?.content).toContain("User prefers Rust for backend tasks.");
- expect(result.messages[2]?.content).toContain("what backend language should we use?");
- expect(result.systemPromptAddition).toBeUndefined();
- } finally {
- vi.unstubAllGlobals();
- }
+ },
+ );
+ client.find
+ .mockResolvedValueOnce({
+ memories: [
+ {
+ uri: "viking://user/default/memories/rust-pref",
+ level: 2,
+ category: "preferences",
+ abstract: "User prefers Rust for backend tasks.",
+ score: 0.93,
+ },
+ ],
+ total: 1,
+ })
+ .mockResolvedValueOnce({ memories: [], total: 0 });
+
+ const sourceMessages = [
+ { role: "user", content: "[Session History Summary]\nOlder archive summary." },
+ { role: "assistant", content: [{ type: "text", text: "Previous answer." }] },
+ { role: "user", content: "what backend language should we use?" },
+ ];
+
+ const result = await engine.assemble({
+ sessionId: "session-transform",
+ messages: sourceMessages,
+ });
+
+ expect(client.healthCheck).toHaveBeenCalledWith("agent:session-transform", 500);
+ expect(client.getSessionContext).not.toHaveBeenCalled();
+ expect(result.messages).toHaveLength(sourceMessages.length);
+ expect(result.messages[0]).toBe(sourceMessages[0]);
+ expect(result.messages[1]).toBe(sourceMessages[1]);
+ expect(result.messages[2]?.role).toBe("user");
+ expect(result.messages[2]?.content).toMatch(/^<relevant-memories>/);
+ expect(result.messages[2]?.content).toContain("Source: openviking-auto-recall");
+ expect(result.messages[2]?.content).toContain(
+ "<uri>viking://user/default/memories/rust-pref</uri>",
+ );
+ expect(result.messages[2]?.content).toContain("User prefers Rust for backend tasks.");
+ expect(result.messages[2]?.content).toContain("what backend language should we use?");
+ expect(result.systemPromptAddition).toBeUndefined();
});
it("passes through transformContext messages when the latest message is not user", async () => {