From 1ee2ac0d280ab1d22378c9e4a294ccb423e8f0e3 Mon Sep 17 00:00:00 2001 From: zhanghui Date: Fri, 13 Nov 2026 13:47:52 +0800 Subject: [PATCH 1/2] fix(openclaw): recall on the current request, owner memory in owner chats only Two OpenClaw 2026.11 additions the plugin did not follow: - before_prompt_build now carries `currentUserMessage`, and the docs warn that `prompt` may contain reconstructed history on some runtimes (Codex is named). Recall built its query from `prompt`, so there the query could be the head of old history. Use `currentUserMessage` when present; an explicit "" means no textual request and recalls nothing rather than falling back to history, as the docs require. Older hosts keep using `prompt`. - hook ctx carries `memoryAudience`: `owner-private` for the owner's direct chat, `conversation` for another sender, a group, channel, or thread. Recall searched the owner's user track (profile, episodes) in every turn, so a group chat could be shown the owner's personal memory. In `conversation` audience only the agent track (cases, skills) is searched. Hosts without the field behave as before. Both fields typecheck against the real 2026.11.3 SDK. Version 3.0.4. Co-Authored-By: Claude Opus 5.5 --- openclaw/README.md | 5 ++++ openclaw/openclaw.plugin.json | 2 +- openclaw/package-lock.json | 4 +-- openclaw/package.json | 2 +- openclaw/src/handlers.ts | 36 ++++++++++++++++++--------- openclaw/src/openclaw-types.ts | 13 ++++++++++ openclaw/test/handlers.test.ts | 45 ++++++++++++++++++++++++++++++++++ 7 files changed, 92 insertions(+), 15 deletions(-) diff --git a/openclaw/README.md b/openclaw/README.md index bae7083..c5462f9 100644 --- a/openclaw/README.md +++ b/openclaw/README.md @@ -224,6 +224,11 @@ Recall injects up to four sections, all served by EverOS: - **Relevant cases** — concrete past agent trajectories (what worked) - **Relevant skills** — reusable patterns distilled from multiple cases +On OpenClaw 2026.11 and later, the first two (your profile and episodes) are recalled +only in your own direct chat. In a turn OpenClaw marks as `conversation` audience +(another sender, a group, channel, or thread) only cases and skills are injected. Older +OpenClaw versions do not mark audience, so every turn gets all four. + ### Captured - User and assistant text (the plugin strips its own injected recall block first, diff --git a/openclaw/openclaw.plugin.json b/openclaw/openclaw.plugin.json index cb245fc..1f02297 100644 --- a/openclaw/openclaw.plugin.json +++ b/openclaw/openclaw.plugin.json @@ -2,7 +2,7 @@ "id": "evermind-ai-everos", "name": "OpenClaw Memory — EverOS", "description": "EverOS-backed cross-session memory for OpenClaw (memory slot).", - "version": "3.0.3", + "version": "3.0.4", "kind": "memory", "activation": { "onStartup": true diff --git a/openclaw/package-lock.json b/openclaw/package-lock.json index 4c54113..9cb8bde 100644 --- a/openclaw/package-lock.json +++ b/openclaw/package-lock.json @@ -1,12 +1,12 @@ { "name": "@everos-ai/openclaw-plugin", - "version": "3.0.3", + "version": "3.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@everos-ai/openclaw-plugin", - "version": "3.0.3", + "version": "3.0.4", "license": "Apache-2.0", "bin": { "everos-setup": "dist/setup-cli.js" diff --git a/openclaw/package.json b/openclaw/package.json index d07e569..6417ae8 100644 --- a/openclaw/package.json +++ b/openclaw/package.json @@ -1,6 +1,6 @@ { "name": "@everos-ai/openclaw-plugin", - "version": "3.0.3", + "version": "3.0.4", "description": "OpenClaw Memory — EverOS: native memory-slot plugin backed by the local EverOS framework.", "keywords": [ "openclaw", diff --git a/openclaw/src/handlers.ts b/openclaw/src/handlers.ts index 8e480b7..6b270f3 100644 --- a/openclaw/src/handlers.ts +++ b/openclaw/src/handlers.ts @@ -752,21 +752,35 @@ export function createHandlers(deps: HandlerDeps): Handlers { const project_id = projectIdFrom(ctx); noteActiveSession(sessionIdOf(ctx), project_id); - // The current user prompt lives in `event.prompt`; `event.messages` is - // prior history (empty on a fresh session, verified against the OpenClaw - // runtime — it never contains the current turn). The query keeps the prompt - // whole and blends in up to `queryN - 1` prior user lines for follow-up - // context; a blank prompt falls back to recent history. See buildRecallQuery. - const current = typeof event.prompt === "string" ? event.prompt : ""; + // The current request is `event.currentUserMessage` where the host supplies + // it (2026.11+): `event.prompt` may then carry reconstructed history, and an + // explicit "" means no textual request, which must not fall back to history. + // Older hosts put it in `event.prompt`. `event.messages` is prior history + // (empty on a fresh session; it never contains the current turn). The query + // keeps the request whole and blends in up to `queryN - 1` prior user lines; + // a blank `prompt` falls back to recent history. See buildRecallQuery. + if (event.currentUserMessage === "") return; + const current = + typeof event.currentUserMessage === "string" + ? event.currentUserMessage + : typeof event.prompt === "string" + ? event.prompt + : ""; const q = buildRecallQuery(current, event.messages ?? [], deps.queryN, deps.queryMaxChars); if (!q) return; // nothing to recall on const opts = { timeoutMs: recallTimeoutMs }; - const userP: Promise = deps.userId - ? deps.client - .search({ user_id: deps.userId, app_id: deps.appId, project_id, query: q, include_profile: true }, opts) - .catch(() => undefined) - : Promise.resolve(undefined); + // The user track is the owner's own memory (profile, episodes). OpenClaw + // marks any turn that is not the owner's direct chat (another sender, a + // group, channel, or thread) as `conversation` audience: keep the owner's + // memory out of it. The agent track (cases, skills) is the agent's own. + const ownerAudience = ctx.memoryAudience?.kind !== "conversation"; + const userP: Promise = + deps.userId && ownerAudience + ? deps.client + .search({ user_id: deps.userId, app_id: deps.appId, project_id, query: q, include_profile: true }, opts) + .catch(() => undefined) + : Promise.resolve(undefined); const agentP: Promise = deps.client .search({ agent_id: deps.agentId, app_id: deps.appId, project_id, query: q }, opts) .catch(() => undefined); diff --git a/openclaw/src/openclaw-types.ts b/openclaw/src/openclaw-types.ts index 3d93648..a71a928 100644 --- a/openclaw/src/openclaw-types.ts +++ b/openclaw/src/openclaw-types.ts @@ -22,6 +22,14 @@ export interface PluginHookAgentContext { modelProviderId?: string; modelId?: string; channelId?: string; + /** + * Host-resolved memory partition for the turn (OpenClaw 2026.11+). `owner-private` + * is the owner's direct chat; `conversation` is any other sender, group, channel, + * or thread. Absent on older hosts. + */ + memoryAudience?: + | { kind: "owner-private"; agentId: string } + | { kind: "conversation"; agentId: string; sessionKey: string; sessionId: string }; [key: string]: unknown; } @@ -40,6 +48,11 @@ export interface PluginHookSessionContext { export interface BeforePromptBuildEvent { prompt: string; messages: unknown[]; + /** + * The current request before history projection (OpenClaw 2026.11+). `prompt` + * may carry reconstructed history on some runtimes; `""` means no textual request. + */ + currentUserMessage?: string; } /** Honored return fields for `before_prompt_build` (exactly these five). */ diff --git a/openclaw/test/handlers.test.ts b/openclaw/test/handlers.test.ts index 2773b68..4ba4566 100644 --- a/openclaw/test/handlers.test.ts +++ b/openclaw/test/handlers.test.ts @@ -449,6 +449,51 @@ test("recall: uses event.prompt when history is empty (fresh session)", async () assert.equal(spy.searches[0]!.query, "what am I working on?"); }); +test("recall: currentUserMessage is the query when the host supplies it", async () => { + const spy = spyClient(); + const h = createHandlers(baseDeps(spy.client)); + await h.recall( + { + prompt: "old turn\nold reply\nwhere is the deploy key?", + messages: [], + currentUserMessage: "where is the deploy key?", + }, + ctx(), + ); + assert.equal(spy.searches.length, 2); + for (const s of spy.searches) assert.equal(s.query, "where is the deploy key?"); +}); + +test("recall: an explicit empty currentUserMessage recalls nothing, even with history", async () => { + const spy = spyClient(); + const h = createHandlers(baseDeps(spy.client)); + const out = await h.recall( + { prompt: "reconstructed", messages: [{ role: "user", content: "earlier question" }], currentUserMessage: "" }, + ctx(), + ); + assert.equal(out, undefined); + assert.equal(spy.searches.length, 0); +}); + +test("recall: conversation audience keeps the owner's memory out, agent track stays", async () => { + const spy = spyClient(); + const h = createHandlers(baseDeps(spy.client)); + const audience = { kind: "conversation" as const, agentId: "main", sessionKey: "k", sessionId: "s" }; + await h.recall({ prompt: "who is on call?", messages: [] }, ctx({ memoryAudience: audience })); + assert.equal(spy.searches.length, 1); + assert.ok("agent_id" in spy.searches[0]! && spy.searches[0]!.agent_id); +}); + +test("recall: owner-private audience searches both tracks", async () => { + const spy = spyClient(); + const h = createHandlers(baseDeps(spy.client)); + await h.recall( + { prompt: "who is on call?", messages: [] }, + ctx({ memoryAudience: { kind: "owner-private", agentId: "main" } }), + ); + assert.equal(spy.searches.length, 2); +}); + test("recall: empty query → no search, no injection", async () => { const spy = spyClient(); const h = createHandlers(baseDeps(spy.client)); From ff9145e263c39e4f76edc1c2483b5f1ae2beaeeb Mon Sep 17 00:00:00 2001 From: zhanghui Date: Fri, 13 Nov 2026 13:56:54 +0800 Subject: [PATCH 2/2] fix(openclaw): drop the audience gate, the host never sends it here OpenClaw resolves `memoryAudience` only when the loaded memory provider is native (registers a `providerRuntime`); resolveLoadedMemoryProviderKind returns nothing for this plugin's `registerMemoryCapability({})`, so hook ctx carries no audience and the gate never fired outside the tests, which supplied it by hand. Keeping owner memory out of group turns needs a native provider integration; that is a separate change. Co-Authored-By: Claude Opus 5.5 --- openclaw/README.md | 5 ----- openclaw/src/handlers.ts | 16 +++++----------- openclaw/src/openclaw-types.ts | 8 -------- openclaw/test/handlers.test.ts | 19 ------------------- 4 files changed, 5 insertions(+), 43 deletions(-) diff --git a/openclaw/README.md b/openclaw/README.md index c5462f9..bae7083 100644 --- a/openclaw/README.md +++ b/openclaw/README.md @@ -224,11 +224,6 @@ Recall injects up to four sections, all served by EverOS: - **Relevant cases** — concrete past agent trajectories (what worked) - **Relevant skills** — reusable patterns distilled from multiple cases -On OpenClaw 2026.11 and later, the first two (your profile and episodes) are recalled -only in your own direct chat. In a turn OpenClaw marks as `conversation` audience -(another sender, a group, channel, or thread) only cases and skills are injected. Older -OpenClaw versions do not mark audience, so every turn gets all four. - ### Captured - User and assistant text (the plugin strips its own injected recall block first, diff --git a/openclaw/src/handlers.ts b/openclaw/src/handlers.ts index 6b270f3..6213796 100644 --- a/openclaw/src/handlers.ts +++ b/openclaw/src/handlers.ts @@ -770,17 +770,11 @@ export function createHandlers(deps: HandlerDeps): Handlers { if (!q) return; // nothing to recall on const opts = { timeoutMs: recallTimeoutMs }; - // The user track is the owner's own memory (profile, episodes). OpenClaw - // marks any turn that is not the owner's direct chat (another sender, a - // group, channel, or thread) as `conversation` audience: keep the owner's - // memory out of it. The agent track (cases, skills) is the agent's own. - const ownerAudience = ctx.memoryAudience?.kind !== "conversation"; - const userP: Promise = - deps.userId && ownerAudience - ? deps.client - .search({ user_id: deps.userId, app_id: deps.appId, project_id, query: q, include_profile: true }, opts) - .catch(() => undefined) - : Promise.resolve(undefined); + const userP: Promise = deps.userId + ? deps.client + .search({ user_id: deps.userId, app_id: deps.appId, project_id, query: q, include_profile: true }, opts) + .catch(() => undefined) + : Promise.resolve(undefined); const agentP: Promise = deps.client .search({ agent_id: deps.agentId, app_id: deps.appId, project_id, query: q }, opts) .catch(() => undefined); diff --git a/openclaw/src/openclaw-types.ts b/openclaw/src/openclaw-types.ts index a71a928..70de0f5 100644 --- a/openclaw/src/openclaw-types.ts +++ b/openclaw/src/openclaw-types.ts @@ -22,14 +22,6 @@ export interface PluginHookAgentContext { modelProviderId?: string; modelId?: string; channelId?: string; - /** - * Host-resolved memory partition for the turn (OpenClaw 2026.11+). `owner-private` - * is the owner's direct chat; `conversation` is any other sender, group, channel, - * or thread. Absent on older hosts. - */ - memoryAudience?: - | { kind: "owner-private"; agentId: string } - | { kind: "conversation"; agentId: string; sessionKey: string; sessionId: string }; [key: string]: unknown; } diff --git a/openclaw/test/handlers.test.ts b/openclaw/test/handlers.test.ts index 4ba4566..bab71b7 100644 --- a/openclaw/test/handlers.test.ts +++ b/openclaw/test/handlers.test.ts @@ -475,25 +475,6 @@ test("recall: an explicit empty currentUserMessage recalls nothing, even with hi assert.equal(spy.searches.length, 0); }); -test("recall: conversation audience keeps the owner's memory out, agent track stays", async () => { - const spy = spyClient(); - const h = createHandlers(baseDeps(spy.client)); - const audience = { kind: "conversation" as const, agentId: "main", sessionKey: "k", sessionId: "s" }; - await h.recall({ prompt: "who is on call?", messages: [] }, ctx({ memoryAudience: audience })); - assert.equal(spy.searches.length, 1); - assert.ok("agent_id" in spy.searches[0]! && spy.searches[0]!.agent_id); -}); - -test("recall: owner-private audience searches both tracks", async () => { - const spy = spyClient(); - const h = createHandlers(baseDeps(spy.client)); - await h.recall( - { prompt: "who is on call?", messages: [] }, - ctx({ memoryAudience: { kind: "owner-private", agentId: "main" } }), - ); - assert.equal(spy.searches.length, 2); -}); - test("recall: empty query → no search, no injection", async () => { const spy = spyClient(); const h = createHandlers(baseDeps(spy.client));