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): widen to unscoped recall when peer_role=sender has no sender (#5347)
Zayn Jarvis8a0d3626477e
diff --git a/examples/openclaw-plugin/plugin/openviking-session-routing-runtime.ts b/examples/openclaw-plugin/plugin/openviking-session-routing-runtime.tsindex 767bb85e1..7a1e366fd 100644--- a/examples/openclaw-plugin/plugin/openviking-session-routing-runtime.ts+++ b/examples/openclaw-plugin/plugin/openviking-session-routing-runtime.ts@@ -9,6 +9,7 @@ import {type Logger = {info: (message: string) => void;+ warn: (message: string) => void;};export type SessionAgentLookup = {@@ -99,6 +100,7 @@ export function createOpenVikingSessionRoutingRuntime(options: {peerRole,senderPeerId: sanitizeOpenVikingPeerId(ctx?.requesterSenderId ?? ctx?.senderId),assistantPeerId: agentId,+ warn: (message) => options.logger.warn(message),}),};};diff --git a/examples/openclaw-plugin/routing/identity-routing.ts b/examples/openclaw-plugin/routing/identity-routing.tsindex b50b4c770..2f8614e7c 100644--- a/examples/openclaw-plugin/routing/identity-routing.ts+++ b/examples/openclaw-plugin/routing/identity-routing.ts@@ -41,17 +41,28 @@ export function resolveOpenVikingMessagePeerId(params: {return undefined;}+/**+ * Peer scoping is soft isolation. OpenClaw does not hand every path a sender+ * (context-engine assemble gets no runtimeContext; cron and heartbeat turns+ * have no sender at all), so a missing one widens to the unscoped request a+ * caller without X-OpenViking-Actor-Peer gets, with a warning, rather than+ * taking OpenViking away for the turn.+ */export function resolveOpenVikingActorPeerId(params: {peerRole: OpenVikingPeerRole;senderPeerId?: string;assistantPeerId?: string;+ warn?: (message: string) => void;}): string | undefined {const actorPeerId = resolveOpenVikingMessagePeerId({...params,role: params.peerRole === "sender" ? "user" : "assistant",});if (params.peerRole === "sender" && !actorPeerId) {- throw new Error("openviking: peer_role=sender requires a sender identity");+ params.warn?.(+ "openviking: peer_role=sender but OpenClaw supplied no sender identity; " ++ "continuing as an unscoped request under this user (no X-OpenViking-Actor-Peer)",+ );}return actorPeerId;}diff --git a/examples/openclaw-plugin/services/context-lifecycle-service.ts b/examples/openclaw-plugin/services/context-lifecycle-service.tsindex 0519e586a..f24c5606b 100644--- a/examples/openclaw-plugin/services/context-lifecycle-service.ts+++ b/examples/openclaw-plugin/services/context-lifecycle-service.ts@@ -440,6 +440,7 @@ async function recallForAssemble(peerRole: cfg.peer_role ?? "none",senderPeerId: sanitizeOpenVikingPeerId(sender.senderId),assistantPeerId: agentId,+ warn: (message) => logger.warn?.(message),});const queryConfig = await queryConfigStore?.getEffective({agentId,diff --git a/examples/openclaw-plugin/tests/ut/context-engine-afterTurn.test.ts b/examples/openclaw-plugin/tests/ut/context-engine-afterTurn.test.tsindex 62f4d09f4..5de5cac88 100644--- a/examples/openclaw-plugin/tests/ut/context-engine-afterTurn.test.ts+++ b/examples/openclaw-plugin/tests/ut/context-engine-afterTurn.test.ts@@ -221,6 +221,20 @@ describe("context-engine afterTurn()", () => {);});+ it("captures without a peer_id under peer_role=sender when the sender is missing", async () => {+ const { engine, client } = makeEngine({ cfgOverrides: { peer_role: "sender" } });++ await engine.afterTurn!({+ sessionId: "s1",+ sessionFile: "",+ messages: [{ role: "user", content: "hello world" }],+ prePromptMessageCount: 0,+ });++ expect(client.addSessionMessage).toHaveBeenCalledTimes(1);+ expect(client.addSessionMessage.mock.calls[0][5]).toBeUndefined();+ });+it("does not attribute user messages to the sender in assistant mode", async () => {const { engine, client } = makeEngine();diff --git a/examples/openclaw-plugin/tests/ut/context-engine-assemble.test.ts b/examples/openclaw-plugin/tests/ut/context-engine-assemble.test.tsindex 99e973574..abe6f75d9 100644--- a/examples/openclaw-plugin/tests/ut/context-engine-assemble.test.ts+++ b/examples/openclaw-plugin/tests/ut/context-engine-assemble.test.ts@@ -117,6 +117,20 @@ describe("context-engine assemble()", () => {expect(result.estimatedTokens).toBeGreaterThan(systemPromptTokens(result.systemPromptAddition));});+ it("still recalls under peer_role=sender when the host supplies no sender", async () => {+ const { engine, client, logger } = makeEngine(undefined, { cfgOverrides: { autoRecall: true, peer_role: "sender" } });+ mockRecall(client);+ const result = await engine.assemble({ sessionId: "session", messages: [], prompt });+ expect(client.searchContext).toHaveBeenCalledWith(prompt, expect.objectContaining({ actorPeerId: undefined }));+ expect(result.systemPromptAddition).toContain(memory);+ expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining("no sender identity"));++ logger.warn.mockClear();+ await engine.assemble({ sessionId: "session", messages: [], prompt, runtimeContext: { senderId: "telegram:12345" } });+ expect(client.searchContext).toHaveBeenLastCalledWith(prompt, expect.objectContaining({ actorPeerId: "telegram_12345" }));+ expect(logger.warn).not.toHaveBeenCalled();+ });+it("recalls another detail from the same memory on a follow-up turn", async () => {const { engine, client } = makeEngine(undefined, { cfgOverrides: { autoRecall: true } });const savedMemory = "Use Rust; deploy in eu-west.";diff --git a/examples/openclaw-plugin/tests/ut/identity-routing.test.ts b/examples/openclaw-plugin/tests/ut/identity-routing.test.tsindex 81dbbc143..7c9d0db17 100644--- a/examples/openclaw-plugin/tests/ut/identity-routing.test.ts+++ b/examples/openclaw-plugin/tests/ut/identity-routing.test.ts@@ -1,4 +1,4 @@-import { describe, expect, it } from "vitest";+import { describe, expect, it, vi } from "vitest";import {createSessionAgentResolver,@@ -49,9 +49,18 @@ describe("identity routing registry", () => {peerRole: "sender",senderPeerId: "sender-42",})).toBe("sender-42");- expect(() => resolveOpenVikingActorPeerId({ peerRole: "sender" })).toThrow(- "peer_role=sender requires a sender identity",- );+ });++ it("widens to the unscoped request with a warning when the sender is missing", () => {+ const warn = vi.fn();+ expect(resolveOpenVikingActorPeerId({ peerRole: "sender", warn })).toBeUndefined();+ expect(warn).toHaveBeenCalledWith(expect.stringContaining("no sender identity"));++ warn.mockClear();+ expect(resolveOpenVikingActorPeerId({ peerRole: "sender", senderPeerId: "sender-42", warn })).toBe("sender-42");+ expect(resolveOpenVikingActorPeerId({ peerRole: "assistant", assistantPeerId: "agent", warn })).toBe("agent");+ expect(resolveOpenVikingActorPeerId({ peerRole: "none", warn })).toBeUndefined();+ expect(warn).not.toHaveBeenCalled();});it("resolves session-scoped agents with aliases and config prefix unchanged", () => {diff --git a/examples/openclaw-plugin/tests/ut/plugin-modules.test.ts b/examples/openclaw-plugin/tests/ut/plugin-modules.test.tsindex eafc49f0e..0ee2bc58d 100644--- a/examples/openclaw-plugin/tests/ut/plugin-modules.test.ts+++ b/examples/openclaw-plugin/tests/ut/plugin-modules.test.ts@@ -25,10 +25,28 @@ import { registerOpenVikingLifecycleHooks } from "../../plugin/openviking-lifecyimport { registerOpenVikingMemoryTools } from "../../plugin/openviking-memory-tools.js";import { registerOpenVikingMemoryRecallTools } from "../../plugin/openviking-memory-recall-tools.js";import { registerOpenVikingQueryTools } from "../../plugin/openviking-query-tools.js";+import { createOpenVikingSessionRoutingRuntime } from "../../plugin/openviking-session-routing-runtime.js";import { registerOpenVikingRecallTraceTools } from "../../plugin/openviking-recall-trace-tools.js";import { registerOpenVikingToolResultTools } from "../../plugin/openviking-tool-result-tools.js";describe("plugin module seams", () => {+ it("routes tools without a sender-scoped peer under peer_role=sender when the sender is missing", () => {+ const logger = { info: vi.fn(), warn: vi.fn() };+ const { resolvePluginSessionRouting } = createOpenVikingSessionRoutingRuntime({+ peerRole: "sender",+ peerPrefix: "default",+ logFindRequests: false,+ logger,+ });++ expect(resolvePluginSessionRouting({ sessionId: "session-1" }).actorPeerId).toBeUndefined();+ expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining("no sender identity"));++ logger.warn.mockClear();+ expect(resolvePluginSessionRouting({ sessionId: "session-1", requesterSenderId: "ou_01:abc" }).actorPeerId).toBe("ou_01_abc");+ expect(logger.warn).not.toHaveBeenCalled();+ });+it("registers only enabled OpenViking tools through the tool-registration seam", () => {const api = { registerTool: vi.fn() };const logger = { debug: vi.fn() };