Skip to content

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

fix(memory-plugin): carry OPENVIKING_EXTRA_HEADERS on the runtime path and fail on a non-JSON 2xx (#5988)

xiebaiyuane05460914532
diff --git a/agent-plugins/servers/shared/ov-http.mjs b/agent-plugins/servers/shared/ov-http.mjs
index 0c198a72a..f1bc32d2d 100644
--- a/agent-plugins/servers/shared/ov-http.mjs
+++ b/agent-plugins/servers/shared/ov-http.mjs
@@ -17,6 +17,8 @@
// that asks for less than a second gets a second.
const MIN_TIMEOUT_MS = 1000;
+import { parseExtraHeaders } from "./mcp-proxy-config.mjs";
+
/**
* The headers every harness puts on every OpenViking request.
*
@@ -59,6 +61,12 @@ export function createOvHttp(cfg = {}, {
} = {}) {
// dsh and pi name this field `endpoint`; every other harness names it `baseUrl`.
const baseUrl = cfg.baseUrl || cfg.endpoint || "";
+ // A caller that owns its header map passes it in; every other harness gets the
+ // operator's escape hatch from the environment. A deployment behind an
+ // authenticating gateway (Cloudflare Access, oauth2-proxy, mTLS-terminating proxy)
+ // needs the same headers on the turn hooks as on the MCP path, and wiring each
+ // harness by hand is how the header blocks drifted in the first place.
+ const resolvedExtraHeaders = extraHeaders ?? parseExtraHeaders(process.env.OPENVIKING_EXTRA_HEADERS);
return async function fetchJSON(path, init = {}, options = {}) {
const timeoutMs = Math.max(MIN_TIMEOUT_MS, Number(options.timeoutMs) || Number(defaultTimeoutMs) || 0);
const controller = new AbortController();
@@ -72,7 +80,7 @@ export function createOvHttp(cfg = {}, {
...buildOvHeaders(cfg, {
actorPeerId: options.actorPeerId ?? resolveActorPeerId(),
identityHeaders,
- extraHeaders,
+ extraHeaders: resolvedExtraHeaders,
}),
...(init.headers || {}),
};
@@ -81,6 +89,19 @@ export function createOvHttp(cfg = {}, {
if (!(error instanceof SyntaxError)) throw error;
return null;
});
+ const contentType = response.headers.get("content-type") || "";
+ if (body === null && response.ok && contentType && !/json/i.test(contentType)) {
+ // A 2xx that is not JSON is not OpenViking. An authenticating gateway's login
+ // page, a captive portal or a WAF page answers with 200 and HTML; calling that a
+ // success makes a harness believe it is connected while every capture and recall
+ // is quietly dropped.
+ return {
+ ok: false,
+ status: response.status,
+ result: null,
+ error: { message: `non-JSON response (${contentType})` },
+ };
+ }
if (requireJsonBody && !body) {
return {
ok: false,
diff --git a/examples/agent-hook-plugin/hosts/cursor/openviking.integration.json b/examples/agent-hook-plugin/hosts/cursor/openviking.integration.json
index 7d7b18b9f..634935081 100644
--- a/examples/agent-hook-plugin/hosts/cursor/openviking.integration.json
+++ b/examples/agent-hook-plugin/hosts/cursor/openviking.integration.json
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "openviking-memory",
- "version": "0.5.19",
+ "version": "0.5.20",
"clients": [
"cursor"
],
diff --git a/examples/agent-hook-plugin/hosts/kimicode/kimi.plugin.json b/examples/agent-hook-plugin/hosts/kimicode/kimi.plugin.json
index 9eb30d9e4..cc896ca54 100644
--- a/examples/agent-hook-plugin/hosts/kimicode/kimi.plugin.json
+++ b/examples/agent-hook-plugin/hosts/kimicode/kimi.plugin.json
@@ -1,6 +1,6 @@
{
"name": "openviking-memory",
- "version": "0.5.19",
+ "version": "0.5.20",
"description": "Long-term semantic memory for Kimi Code CLI, powered by OpenViking.",
"author": {
"name": "OpenViking",
diff --git a/examples/agent-hook-plugin/hosts/kimicode/openviking.integration.json b/examples/agent-hook-plugin/hosts/kimicode/openviking.integration.json
index 6ac56bfaf..2d5a2ba67 100644
--- a/examples/agent-hook-plugin/hosts/kimicode/openviking.integration.json
+++ b/examples/agent-hook-plugin/hosts/kimicode/openviking.integration.json
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "openviking-memory",
- "version": "0.5.19",
+ "version": "0.5.20",
"clients": [
"kimicode"
],
diff --git a/examples/agent-hook-plugin/hosts/trae/openviking.integration.json b/examples/agent-hook-plugin/hosts/trae/openviking.integration.json
index f748d0a24..accf10f34 100644
--- a/examples/agent-hook-plugin/hosts/trae/openviking.integration.json
+++ b/examples/agent-hook-plugin/hosts/trae/openviking.integration.json
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "openviking-memory",
- "version": "0.5.19",
+ "version": "0.5.20",
"clients": [
"trae",
"trae-cn"
diff --git a/examples/agent-hook-plugin/hosts/zcode/openviking.integration.json b/examples/agent-hook-plugin/hosts/zcode/openviking.integration.json
index ab494e00b..cb80b8ad5 100644
--- a/examples/agent-hook-plugin/hosts/zcode/openviking.integration.json
+++ b/examples/agent-hook-plugin/hosts/zcode/openviking.integration.json
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "openviking-memory",
- "version": "0.5.19",
+ "version": "0.5.20",
"clients": [
"zcode"
],
diff --git a/examples/agent-hook-plugin/plugin.json b/examples/agent-hook-plugin/plugin.json
index 711307aee..71609170a 100644
--- a/examples/agent-hook-plugin/plugin.json
+++ b/examples/agent-hook-plugin/plugin.json
@@ -1,6 +1,6 @@
{
"name": "agent-hook-plugin",
- "version": "0.5.19",
+ "version": "0.5.20",
"description": "Long-term semantic memory for Cursor, TRAE, TRAE CN, ZCode and Kimi Code — powered by OpenViking. Auto-recall relevant memories and capture the conversation as it happens.",
"author": {
"name": "OpenViking",
diff --git a/examples/claude-code-memory-plugin/scripts/shared/ov-http.mjs b/examples/claude-code-memory-plugin/scripts/shared/ov-http.mjs
index 0c198a72a..f1bc32d2d 100644
--- a/examples/claude-code-memory-plugin/scripts/shared/ov-http.mjs
+++ b/examples/claude-code-memory-plugin/scripts/shared/ov-http.mjs
@@ -17,6 +17,8 @@
// that asks for less than a second gets a second.
const MIN_TIMEOUT_MS = 1000;
+import { parseExtraHeaders } from "./mcp-proxy-config.mjs";
+
/**
* The headers every harness puts on every OpenViking request.
*
@@ -59,6 +61,12 @@ export function createOvHttp(cfg = {}, {
} = {}) {
// dsh and pi name this field `endpoint`; every other harness names it `baseUrl`.
const baseUrl = cfg.baseUrl || cfg.endpoint || "";
+ // A caller that owns its header map passes it in; every other harness gets the
+ // operator's escape hatch from the environment. A deployment behind an
+ // authenticating gateway (Cloudflare Access, oauth2-proxy, mTLS-terminating proxy)
+ // needs the same headers on the turn hooks as on the MCP path, and wiring each
+ // harness by hand is how the header blocks drifted in the first place.
+ const resolvedExtraHeaders = extraHeaders ?? parseExtraHeaders(process.env.OPENVIKING_EXTRA_HEADERS);
return async function fetchJSON(path, init = {}, options = {}) {
const timeoutMs = Math.max(MIN_TIMEOUT_MS, Number(options.timeoutMs) || Number(defaultTimeoutMs) || 0);
const controller = new AbortController();
@@ -72,7 +80,7 @@ export function createOvHttp(cfg = {}, {
...buildOvHeaders(cfg, {
actorPeerId: options.actorPeerId ?? resolveActorPeerId(),
identityHeaders,
- extraHeaders,
+ extraHeaders: resolvedExtraHeaders,
}),
...(init.headers || {}),
};
@@ -81,6 +89,19 @@ export function createOvHttp(cfg = {}, {
if (!(error instanceof SyntaxError)) throw error;
return null;
});
+ const contentType = response.headers.get("content-type") || "";
+ if (body === null && response.ok && contentType && !/json/i.test(contentType)) {
+ // A 2xx that is not JSON is not OpenViking. An authenticating gateway's login
+ // page, a captive portal or a WAF page answers with 200 and HTML; calling that a
+ // success makes a harness believe it is connected while every capture and recall
+ // is quietly dropped.
+ return {
+ ok: false,
+ status: response.status,
+ result: null,
+ error: { message: `non-JSON response (${contentType})` },
+ };
+ }
if (requireJsonBody && !body) {
return {
ok: false,
diff --git a/examples/codex-memory-plugin/scripts/shared/ov-http.mjs b/examples/codex-memory-plugin/scripts/shared/ov-http.mjs
index 0c198a72a..f1bc32d2d 100644
--- a/examples/codex-memory-plugin/scripts/shared/ov-http.mjs
+++ b/examples/codex-memory-plugin/scripts/shared/ov-http.mjs
@@ -17,6 +17,8 @@
// that asks for less than a second gets a second.
const MIN_TIMEOUT_MS = 1000;
+import { parseExtraHeaders } from "./mcp-proxy-config.mjs";
+
/**
* The headers every harness puts on every OpenViking request.
*
@@ -59,6 +61,12 @@ export function createOvHttp(cfg = {}, {
} = {}) {
// dsh and pi name this field `endpoint`; every other harness names it `baseUrl`.
const baseUrl = cfg.baseUrl || cfg.endpoint || "";
+ // A caller that owns its header map passes it in; every other harness gets the
+ // operator's escape hatch from the environment. A deployment behind an
+ // authenticating gateway (Cloudflare Access, oauth2-proxy, mTLS-terminating proxy)
+ // needs the same headers on the turn hooks as on the MCP path, and wiring each
+ // harness by hand is how the header blocks drifted in the first place.
+ const resolvedExtraHeaders = extraHeaders ?? parseExtraHeaders(process.env.OPENVIKING_EXTRA_HEADERS);
return async function fetchJSON(path, init = {}, options = {}) {
const timeoutMs = Math.max(MIN_TIMEOUT_MS, Number(options.timeoutMs) || Number(defaultTimeoutMs) || 0);
const controller = new AbortController();
@@ -72,7 +80,7 @@ export function createOvHttp(cfg = {}, {
...buildOvHeaders(cfg, {
actorPeerId: options.actorPeerId ?? resolveActorPeerId(),
identityHeaders,
- extraHeaders,
+ extraHeaders: resolvedExtraHeaders,
}),
...(init.headers || {}),
};
@@ -81,6 +89,19 @@ export function createOvHttp(cfg = {}, {
if (!(error instanceof SyntaxError)) throw error;
return null;
});
+ const contentType = response.headers.get("content-type") || "";
+ if (body === null && response.ok && contentType && !/json/i.test(contentType)) {
+ // A 2xx that is not JSON is not OpenViking. An authenticating gateway's login
+ // page, a captive portal or a WAF page answers with 200 and HTML; calling that a
+ // success makes a harness believe it is connected while every capture and recall
+ // is quietly dropped.
+ return {
+ ok: false,
+ status: response.status,
+ result: null,
+ error: { message: `non-JSON response (${contentType})` },
+ };
+ }
if (requireJsonBody && !body) {
return {
ok: false,
diff --git a/examples/dsh-memory-plugin/config.mjs b/examples/dsh-memory-plugin/config.mjs
index 3b3cf178e..e9625bf3d 100644
--- a/examples/dsh-memory-plugin/config.mjs
+++ b/examples/dsh-memory-plugin/config.mjs
@@ -1,7 +1,7 @@
import { buildPluginConfig } from "./shared/plugin-config.mjs";
import { loadCredentialFiles } from "./shared/credentials.mjs";
-export const PLUGIN_VERSION = "0.5.24";
+export const PLUGIN_VERSION = "0.5.25";
/**
* Namespace for the bridged OpenViking MCP tools. DSH publishes every MCP tool
diff --git a/examples/dsh-memory-plugin/package-lock.json b/examples/dsh-memory-plugin/package-lock.json
index eee1ed556..be21e740c 100644
--- a/examples/dsh-memory-plugin/package-lock.json
+++ b/examples/dsh-memory-plugin/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@openviking/dsh-memory-plugin",
- "version": "0.5.24",
+ "version": "0.5.25",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@openviking/dsh-memory-plugin",
- "version": "0.5.24",
+ "version": "0.5.25",
"license": "Apache-2.0",
"devDependencies": {
"@deepseek-ai/dsh-llm": "0.1.0-rc.6",
diff --git a/examples/dsh-memory-plugin/package.json b/examples/dsh-memory-plugin/package.json
index 1627cbef6..e4ba72a18 100644
--- a/examples/dsh-memory-plugin/package.json
+++ b/examples/dsh-memory-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "@openviking/dsh-memory-plugin",
- "version": "0.5.24",
+ "version": "0.5.25",
"description": "OpenViking memory and context bundle for DeepSeek Harness",
"icon": "./icon.svg",
"type": "module",
diff --git a/examples/memory-plugin-shared/lib/ov-http.mjs b/examples/memory-plugin-shared/lib/ov-http.mjs
index 93163a19d..b35978391 100644
--- a/examples/memory-plugin-shared/lib/ov-http.mjs
+++ b/examples/memory-plugin-shared/lib/ov-http.mjs
@@ -16,6 +16,8 @@
// that asks for less than a second gets a second.
const MIN_TIMEOUT_MS = 1000;
+import { parseExtraHeaders } from "./mcp-proxy-config.mjs";
+
/**
* The headers every harness puts on every OpenViking request.
*
@@ -58,6 +60,12 @@ export function createOvHttp(cfg = {}, {
} = {}) {
// dsh and pi name this field `endpoint`; every other harness names it `baseUrl`.
const baseUrl = cfg.baseUrl || cfg.endpoint || "";
+ // A caller that owns its header map passes it in; every other harness gets the
+ // operator's escape hatch from the environment. A deployment behind an
+ // authenticating gateway (Cloudflare Access, oauth2-proxy, mTLS-terminating proxy)
+ // needs the same headers on the turn hooks as on the MCP path, and wiring each
+ // harness by hand is how the header blocks drifted in the first place.
+ const resolvedExtraHeaders = extraHeaders ?? parseExtraHeaders(process.env.OPENVIKING_EXTRA_HEADERS);
return async function fetchJSON(path, init = {}, options = {}) {
const timeoutMs = Math.max(MIN_TIMEOUT_MS, Number(options.timeoutMs) || Number(defaultTimeoutMs) || 0);
const controller = new AbortController();
@@ -71,7 +79,7 @@ export function createOvHttp(cfg = {}, {
...buildOvHeaders(cfg, {
actorPeerId: options.actorPeerId ?? resolveActorPeerId(),
identityHeaders,
- extraHeaders,
+ extraHeaders: resolvedExtraHeaders,
}),
...(init.headers || {}),
};
@@ -80,6 +88,19 @@ export function createOvHttp(cfg = {}, {
if (!(error instanceof SyntaxError)) throw error;
return null;
});
+ const contentType = response.headers.get("content-type") || "";
+ if (body === null && response.ok && contentType && !/json/i.test(contentType)) {
+ // A 2xx that is not JSON is not OpenViking. An authenticating gateway's login
+ // page, a captive portal or a WAF page answers with 200 and HTML; calling that a
+ // success makes a harness believe it is connected while every capture and recall
+ // is quietly dropped.
+ return {
+ ok: false,
+ status: response.status,
+ result: null,
+ error: { message: `non-JSON response (${contentType})` },
+ };
+ }
if (requireJsonBody && !body) {
return {
ok: false,
diff --git a/examples/memory-plugin-shared/ov-http.test.mjs b/examples/memory-plugin-shared/ov-http.test.mjs
index 393fa24e6..bfa68fd4d 100644
--- a/examples/memory-plugin-shared/ov-http.test.mjs
+++ b/examples/memory-plugin-shared/ov-http.test.mjs
@@ -10,6 +10,7 @@ import { createServer } from "node:http";
import { buildOvHeaders, createOvHttp } from "./lib/ov-http.mjs";
import { isRetryableFailure } from "./lib/retryable.mjs";
+import { withMockOpenViking, writeJson } from "./testing/support.mjs";
const CFG = {
baseUrl: "http://127.0.0.1:1933",
@@ -300,3 +301,68 @@ test("dsh and pi name the base url `endpoint`", async () => {
assert.equal(calls[0].url, "http://127.0.0.1:1934/health");
});
+
+test("the operator's OPENVIKING_EXTRA_HEADERS reach the wire without a caller wiring them", async () => {
+ const previous = process.env.OPENVIKING_EXTRA_HEADERS;
+ process.env.OPENVIKING_EXTRA_HEADERS = JSON.stringify({
+ "CF-Access-Client-Id": "id.access",
+ "CF-Access-Client-Secret": "gateway-secret",
+ });
+ try {
+ await withMockOpenViking(
+ (req, res) => writeJson(res, { status: "ok", result: {} }),
+ async (baseUrl, requests) => {
+ // No extraHeaders option and no harness-specific plumbing: this is the path
+ // dsh's client, the turn hooks and every other harness take.
+ await createOvHttp({ baseUrl, apiKey: "test-key" }, { defaultTimeoutMs: 5000 })("/health");
+
+ assert.equal(requests[0].headers["cf-access-client-id"], "id.access");
+ assert.equal(requests[0].headers["cf-access-client-secret"], "gateway-secret");
+ assert.equal(requests[0].headers.authorization, "Bearer test-key");
+ },
+ );
+ } finally {
+ if (previous === undefined) delete process.env.OPENVIKING_EXTRA_HEADERS;
+ else process.env.OPENVIKING_EXTRA_HEADERS = previous;
+ }
+});
+
+test("an explicit extraHeaders map still wins over the environment", async () => {
+ const previous = process.env.OPENVIKING_EXTRA_HEADERS;
+ process.env.OPENVIKING_EXTRA_HEADERS = JSON.stringify({ "CF-Access-Client-Id": "from-env" });
+ try {
+ await withMockOpenViking(
+ (req, res) => writeJson(res, { status: "ok", result: {} }),
+ async (baseUrl, requests) => {
+ await createOvHttp({ baseUrl, apiKey: "test-key" }, {
+ defaultTimeoutMs: 5000,
+ extraHeaders: { "CF-Access-Client-Id": "from-caller" },
+ })("/health");
+
+ assert.equal(requests[0].headers["cf-access-client-id"], "from-caller");
+ },
+ );
+ } finally {
+ if (previous === undefined) delete process.env.OPENVIKING_EXTRA_HEADERS;
+ else process.env.OPENVIKING_EXTRA_HEADERS = previous;
+ }
+});
+
+test("a 2xx that is not JSON is a failure, not a connected server", async () => {
+ // An authenticating gateway answers a header-less request with its login page at
+ // 200/text-html; a harness that reads only the status then reports a happy server
+ // while every request goes to the login page.
+ await withMockOpenViking(
+ (req, res) => {
+ res.writeHead(200, { "Content-Type": "text/html; charset=UTF-8" });
+ res.end("<html><head><title>302 Found</title></head><body></body></html>");
+ },
+ async (baseUrl) => {
+ const result = await createOvHttp({ baseUrl, apiKey: "test-key" }, { defaultTimeoutMs: 5000 })("/health");
+
+ assert.equal(result.ok, false);
+ assert.equal(result.status, 200);
+ assert.match(result.error.message, /non-JSON response/);
+ },
+ );
+});
diff --git a/examples/opencode-plugin/package.json b/examples/opencode-plugin/package.json
index 46bf31f46..7d15e1e6b 100644
--- a/examples/opencode-plugin/package.json
+++ b/examples/opencode-plugin/package.json
@@ -1,6 +1,6 @@
{
"name": "@openviking/opencode-plugin",
- "version": "0.5.13",
+ "version": "0.5.14",
"author": "@openviking",
"description": "Unified OpenCode plugin for OpenViking repository retrieval and long-term memory",
"type": "module",
diff --git a/examples/pi-coding-agent-extension/package-lock.json b/examples/pi-coding-agent-extension/package-lock.json
index 2ea799f70..c624f39a5 100644
--- a/examples/pi-coding-agent-extension/package-lock.json
+++ b/examples/pi-coding-agent-extension/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "openviking-pi-extension",
- "version": "0.4.18",
+ "version": "0.4.19",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "openviking-pi-extension",
- "version": "0.4.18",
+ "version": "0.4.19",
"dependencies": {
"@modelcontextprotocol/client": "2.0.0"
},
diff --git a/examples/pi-coding-agent-extension/package.json b/examples/pi-coding-agent-extension/package.json
index d08dc35dc..e9fba4696 100644
--- a/examples/pi-coding-agent-extension/package.json
+++ b/examples/pi-coding-agent-extension/package.json
@@ -1,6 +1,6 @@
{
"name": "openviking-pi-extension",
- "version": "0.4.18",
+ "version": "0.4.19",
"description": "OpenViking memory and context extension for the pi coding agent",
"private": true,
"type": "module",