Skip to content

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

fix(openclaw-plugin): stop synthesizing tenant headers (#1789)

Qin Haojie08dcfc10ac5a
diff --git a/examples/openclaw-plugin/README.md b/examples/openclaw-plugin/README.md
index 1da870868..1098476fb 100644
--- a/examples/openclaw-plugin/README.md
+++ b/examples/openclaw-plugin/README.md
@@ -47,7 +47,7 @@ The main rules are:
- normalize unsafe path characters, or fall back to a stable SHA-256 when needed
- resolve `X-OpenViking-Agent` per session, not per process
- when `plugins.entries.openviking.config.agent_prefix` is not `default`, prefix the session agent as `<agent_prefix>_<sessionAgent>`
-- add `X-OpenViking-Account`, `X-OpenViking-User`, and `X-OpenViking-Agent` in the client layer
+- add `X-OpenViking-Agent` in the client layer, and only add `X-OpenViking-Account` / `X-OpenViking-User` when `accountId` / `userId` are explicitly configured
This matters because the plugin is built to support multi-agent and multi-session OpenClaw usage without mixing memories across sessions.
@@ -60,7 +60,7 @@ The recommended remote-mode configuration only needs:
In this setup:
- `apiKey` should usually be a user key
-- `accountId` / `userId` are advanced options only for root-key or `trusted` deployments
+- `accountId` / `userId` are advanced options only when the deployment needs explicit identity headers, such as root-key or trusted-server flows
- `isolateUserScopeByAgent` / `isolateAgentScopeByUser` must match the server-side account namespace policy when using the PR #1356 canonical namespace model
- `agentScopeMode` is a deprecated compatibility alias for older hash-based routing and should only be used against older servers
diff --git a/examples/openclaw-plugin/README_CN.md b/examples/openclaw-plugin/README_CN.md
index 8184233f2..3f040d619 100644
--- a/examples/openclaw-plugin/README_CN.md
+++ b/examples/openclaw-plugin/README_CN.md
@@ -47,7 +47,7 @@
- 非安全路径字符会被规整或退化成稳定的 SHA-256。
- `X-OpenViking-Agent` 按 session 解析,不按进程写死。
- 若 `plugins.entries.openviking.config.agent_prefix` 不是 `default`,会形成 `<agent_prefix>_<sessionAgent>` 的前缀形式。
-- client 层统一补全 `X-OpenViking-Account`、`X-OpenViking-User`、`X-OpenViking-Agent` 这些 header。
+- client 层会发送 `X-OpenViking-Agent`;只有显式配置了 `accountId` / `userId` 时才发送 `X-OpenViking-Account` / `X-OpenViking-User`。
这样做是为了支持多 agent、多 session 并发时的记忆隔离,避免不同 OpenClaw 会话串用同一套长期上下文。
@@ -60,7 +60,7 @@
其中:
- `apiKey` 推荐使用某个 user 的 user key
-- `accountId` / `userId` 仅在 root key 或 `trusted` 模式下作为高级选项使用
+- `accountId` / `userId` 仅在部署需要显式身份 header 时作为高级选项使用,例如 root key 或 trusted server 流程
- 使用 PR #1356 canonical namespace 模型时,`isolateUserScopeByAgent` / `isolateAgentScopeByUser` 必须与服务端 account namespace policy 保持一致
- `agentScopeMode` 已退化为兼容旧 hash 路由的 deprecated alias,仅应在旧服务端上使用
diff --git a/examples/openclaw-plugin/client.ts b/examples/openclaw-plugin/client.ts
index 2bfd65668..e47ea6fec 100644
--- a/examples/openclaw-plugin/client.ts
+++ b/examples/openclaw-plugin/client.ts
@@ -27,7 +27,6 @@ export type FindResult = {
export type CaptureMode = "semantic" | "keyword";
export type ScopeName = "user" | "agent";
export type AgentScopeMode = "user_agent" | "agent";
-export type ServerAuthMode = "api_key" | "trusted";
export type RuntimeIdentity = {
userId: string;
agentId: string;
@@ -204,8 +203,7 @@ export class OpenVikingClient {
private readonly apiKey: string,
private readonly defaultAgentId: string,
private readonly timeoutMs: number,
- private readonly serverAuthMode: ServerAuthMode = "api_key",
- /** When set (or defaulted), sent so ROOT key can access tenant-scoped APIs. */
+ /** When set, sent so ROOT keys or trusted deployments can select tenant identity. */
private readonly accountId: string = "",
private readonly userId: string = "",
/** When set, logs routing for find + session writes (tenant headers + paths; never apiKey). */
@@ -228,23 +226,10 @@ export class OpenVikingClient {
const apiKey = this.apiKey.trim();
const accountId = this.accountId.trim();
const userId = this.userId.trim();
- if (this.serverAuthMode === "trusted") {
- return {
- ...(apiKey ? { apiKey } : {}),
- accountId: accountId || "default",
- userId: userId || "default",
- };
- }
- if (apiKey) {
- return {
- apiKey,
- ...(accountId ? { accountId } : {}),
- ...(userId ? { userId } : {}),
- };
- }
return {
- accountId: accountId || "default",
- userId: userId || "default",
+ ...(apiKey ? { apiKey } : {}),
+ ...(accountId ? { accountId } : {}),
+ ...(userId ? { userId } : {}),
};
}
diff --git a/examples/openclaw-plugin/config.ts b/examples/openclaw-plugin/config.ts
index 009bf66db..379404e3f 100644
--- a/examples/openclaw-plugin/config.ts
+++ b/examples/openclaw-plugin/config.ts
@@ -4,11 +4,10 @@ export type MemoryOpenVikingConfig = {
mode?: "remote";
baseUrl?: string;
agent_prefix?: string;
- serverAuthMode?: "api_key" | "trusted";
apiKey?: string;
- /** Advanced option. Only needed when using root key or trusted auth mode. With a user key the server derives identity from the key. */
+ /** Advanced option. Only needed when explicitly sending tenant identity headers. With a user key the server derives identity from the key. */
accountId?: string;
- /** Advanced option. Only needed when using root key or trusted auth mode. */
+ /** Advanced option. Only needed when explicitly sending tenant identity headers. */
userId?: string;
/**
* Canonical namespace policy. Must match the server-side account namespace
@@ -63,7 +62,6 @@ const DEFAULT_COMMIT_TOKEN_THRESHOLD = 20000;
const DEFAULT_BYPASS_SESSION_PATTERNS: string[] = [];
const DEFAULT_EMIT_STANDARD_DIAGNOSTICS = false;
const DEFAULT_AGENT_PREFIX = "default";
-const DEFAULT_SERVER_AUTH_MODE = "api_key";
function resolveAgentPrefix(configured: unknown): string {
if (typeof configured === "string" && configured.trim()) {
@@ -192,10 +190,6 @@ export const memoryOpenVikingConfigSchema = {
const rawBaseUrl = typeof cfg.baseUrl === "string" ? cfg.baseUrl : resolveDefaultBaseUrl();
const resolvedBaseUrl = resolveEnvVars(rawBaseUrl).replace(/\/+$/, "");
const rawApiKey = typeof cfg.apiKey === "string" ? cfg.apiKey : process.env.OPENVIKING_API_KEY;
- const rawServerAuthMode =
- cfg.serverAuthMode ?? process.env.OPENVIKING_SERVER_AUTH_MODE;
- const serverAuthMode =
- rawServerAuthMode === "trusted" ? "trusted" as const : "api_key" as const;
const captureMode = cfg.captureMode;
if (
typeof captureMode !== "undefined" &&
@@ -262,7 +256,6 @@ export const memoryOpenVikingConfigSchema = {
mode,
baseUrl: resolvedBaseUrl,
agent_prefix: resolveAgentPrefix(cfg.agent_prefix),
- serverAuthMode,
apiKey: rawApiKey ? resolveEnvVars(rawApiKey) : "",
accountId,
userId,
@@ -323,11 +316,6 @@ export const memoryOpenVikingConfigSchema = {
placeholder: "auto-generated",
help: 'OpenViking X-OpenViking-Agent prefix. "default" follows OpenClaw ctx.agentId. Non-default values are prepended as "<prefix>_<ctx.agentId>" (sanitized to [a-zA-Z0-9_-]).',
},
- serverAuthMode: {
- label: "Server Auth Mode",
- placeholder: DEFAULT_SERVER_AUTH_MODE,
- help: 'OpenViking auth behavior. "api_key" (default): send X-API-Key when configured, otherwise dev fallback to X-OpenViking-Account/User default/default. "trusted": always send accountId/userId and optionally send apiKey when configured.',
- },
apiKey: {
label: "OpenViking API Key",
sensitive: true,
@@ -337,13 +325,13 @@ export const memoryOpenVikingConfigSchema = {
accountId: {
label: "Account ID",
placeholder: "(derived from API key)",
- help: "Advanced option. Tenant account ID. Only needed when using root key or trusted auth mode. With a user key the server derives identity from the key.",
+ help: "Advanced option. Tenant account ID. Only needed when explicitly sending identity headers, such as root-key or trusted deployments. With a user key the server derives identity from the key.",
advanced: true,
},
userId: {
label: "User ID",
placeholder: "(derived from API key)",
- help: "Advanced option. Tenant user ID. Only needed when using root key or trusted auth mode.",
+ help: "Advanced option. Tenant user ID. Only needed when explicitly sending identity headers.",
advanced: true,
},
isolateUserScopeByAgent: {
diff --git a/examples/openclaw-plugin/index.ts b/examples/openclaw-plugin/index.ts
index cdff509b4..687977115 100644
--- a/examples/openclaw-plugin/index.ts
+++ b/examples/openclaw-plugin/index.ts
@@ -562,7 +562,6 @@ const contextEnginePlugin = {
verboseRoutingInfo(
`openviking: auth/namespace config ` +
JSON.stringify({
- serverAuthMode: cfg.serverAuthMode,
isolateUserScopeByAgent: cfg.isolateUserScopeByAgent,
isolateAgentScopeByUser: cfg.isolateAgentScopeByUser,
deprecatedAgentScopeMode: cfg.agentScopeMode,
@@ -582,7 +581,6 @@ const contextEnginePlugin = {
cfg.apiKey,
cfg.agent_prefix,
cfg.timeoutMs,
- cfg.serverAuthMode,
tenantAccount,
tenantUser,
routingDebugLog,
diff --git a/examples/openclaw-plugin/openclaw-multi-tenant-test-report.md b/examples/openclaw-plugin/openclaw-multi-tenant-test-report.md
index 558052298..8229237de 100644
--- a/examples/openclaw-plugin/openclaw-multi-tenant-test-report.md
+++ b/examples/openclaw-plugin/openclaw-multi-tenant-test-report.md
@@ -74,7 +74,7 @@
| 维度 | case | 结果 | 说明 |
|---|---|---|---|
-| `api_key` | `api_key_without_key_dev` | 通过 | `default/default` dev fallback 生效 |
+| `api_key` | `api_key_without_key_dev` | 通过 | 不再合成 `default/default` 租户 header |
| `api_key` | `personal_token_default` | 通过 | 命中 `DEFAULT_USER_TOKEN_19950` |
| `api_key` | `agentid_prefix_worker` | 通过 | 实际 agent 值为 `worker_main` |
| 兼容 | `deprecated_agent_alias` | 通过 | `agentScopeMode=agent` 兼容正常 |
@@ -105,7 +105,7 @@
## 5. 关键结论
-1. 插件侧 `serverAuthMode`、canonical namespace policy 与 `role_id` 透传能力已完成联调验证。
+1. 插件侧 canonical namespace policy、显式租户 header 与 `role_id` 透传能力已完成联调验证。
2. `afterTurn` 路径可通过 `runtimeContext.senderId` 正确写出 `role_id`。
3. `memory_store` 路径在工具上下文中无法直接读取 `senderId`,但可稳定通过 `requesterSenderId` 写出 `role_id`。
4. 在真实机器人私聊与群聊场景中,已确认不同用户会被映射为不同的 `role_id`,且 assistant message 保持 `role_id:null`。
diff --git a/examples/openclaw-plugin/openclaw.plugin.json b/examples/openclaw-plugin/openclaw.plugin.json
index 541ca76ed..fc9486787 100644
--- a/examples/openclaw-plugin/openclaw.plugin.json
+++ b/examples/openclaw-plugin/openclaw.plugin.json
@@ -14,11 +14,6 @@
"placeholder": "auto-generated",
"help": "OpenViking agent prefix. default: follow OpenClaw ctx.agentId. Non-default: use `<prefix>_<OpenClaw ctx.agentId>` (sanitized to letters/digits/_/-), so the configured value acts as a prefix."
},
- "serverAuthMode": {
- "label": "Server Auth Mode",
- "placeholder": "api_key",
- "help": "api_key (default): send X-API-Key when configured, otherwise dev fallback to default/default tenant headers. trusted: always send accountId/userId and optionally send apiKey when configured."
- },
"apiKey": {
"label": "OpenViking API Key",
"sensitive": true,
@@ -28,13 +23,13 @@
"accountId": {
"label": "Account ID",
"placeholder": "(derived from API key)",
- "help": "Advanced option. Tenant account ID. Only needed when using root key or trusted auth mode. With a user key the server derives identity from the key.",
+ "help": "Advanced option. Tenant account ID. Only needed when explicitly sending identity headers, such as root-key or trusted deployments. With a user key the server derives identity from the key.",
"advanced": true
},
"userId": {
"label": "User ID",
"placeholder": "(derived from API key)",
- "help": "Advanced option. Tenant user ID. Only needed when using root key or trusted auth mode.",
+ "help": "Advanced option. Tenant user ID. Only needed when explicitly sending identity headers.",
"advanced": true
},
"isolateUserScopeByAgent": {
@@ -161,7 +156,8 @@
"description": "Deprecated: use agent_prefix instead"
},
"serverAuthMode": {
- "type": "string"
+ "type": "string",
+ "description": "Deprecated and ignored. Tenant identity headers are controlled by explicit accountId/userId."
},
"apiKey": {
"type": "string"
diff --git a/examples/openclaw-plugin/tests/ut/client.test.ts b/examples/openclaw-plugin/tests/ut/client.test.ts
index 4f62f4ed3..def206e17 100644
--- a/examples/openclaw-plugin/tests/ut/client.test.ts
+++ b/examples/openclaw-plugin/tests/ut/client.test.ts
@@ -334,13 +334,12 @@ describe("OpenVikingClient resource and skill import", () => {
});
describe("OpenVikingClient tenant headers (advanced accountId / userId overrides)", () => {
- it("sends configured accountId and userId in request headers for trusted flows", async () => {
+ it("sends explicitly configured accountId and userId in request headers", async () => {
const fetchMock = vi.fn().mockResolvedValue(okResponse({ status: "ok" }));
vi.stubGlobal("fetch", fetchMock);
const client = new OpenVikingClient(
"http://127.0.0.1:1933", "sk-test", "agent", 5000,
- "trusted",
"acct-123", "user-456",
);
await client.healthCheck();
@@ -357,7 +356,6 @@ describe("OpenVikingClient tenant headers (advanced accountId / userId overrides
const client = new OpenVikingClient(
"http://127.0.0.1:1933", "sk-user", "agent", 5000,
- "api_key",
"", "",
);
await client.healthCheck();
@@ -375,7 +373,6 @@ describe("OpenVikingClient tenant headers (advanced accountId / userId overrides
const client = new OpenVikingClient(
"http://127.0.0.1:1933", "sk-root", "agent", 5000,
- "api_key",
"acct-123", "user-456",
);
await client.healthCheck();
@@ -387,30 +384,28 @@ describe("OpenVikingClient tenant headers (advanced accountId / userId overrides
expect(headers.get("X-OpenViking-User")).toBe("user-456");
});
- it("falls back to default/default in api_key dev mode when apiKey is missing", async () => {
+ it("does not synthesize tenant headers when apiKey is missing", async () => {
const fetchMock = vi.fn().mockResolvedValue(okResponse({ status: "ok" }));
vi.stubGlobal("fetch", fetchMock);
const client = new OpenVikingClient(
"http://127.0.0.1:1933", "", "agent", 5000,
- "api_key",
"", "",
);
await client.healthCheck();
const [, init] = fetchMock.mock.calls[0] as [string, RequestInit];
const headers = new Headers(init.headers);
- expect(headers.get("X-OpenViking-Account")).toBe("default");
- expect(headers.get("X-OpenViking-User")).toBe("default");
+ expect(headers.get("X-OpenViking-Account")).toBeNull();
+ expect(headers.get("X-OpenViking-User")).toBeNull();
});
- it("trims whitespace from trusted accountId and userId overrides", async () => {
+ it("trims whitespace from accountId and userId overrides", async () => {
const fetchMock = vi.fn().mockResolvedValue(okResponse({ status: "ok" }));
vi.stubGlobal("fetch", fetchMock);
const client = new OpenVikingClient(
"http://127.0.0.1:1933", "", "agent", 5000,
- "trusted",
" acct ", " user ",
);
await client.healthCheck();
@@ -437,7 +432,6 @@ describe("OpenVikingClient canonical namespace policy", () => {
const client = new OpenVikingClient(
"http://127.0.0.1:1933", "", "my-agent", 5000,
- "api_key",
"", "", undefined,
false,
true,
@@ -465,7 +459,6 @@ describe("OpenVikingClient canonical namespace policy", () => {
const client = new OpenVikingClient(
"http://127.0.0.1:1933", "", "my-agent", 5000,
- "api_key",
"", "", undefined,
true,
true,
@@ -493,7 +486,6 @@ describe("OpenVikingClient canonical namespace policy", () => {
const client = new OpenVikingClient(
"http://127.0.0.1:1933", "", "shared-agent", 5000,
- "api_key",
"", "", undefined,
false,
true,
@@ -521,7 +513,6 @@ describe("OpenVikingClient canonical namespace policy", () => {
const client = new OpenVikingClient(
"http://127.0.0.1:1933", "", "shared-agent", 5000,
- "api_key",
"", "", undefined,
false,
false,
diff --git a/examples/openclaw-plugin/tests/ut/config.test.ts b/examples/openclaw-plugin/tests/ut/config.test.ts
index f7978ec9a..18c86cae7 100644
--- a/examples/openclaw-plugin/tests/ut/config.test.ts
+++ b/examples/openclaw-plugin/tests/ut/config.test.ts
@@ -24,7 +24,6 @@ describe("memoryOpenVikingConfigSchema.parse()", () => {
expect(cfg.captureMaxLength).toBe(24000);
expect(cfg.recallMaxContentChars).toBe(5000);
expect(cfg.agent_prefix).toBe("default");
- expect(cfg.serverAuthMode).toBe("api_key");
expect(cfg.isolateUserScopeByAgent).toBe(false);
expect(cfg.isolateAgentScopeByUser).toBe(false);
expect(cfg.emitStandardDiagnostics).toBe(false);
@@ -257,14 +256,9 @@ describe("memoryOpenVikingConfigSchema.parse()", () => {
expect(cfg.isolateAgentScopeByUser).toBe(true);
});
- it("parses trusted serverAuthMode", () => {
+ it("accepts deprecated serverAuthMode without exposing it in parsed config", () => {
const cfg = memoryOpenVikingConfigSchema.parse({ serverAuthMode: "trusted" });
- expect(cfg.serverAuthMode).toBe("trusted");
- });
-
- it("falls back to api_key for invalid serverAuthMode", () => {
- const cfg = memoryOpenVikingConfigSchema.parse({ serverAuthMode: "invalid" });
- expect(cfg.serverAuthMode).toBe("api_key");
+ expect("serverAuthMode" in cfg).toBe(false);
});
it("defaults recallResources to false", () => {
diff --git a/examples/openclaw-plugin/tests/ut/context-engine-afterTurn.test.ts b/examples/openclaw-plugin/tests/ut/context-engine-afterTurn.test.ts
index af9602501..7515dac1b 100644
--- a/examples/openclaw-plugin/tests/ut/context-engine-afterTurn.test.ts
+++ b/examples/openclaw-plugin/tests/ut/context-engine-afterTurn.test.ts
@@ -203,7 +203,6 @@ describe("context-engine afterTurn()", () => {
const { engine, logger } = makeEngine({
commitTokenThreshold: 50,
getSession: { pending_tokens: 5000 },
- cfgOverrides: { serverAuthMode: "trusted" },
});
await engine.afterTurn!({
@@ -222,28 +221,8 @@ describe("context-engine afterTurn()", () => {
);
});
- it("passes sanitized senderId as role_id in trusted mode", async () => {
- const { engine, client } = makeEngine({
- cfgOverrides: { serverAuthMode: "trusted" },
- });
-
- await engine.afterTurn!({
- sessionId: "s1",
- sessionFile: "",
- messages: [{ role: "user", content: "hello world" }],
- prePromptMessageCount: 0,
- runtimeContext: { senderId: "telegram:12345" },
- });
-
- expect(client.addSessionMessage).toHaveBeenCalledTimes(1);
- expect(client.addSessionMessage.mock.calls[0][5]).toBe("telegram_12345");
- });
-
-
- it("passes sanitized senderId as role_id in api_key mode", async () => {
- const { engine, client } = makeEngine({
- cfgOverrides: { serverAuthMode: "api_key" },
- });
+ it("passes sanitized senderId as role_id", async () => {
+ const { engine, client } = makeEngine();
await engine.afterTurn!({
sessionId: "s1",