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
feat(dsh): prevent delegated sessions from contaminating user memory (#4382)
czyyyy66c165681353
diff --git a/examples/dsh-memory-plugin/README.md b/examples/dsh-memory-plugin/README.mdindex 6f28624dc..a38036e53 100644--- a/examples/dsh-memory-plugin/README.md+++ b/examples/dsh-memory-plugin/README.md@@ -141,6 +141,7 @@ The patch can also carry plugin config:recallTokenBudget: 2000scoreThreshold: 0.35captureToolResults: false+ skipSubagentSessions: truecommitTokenThreshold: 20000mcpToolCallTimeoutMs: 60000```@@ -151,6 +152,7 @@ The patch can also carry plugin config:- `agent/pre-step` retrieves with the current step input and appends a durable plugin message to that same step.- `session/event` captures user, assistant, and optionally tool-result messages without scraping a transcript.- `turn/end` checks the OpenViking pending-token threshold and commits when required.+- `skipSubagentSessions: true` excludes sessions marked with `header.origin: subagent` from automatic profile, recall, capture, and commit; it defaults to `false`.- Failed writes enter the shared OpenViking pending queue for replay at the next session start.- `tools/pre-execute` blocks DSH filesystem and shell tools from treating `viking://` URIs as local paths, pointing the model at the bridged `mcp__openviking__*` tools instead.diff --git a/examples/dsh-memory-plugin/config.mjs b/examples/dsh-memory-plugin/config.mjsindex 786b20937..db48c320b 100644--- a/examples/dsh-memory-plugin/config.mjs+++ b/examples/dsh-memory-plugin/config.mjs@@ -1,7 +1,7 @@import { buildUserAgent, resolveOpenVikingCredentials } from "./shared/credentials.mjs";import { resolveEffectivePeerId } from "./shared/workspace-peer.mjs";-export const PLUGIN_VERSION = "0.2.1";+export const PLUGIN_VERSION = "0.3.0";/*** Namespace for the bridged OpenViking MCP tools. DSH publishes every MCP tool@@ -37,6 +37,7 @@ const DEFAULT_CONFIG = Object.freeze({captureMaxLength: 24000,captureToolMaxChars: 1000000,captureAssistantTurns: true,+ skipSubagentSessions: false,requestTimeoutMs: 10000,mcpToolCallTimeoutMs: 60000,});@@ -152,6 +153,7 @@ export function resolveConfig(input = {}, env = process.env, cwd = process.cwd()config.syncTurns = config.syncTurns !== false;config.captureAssistantTurns = config.captureAssistantTurns !== false;config.captureToolResults = config.captureToolResults === true;+ config.skipSubagentSessions = config.skipSubagentSessions === true;return config;}diff --git a/examples/dsh-memory-plugin/index.mjs b/examples/dsh-memory-plugin/index.mjsindex 5cbfb2d86..34d7679bf 100644--- a/examples/dsh-memory-plugin/index.mjs+++ b/examples/dsh-memory-plugin/index.mjs@@ -13,6 +13,9 @@ export function apply(ctx, input = {}) {const config = resolveConfig(input);const client = new OpenVikingClient(config);const runtime = new OpenVikingRuntime(client, config, ctx.logger);+ const skipMemory = session => (+ config.skipSubagentSessions && session?.header?.origin === "subagent"+ );ctx.provide("openvikingMemory", runtime);ctx.effect(() => () => runtime.disposeAll(),@@ -20,6 +23,7 @@ export function apply(ctx, input = {}) {);ctx.on("agent/session-start", ({ agent }) => {+ if (skipMemory(agent.session)) return false;agent.ctx.effect(() => () => runtime.dispose(agent.session),"openvikingMemory.disposeSession()",@@ -31,6 +35,7 @@ export function apply(ctx, input = {}) {// the final claimed batch and appends after every other contributor.ctx.on("agent/pre-step", async ({ agent, messages, signal }, next) => {const decision = await next();+ if (skipMemory(agent.session)) return decision;if (decision.kind !== "enter" || signal.aborted) return decision;const profile = await runtime.profileMessage(agent);if (signal.aborted) return decision;@@ -43,11 +48,13 @@ export function apply(ctx, input = {}) {}, { prepend: true });ctx.on("session/event", (session, event) => {+ if (skipMemory(session)) return;runtime.capture(session, event);runtime.maybeCommit(session, event);});ctx.on("session/flush", async session => {+ if (skipMemory(session)) return;await runtime.flush(session);});diff --git a/examples/dsh-memory-plugin/index.test.mjs b/examples/dsh-memory-plugin/index.test.mjsindex 705b5414b..43f9e2770 100644--- a/examples/dsh-memory-plugin/index.test.mjs+++ b/examples/dsh-memory-plugin/index.test.mjs@@ -2,11 +2,14 @@ import assert from "node:assert/strict";import test from "node:test";import { apply } from "./index.mjs";-test("pre-step recalls from the final downstream message batch", async () => {+test("session filtering skips subagents without changing main-session recall", async () => {const handlers = new Map();+ let memoryRuntime;const ctx = {logger: { debug() {} },- provide() {},+ provide(name, value) {+ if (name === "openvikingMemory") memoryRuntime = value;+ },effect(execute) {execute();return async () => {};@@ -20,6 +23,7 @@ test("pre-step recalls from the final downstream message batch", async () => {apply(ctx, {endpoint: "http://127.0.0.1:1933",workspacePeer: false,+ skipSubagentSessions: true,});const agent = {@@ -31,8 +35,8 @@ test("pre-step recalls from the final downstream message batch", async () => {},},};- const runtime = handlers.get("agent/session-start");- assert.equal(typeof runtime, "function");+ const sessionStart = handlers.get("agent/session-start");+ assert.equal(typeof sessionStart, "function");const preStep = handlers.get("agent/pre-step");const initial = [message("initial input")];@@ -57,6 +61,38 @@ test("pre-step recalls from the final downstream message batch", async () => {messages: initial,signal: new AbortController().signal,}, async () => ({ kind: "enter", messages: downstream }));++ const child = {+ status: "idle",+ session: {+ id: "dsh-derived-child",+ header: { cwd: "/workspace", origin: "subagent" },+ },+ inject() {+ assert.fail("subagent profile must not be injected");+ },+ ctx: {+ effect() {+ assert.fail("subagent teardown commit must not be registered");+ },+ },+ };+ assert.equal(await sessionStart({ agent: child }), false);+ const childMessages = [message("derived worker input")];+ const childDecision = await preStep({+ agent: child,+ messages: childMessages,+ signal: new AbortController().signal,+ }, async () => ({ kind: "enter", messages: childMessages }));+ handlers.get("session/event")(child.session, {+ type: "user/message",+ data: message("derived exploration chatter"),+ });+ handlers.get("session/event")(child.session, { type: "turn/end", data: {} });+ await handlers.get("session/flush")(child.session);++ assert.deepEqual(childDecision.messages, childMessages);+ assert.equal(memoryRuntime.states.has(child.session.id), false);} finally {globalThis.fetch = originalFetch;}diff --git a/examples/dsh-memory-plugin/package-lock.json b/examples/dsh-memory-plugin/package-lock.jsonindex d1cd9eb1c..3666a7365 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.2.1",+ "version": "0.3.0","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "@openviking/dsh-memory-plugin",- "version": "0.2.1",+ "version": "0.3.0","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.jsonindex 1f0a51884..3683ab9dc 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.2.1",+ "version": "0.3.0","description": "OpenViking memory and context bundle for DeepSeek Harness","type": "module","main": "index.mjs",