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(plugins): skip Codex PreCompact and pi compaction/shutdown writes when auto-capture is off (#6597)
t0sakic558098284cd
diff --git a/examples/codex-memory-plugin/.codex-plugin/plugin.json b/examples/codex-memory-plugin/.codex-plugin/plugin.jsonindex 6f135d8d4..1b78bd8d1 100644--- a/examples/codex-memory-plugin/.codex-plugin/plugin.json+++ b/examples/codex-memory-plugin/.codex-plugin/plugin.json@@ -1,6 +1,6 @@{"name": "openviking-memory",- "version": "0.11.17",+ "version": "0.11.18","description": "Long-term semantic memory for Codex, powered by OpenViking. Recall on UserPromptSubmit, incremental add_message on Stop (per turn), commit on SessionEnd (Codex >= 0.145) and on PreCompact, with an idle/ended sweep on SessionStart as the fallback for signals, crashes and older Codex builds. Includes a local stdio MCP proxy that reads OpenViking credentials from env/ovcli.conf.","author": {"name": "OpenViking",diff --git a/examples/codex-memory-plugin/scripts/pre-compact-capture.mjs b/examples/codex-memory-plugin/scripts/pre-compact-capture.mjsindex dbc95b4a5..063a3e3ed 100644--- a/examples/codex-memory-plugin/scripts/pre-compact-capture.mjs+++ b/examples/codex-memory-plugin/scripts/pre-compact-capture.mjs@@ -139,7 +139,8 @@ async function compact(sessionId, transcriptPath, trigger, cwd, heartbeat) {runHookStage({loadConfig,- gates: { enabled: (reloaded) => reloaded.autoCommitOnCompact },+ // Catch-up uploads turns, so disabling capture also disables this commit.+ gates: { enabled: (reloaded) => reloaded.autoCapture && reloaded.autoCommitOnCompact },envelope: noop,onSkip: (reason) => log("skip", { stage: "init", reason }),}, async (stage) => {diff --git a/examples/codex-memory-plugin/scripts/pre-compact-capture.test.mjs b/examples/codex-memory-plugin/scripts/pre-compact-capture.test.mjsindex 050d9bb0b..0aee8cd40 100644--- a/examples/codex-memory-plugin/scripts/pre-compact-capture.test.mjs+++ b/examples/codex-memory-plugin/scripts/pre-compact-capture.test.mjs@@ -145,6 +145,43 @@ test("pre-compact catches up, commits and keeps the cursor", async () => {}});+test("pre-compact is inert when auto-capture is disabled", async () => {+ const stateDir = await mkdtemp(join(tmpdir(), "ov-pre-compact-off-"));+ const transcriptPath = join(stateDir, "transcript.jsonl");+ const calls = [];+ try {+ const now = Date.now();+ await writeFile(join(stateDir, "pc-off.json"), JSON.stringify({+ codexSessionId: "pc-off",+ ovSessionId: "cx-pc-off",+ capturedTurnCount: 2,+ createdAt: now - 1000,+ lastUpdatedAt: now,+ }));+ await writeFile(transcriptPath, [+ turn("user", "turn-0"),+ turn("assistant", "turn-1"),+ turn("user", "turn-2"),+ turn("assistant", "turn-3"),+ ].join("\n"));++ await withMockOpenViking(mockHandler(calls), async (baseUrl) => {+ const { output } = await runPreCompact(+ { session_id: "pc-off", transcript_path: transcriptPath, trigger: "auto" },+ baseEnv(baseUrl, stateDir, { OPENVIKING_AUTO_CAPTURE: "0" }),+ );+ assert.deepEqual(output, {});+ });++ assert.deepEqual(calls, []);+ const state = JSON.parse(await readFile(join(stateDir, "pc-off.json"), "utf-8"));+ assert.equal(state.ovSessionId, "cx-pc-off");+ assert.equal(state.capturedTurnCount, 2);+ } finally {+ await rm(stateDir, { recursive: true, force: true });+ }+});+test("pre-compact does not create or commit a startup-only session", async () => {const stateDir = await mkdtemp(join(tmpdir(), "ov-pre-compact-startup-"));const transcriptPath = join(stateDir, "transcript.jsonl");diff --git a/examples/pi-coding-agent-extension/index.ts b/examples/pi-coding-agent-extension/index.tsindex e9f068572..5fe68c070 100644--- a/examples/pi-coding-agent-extension/index.ts+++ b/examples/pi-coding-agent-extension/index.ts@@ -380,7 +380,7 @@ export default async function (pi: ExtensionAPI) {// --- session_before_compact ---pi.on("session_before_compact", async (event, ctx) => {- if (!connected || bypassed) return;+ if (!connected || bypassed || !isCaptureEnabled(config)) return;if (config.takeoverEnabled) {const deadline = Date.now() + HANDLER_BUDGET_MS;@@ -426,7 +426,7 @@ export default async function (pi: ExtensionAPI) {await sync.shutdown();if (config.takeoverEnabled) {await takeover.shutdown();- } else {+ } else if (isCaptureEnabled(config)) {await sync.commit();}});diff --git a/examples/pi-coding-agent-extension/package-lock.json b/examples/pi-coding-agent-extension/package-lock.jsonindex 99ce17b5a..bd1fbde8c 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.25",+ "version": "0.4.26","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "openviking-pi-extension",- "version": "0.4.25",+ "version": "0.4.26","dependencies": {"@modelcontextprotocol/client": "2.0.0"},diff --git a/examples/pi-coding-agent-extension/package.json b/examples/pi-coding-agent-extension/package.jsonindex 15deb625c..1a2b6d624 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.25",+ "version": "0.4.26","description": "OpenViking memory and context extension for the pi coding agent","private": true,"type": "module",diff --git a/examples/pi-coding-agent-extension/tests/handshake-once.test.mjs b/examples/pi-coding-agent-extension/tests/handshake-once.test.mjsindex 60a6fd6ea..45bc7c592 100644--- a/examples/pi-coding-agent-extension/tests/handshake-once.test.mjs+++ b/examples/pi-coding-agent-extension/tests/handshake-once.test.mjs@@ -51,12 +51,14 @@ const MANAGED_ENV = [async function startServer() {const initializes = [];+ const requests = [];const gate = { health: null };const server = createServer((req, res) => {const chunks = [];req.on("data", (chunk) => chunks.push(chunk));req.on("end", async () => {const path = (req.url || "").split("?")[0];+ requests.push(`${req.method} ${path}`);if (path === "/mcp") {let method = null;try {@@ -81,6 +83,7 @@ async function startServer() {return {url: `http://127.0.0.1:${port}`,initializes,+ requests,gate,close: () => new Promise((resolve) => server.close(resolve)),};@@ -260,3 +263,24 @@ for (const plugin of [{ mcpEnabled: false }, { bypassSession: true }]) {});});}++for (const plugin of [{ autoCapture: false }, { autoCapture: false, takeoverEnabled: true }]) {+ test("compaction and shutdown do not write with " + JSON.stringify(plugin), async (t) => {+ await withExtension(t, async ({ server, shutdown, configPath }) => {+ await shutdown();+ await writeFile(configPath, JSON.stringify({ plugin: { pi: { ...plugin, mcpEnabled: false } } }));+ const { default: extension } = await import(join(EXTENSION_DIR, "index.ts"));+ const { pi, handlers } = fakePi();+ await extension(pi);+ await handlers.get("before_agent_start")({ prompt: "hello", systemPrompt: "BASE" }, fakeCtx());+ server.requests.length = 0;+ const compaction = await handlers.get("session_before_compact")(+ { type: "session_before_compact", preparation: { firstKeptEntryId: "entry-1", tokensBefore: 1 } },+ fakeCtx(),+ );+ assert.equal(compaction, undefined, "pi keeps its own compaction");+ await handlers.get("session_shutdown")({ type: "session_shutdown", reason: "quit" }, fakeCtx());+ assert.deepEqual(server.requests.filter((r) => r.startsWith("POST")), []);+ });+ });+}