Skip to content

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

fix(dsh): resolve workspace peer settings per session (#5380)

t0saki7fcb42377c80
diff --git a/examples/dsh-memory-plugin/README.md b/examples/dsh-memory-plugin/README.md
index 5523e1813..f89b53a79 100644
--- a/examples/dsh-memory-plugin/README.md
+++ b/examples/dsh-memory-plugin/README.md
@@ -137,7 +137,7 @@ effect for the tools when DSH restarts the bundle, as it does for the runtime.
Two consequences follow from the proxy being one process per profile:
-- **The actor peer is process-level.** Recall, capture, and commit still resolve a peer per session from that session's workspace repository, but tool calls carry the peer resolved at boot. Set `OPENVIKING_PEER_ID` when one process serves several repositories and you need tool calls attributed exactly.
+- **MCP actor scope is process-level.** With the default `recallPeerScope: all`, MCP tool calls omit the actor peer header. With `actor`, they use the peer resolved at boot. Automatic recall, capture, and commit resolve their peer from each session's workspace.
- **`remember` is not session-scoped.** The server's MCP `remember` stores into
its own short-lived session rather than the live `dsh-<session-id>` stream —
the same behavior the Claude Code, Codex, and Cursor integrations have.
@@ -210,7 +210,18 @@ The patch can also carry plugin config:
- `tools/pre-execute` denies a DSH filesystem tool (`read`, `glob`, `grep`, `edit`, `write`, `str_replace_editor`) whose path argument is a `viking://` URI, pointing the model at the bridged `mcp__openviking__*` tools instead. A `write` or `edit` under a skill directory (`viking://~/skills/...`, `viking://user/<id>/skills/...`, `viking://agent/skills/...`) points at `mcp__openviking__add_skill` instead, which creates or replaces a whole skill from its `SKILL.md` text. A `grep` whose pattern is `viking://` text still runs.
- `tools/post-execute` lets a `bash` command that carries a `viking://` URI run unchanged and attaches a notice for the model: use the bridged tools if it meant OpenViking content, or ignore the notice when the URI is intentional data such as an `ov` argument or an HTTP payload.
-Each DSH session maps to `dsh-<session-id>` in OpenViking. Workspace-derived actor peers are resolved per session and sent on every session-specific request: the peer is the git identity of the session's workspace — the normalized `origin` URL (`[email protected]:volcengine/OpenViking.git` becomes `github.com-volcengine-openviking`), else the repository root path, that fallback keeping the older rule where every non-letter-or-digit character becomes `-`. Outside a git repository no peer is sent at all, and what is remembered there goes to the user-level space `viking://user/<you>/memories`. One repository therefore keeps one peer across subdirectories, worktrees, clones and machines, while a fork's different origin keeps it separate. DSH does not read workspace `.openviking/config.json` files, so a `peer.id` written there has no effect; pin a peer with `OPENVIKING_PEER_ID` instead. Memories written under the older path-derived peer stay reachable: the default `recallPeerScope: all` sweeps every peer under the user.
+Each DSH session maps to `dsh-<session-id>` in OpenViking. Workspace-derived actor peers are resolved per session and sent on every session-specific request: the peer is the git identity of the session's workspace — the normalized `origin` URL (`[email protected]:volcengine/OpenViking.git` becomes `github.com-volcengine-openviking`), else the repository root path, that fallback keeping the older rule where every non-letter-or-digit character becomes `-`. With the default peer settings, no peer is sent outside a git repository, and what is remembered there goes to the user-level space `viking://user/<you>/memories`. One repository therefore keeps one peer across subdirectories, worktrees, clones and machines, while a fork's different origin keeps it separate. Memories written under the older path-derived peer stay reachable: the default `recallPeerScope: all` sweeps every peer under the user.
+
+Workspace peer settings are loaded from `session.header.cwd` when the session first uses memory. A workspace can set `peer.id` to name its project explicitly, or `peer.source` to choose a preset or template chain. For example, `<root>/.openviking/config.json` can contain:
+
+```json
+{
+ "version": 1,
+ "peer": { "id": "my-project" }
+}
+```
+
+The shared loader also applies `config.local.json` and machine registry overrides. Explicit host `peerId`, environment overrides and pinned `ovcli.conf` credentials retain their existing precedence. The resolved peer stays fixed for the session's runtime state; new sessions load the current workspace settings. A session without a cwd falls back to the process's working directory.
## Tools
diff --git a/examples/dsh-memory-plugin/config.mjs b/examples/dsh-memory-plugin/config.mjs
index 1cc397995..64d8b3ce6 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.5";
+export const PLUGIN_VERSION = "0.5.6";
/**
* Namespace for the bridged OpenViking MCP tools. DSH publishes every MCP tool
diff --git a/examples/dsh-memory-plugin/index.mjs b/examples/dsh-memory-plugin/index.mjs
index b8f001a0a..de8c0edbc 100644
--- a/examples/dsh-memory-plugin/index.mjs
+++ b/examples/dsh-memory-plugin/index.mjs
@@ -12,7 +12,11 @@ export const inject = ["agents", "sessions", "tools"];
export function apply(ctx, input = {}) {
const config = resolveConfig(input);
const client = new OpenVikingClient(config);
- const runtime = new OpenVikingRuntime(client, config, ctx.logger);
+ const runtime = new OpenVikingRuntime(client, config, ctx.logger, cwd => (
+ // Rebuild from the host input, not the config already merged for boot's cwd.
+ // The shared loader preserves host/env precedence over workspace peers.
+ resolveConfig(input, process.env, cwd).effectivePeer
+ ));
const skipMemory = session => (
config.skipSubagentSessions && session?.header?.origin === "subagent"
);
diff --git a/examples/dsh-memory-plugin/package-lock.json b/examples/dsh-memory-plugin/package-lock.json
index 6d9e2cf30..7a1c2a175 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.5",
+ "version": "0.5.6",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@openviking/dsh-memory-plugin",
- "version": "0.5.5",
+ "version": "0.5.6",
"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 09d7b9e99..8c3c60aa2 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.5",
+ "version": "0.5.6",
"description": "OpenViking memory and context bundle for DeepSeek Harness",
"type": "module",
"main": "index.mjs",
diff --git a/examples/dsh-memory-plugin/runtime.mjs b/examples/dsh-memory-plugin/runtime.mjs
index 3fb20beb6..03955e984 100644
--- a/examples/dsh-memory-plugin/runtime.mjs
+++ b/examples/dsh-memory-plugin/runtime.mjs
@@ -18,10 +18,11 @@ import {
} from "./capture.mjs";
export class OpenVikingRuntime {
- constructor(client, config, logger = console) {
+ constructor(client, config, logger = console, resolveSessionPeer = null) {
this.client = client;
this.config = config;
this.logger = logger;
+ this.resolveSessionPeer = resolveSessionPeer;
this.states = new Map();
this.drainTimer = null;
this.drainRunning = false;
@@ -33,7 +34,7 @@ export class OpenVikingRuntime {
let state = this.states.get(session.id);
if (state) return state;
const cwd = session.header?.cwd || process.cwd();
- const peer = resolveEffectivePeerId({
+ const peer = this.resolveSessionPeer?.(cwd) ?? resolveEffectivePeerId({
cfg: {
peerId: this.config.explicitPeerId,
peerSource: this.config.peerSource,
diff --git a/examples/dsh-memory-plugin/session-workspace.test.mjs b/examples/dsh-memory-plugin/session-workspace.test.mjs
new file mode 100644
index 000000000..614a002b4
--- /dev/null
+++ b/examples/dsh-memory-plugin/session-workspace.test.mjs
@@ -0,0 +1,153 @@
+import assert from "node:assert/strict";
+import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import test from "node:test";
+import { apply } from "./index.mjs";
+
+function setup(t) {
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "dsh-session-workspace-")));
+ const originalEnv = process.env;
+ process.env = { ...originalEnv };
+ for (const key of Object.keys(process.env)) {
+ if (key.startsWith("OPENVIKING_")) delete process.env[key];
+ }
+ Object.assign(process.env, {
+ OPENVIKING_CONFIG_FILE: join(root, "absent-ov.conf"),
+ OPENVIKING_CLI_CONFIG_FILE: join(root, "ovcli.conf"),
+ OPENVIKING_STATE_DIR: join(root, "state"),
+ OPENVIKING_PENDING_DIR: join(root, "pending"),
+ });
+ const a = join(root, "a");
+ const b = join(root, "b");
+ const writeConfig = (cwd, value, file = "config.json") => {
+ mkdirSync(join(cwd, ".openviking"), { recursive: true });
+ writeFileSync(join(cwd, ".openviking", file), JSON.stringify({ version: 1, ...value }));
+ };
+ writeConfig(a, { peer: { id: "project-a", source: "a-{dir}" } });
+ mkdirSync(b);
+ t.mock.method(process, "cwd", () => a);
+ const runtimes = [];
+ t.after(() => {
+ for (const runtime of runtimes) runtime.stopDrainer();
+ process.env = originalEnv;
+ rmSync(root, { recursive: true, force: true });
+ });
+ const start = (input = {}) => {
+ let runtime;
+ apply({
+ logger: { debug() {} },
+ provide(name, value) {
+ if (name === "openvikingMemory") runtime = value;
+ },
+ effect(execute) { execute(); },
+ on() {},
+ plugin() {},
+ }, { endpoint: "http://openviking.test", ...input });
+ runtimes.push(runtime);
+ return runtime;
+ };
+ const session = (cwd, id = cwd) => ({ id, header: { cwd } });
+ return { root, a, b, writeConfig, start, session };
+}
+
+test("sessions load their own workspace peer and keep it for their lifetime", t => {
+ const { a, b, writeConfig, start, session } = setup(t);
+ writeConfig(b, { peer: { id: "project-b", source: "b-{dir}" } });
+ const runtime = start();
+ assert.equal(runtime.config.peerId, "project-a");
+ const stateA = runtime.stateFor(session(a));
+ const stateB = runtime.stateFor(session(b));
+ assert.equal(stateA.config.peerId, "project-a");
+ assert.equal(stateB.config.peerId, "project-b");
+ assert.equal(stateB.config.legacyPeerId, "");
+
+ writeConfig(b, { peer: { id: "project-b-updated" } });
+ assert.equal(runtime.stateFor(session(b)), stateB);
+ assert.equal(stateB.config.peerId, "project-b");
+ assert.equal(runtime.stateFor(session(b, "new-b")).config.peerId, "project-b-updated");
+ assert.equal(runtime.stateFor(session(a)), stateA);
+ assert.equal(runtime.stateFor({ id: "no-cwd" }).config.peerId, "project-a");
+});
+
+test("a session never inherits the launch workspace's peer id or source", t => {
+ const { b, writeConfig, start, session } = setup(t);
+ writeConfig(b, {});
+ const runtime = start();
+ // A non-git workspace with no peer settings has no project peer.
+ assert.equal(runtime.stateFor(session(b, "plain")).config.peerId, "");
+ writeConfig(b, { peer: { source: ["{git_remote}", "b-{dir}"] } });
+ assert.equal(runtime.stateFor(session(b, "template")).config.peerId, "b-b");
+ writeConfig(b, { peer: { source: "none" } });
+ assert.equal(runtime.stateFor(session(b, "none")).config.peerId, "");
+ writeConfig(b, { peer: { id: "team-b" } });
+ writeConfig(b, { peer: { id: "local-b" } }, "config.local.json");
+ assert.equal(runtime.stateFor(session(b, "local")).config.peerId, "local-b");
+});
+
+test("session peer resolution preserves host, environment and pinned credential precedence", t => {
+ const { root, b, writeConfig, start, session } = setup(t);
+ writeConfig(b, { peer: { id: "project-b" } });
+ process.env.OPENVIKING_PEER_ID = "env-peer";
+ assert.equal(start().stateFor(session(b)).config.peerId, "env-peer");
+ assert.equal(start({ peerId: "host-peer" }).stateFor(session(b)).config.peerId, "host-peer");
+
+ // Pinning credentials to ovcli.conf intentionally excludes the env peer.
+ process.env.OPENVIKING_CREDENTIAL_SOURCE = "ovcli";
+ writeFileSync(join(root, "ovcli.conf"), JSON.stringify({ actor_peer_id: "account-peer" }));
+ assert.equal(start().stateFor(session(b)).config.peerId, "account-peer");
+ assert.equal(start({ peerId: "host-peer" }).stateFor(session(b)).config.peerId, "host-peer");
+ delete process.env.OPENVIKING_PEER_ID;
+ assert.equal(start().stateFor(session(b)).config.peerId, "project-b");
+ writeConfig(b, {});
+ assert.equal(start().stateFor(session(b)).config.peerId, "account-peer");
+
+ delete process.env.OPENVIKING_CREDENTIAL_SOURCE;
+ writeFileSync(join(root, "ovcli.conf"), JSON.stringify({ plugin: { dsh: { peerSource: "global-{dir}" } } }));
+ assert.equal(start().stateFor(session(b)).config.peerId, "global-b");
+ writeConfig(b, { peer: { source: "workspace-{dir}" } });
+ process.env.OPENVIKING_PEER_SOURCE = "env-{dir}";
+ assert.equal(start().stateFor(session(b)).config.peerId, "env-b");
+ process.env.OPENVIKING_WORKSPACE_PEER = "0";
+ assert.equal(start().stateFor(session(b)).config.peerId, "");
+});
+
+test("capture, recall and commit send each session's peer on the wire", async t => {
+ const { a, b, writeConfig, start, session } = setup(t);
+ writeConfig(b, { peer: { id: "project-b" } });
+ const requests = [];
+ t.mock.method(globalThis, "fetch", async (url, init = {}) => {
+ const path = new URL(url).pathname;
+ const body = init.body ? JSON.parse(init.body) : null;
+ requests.push({ path, body, peer: new Headers(init.headers).get("X-OpenViking-Actor-Peer") });
+ let result = {};
+ if (path === "/api/v1/search/search") result = { rendered: "" };
+ else if (path === "/api/v1/fs/ls") result = [];
+ else if (path.startsWith("/api/v1/sessions/") && !init.method) result = { pending_tokens: 20000 };
+ return new Response(JSON.stringify({ status: "ok", result }), {
+ headers: { "Content-Type": "application/json" },
+ });
+ });
+ const runtime = start();
+ for (const [cwd, id, peer] of [[a, "a", "project-a"], [b, "b", "project-b"]]) {
+ const current = session(cwd, id);
+ const message = { role: "user", content: [{ type: "text", text: `Remember the deployment for project ${id}.` }], source: { kind: "user" } };
+ const before = requests.length;
+ await runtime.recallMessage({ session: current }, [message]);
+ runtime.capture(current, { type: "user/message", data: message });
+ runtime.maybeCommit(current, { type: "turn/end" });
+ await runtime.flush(current);
+
+ const sent = requests.slice(before);
+ const created = sent.find(req => req.path === "/api/v1/sessions");
+ assert.equal(created.body.session_id, `dsh-${id}`);
+ const recall = sent.find(req => req.path === "/api/v1/search/search");
+ const capture = sent.find(req => req.path === `/api/v1/sessions/dsh-${id}/messages`);
+ const commit = sent.find(req => req.path === `/api/v1/sessions/dsh-${id}/commit`);
+ for (const req of [created, recall, capture, commit]) {
+ assert.ok(req, `missing session request for ${id}`);
+ assert.equal(req.peer, peer, req.path);
+ }
+ assert.equal(capture.body.peer_id, peer);
+ }
+});