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): archive every message on session commit (#5459)
t0saki71bd2170889e
diff --git a/docs/en/agent-integrations/10-opencode.md b/docs/en/agent-integrations/10-opencode.mdindex dcc55b0ec..b343c634c 100644--- a/docs/en/agent-integrations/10-opencode.md+++ b/docs/en/agent-integrations/10-opencode.md@@ -114,7 +114,6 @@ Behavior knobs live in the `plugin` section of `~/.openviking/ovcli.conf`, besid"recallTokenBudget": 2000,"minQueryLength": 3,"commitTokenThreshold": 20000,- "commitKeepRecentCount": 10,"profileTokenBudget": 10000,"skillCatalog": true,"skillCatalogTokenBudget": 1200,diff --git a/docs/en/agent-integrations/11-pi.md b/docs/en/agent-integrations/11-pi.mdindex adadcafd2..ef9ed4080 100644--- a/docs/en/agent-integrations/11-pi.md+++ b/docs/en/agent-integrations/11-pi.md@@ -71,7 +71,6 @@ Behavior and peer-scoping knobs live in the `plugin` section of `~/.openviking/o"skillCatalogTokenBudget": 1200,"resumeContextBudget": 32000,"commitTokenThreshold": 20000,- "commitKeepRecentCount": 10,"captureAssistantTurns": true,"pi": {"workspacePeer": true,@@ -90,6 +89,8 @@ Behavior and peer-scoping knobs live in the `plugin` section of `~/.openviking/oSettings resolve highest priority first: `OPENVIKING_*` environment variables, the workspace's `.openviking/config.json` and `config.local.json`, `plugin.pi`, `plugin`, then the built-in defaults. `autoCapture: false` — the extension's older spelling is `syncTurns` — stops it sending turns back, and `autoRecall: false` stops it retrieving.+`commitKeepRecentCount` (`OPENVIKING_COMMIT_KEEP_RECENT_COUNT`) is no longer read: commits outside takeover archive all captured messages, and takeover sends the exact message count of the turns it keeps. Delete it from existing config.+`profileTokenBudget` covers the profile and memory indexes in the session-start block. The `<available-skills>` catalog has its own budget, `skillCatalogTokenBudget` (default `1200`, env `OPENVIKING_SKILL_CATALOG_TOKEN_BUDGET`): your own skills come first, then the ones shared under `viking://agent/skills`, leaving out a shared skill that has the same name as one of yours. When the descriptions do not fit, the catalog lists names only (with a `... +N more` tail if even the names do not all fit), and when not even one name fits, a one-line count. `skillCatalog: false` (`OPENVIKING_SKILL_CATALOG=0`) or a budget of `0` turns the catalog off; with no skills, or on a server without `GET /api/v1/skills`, it is left out.`OPENVIKING_PEER_ID` outranks every file. Below it the more specific layer wins, so a workspace `peer.id` or a `peerId` set in the `plugin` section takes precedence over `ovcli.conf`'s `actor_peer_id` and `ov.conf`'s `pi.peerId`. Any peer named by one of those layers takes precedence over the workspace-derived peer, which is used only when `workspacePeer` is enabled and no layer names one.diff --git a/docs/en/agent-integrations/16-capability-reference.md b/docs/en/agent-integrations/16-capability-reference.mdindex 803507846..71ea45f3a 100644--- a/docs/en/agent-integrations/16-capability-reference.md+++ b/docs/en/agent-integrations/16-capability-reference.md@@ -297,7 +297,7 @@ Injected context is wrapped in fixed tags such as `<openviking-context>`, and ca- **Sessions are created implicitly.** The server creates a session when it receives the first message for it, or on the first context-mode recall with that session ID. DSH is the only integration that creates its sessions explicitly.- **A commit has two phases.** `POST /api/v1/sessions/{id}/commit` returns after phase 1 archives the messages. Its response includes a `task_id` for phase 2, memory extraction, which runs in the background. A successful commit response does not mean extraction has finished.-- **`keep_recent_count`** sets how many recent messages a commit leaves live in the session. The server default is 0, which archives everything. Claude Code, Codex, OpenCode, and DSH send 10 on threshold commits; Cursor, TRAE, TRAE CN, ZCode, and Hermes send 0; pi sends the exact message count of its last 3 user turns in takeover mode and 10 otherwise; OpenClaw sends 10 on its threshold commit and 0 on reset, `memory_store`, and compaction.+- **`keep_recent_count`** sets how many recent messages a commit leaves live in the session. The server default is 0, which archives everything. Claude Code, Codex, OpenCode, DSH, Cursor, TRAE, TRAE CN, ZCode, and Hermes send 0; pi sends the exact message count of its last 3 user turns in takeover mode and 0 otherwise; OpenClaw sends 10 on its threshold commit and 0 on reset, `memory_store`, and compaction.- **Server auto-commit is off by default.** `memory.session_auto_commit.enabled` defaults to `false`, and the idle scanner does not start while it is off. A new session can still get a policy from `server.user_config_defaults.auto_commit_policy`, or explicitly through `POST /api/v1/sessions`, `PATCH /api/v1/sessions/{id}/config`, the SDK, or `ov session new --auto-commit-policy-json` and `ov session config set`. A policy's defaults are 150,000 pending tokens (strictly greater than), 100 messages, an 86,400-second idle timeout, `keep_recent_count` 0, and no minimum interval. The idle timeout also needs `memory.session_auto_commit.enabled=true`. The memory plugins send no policy, so without one of these settings the client is the only thing that commits.- **Writes are batched.** The shared plugins send up to 100 messages per `POST /messages/batch`, matching the server limit, and fall back to one message at a time when the batch endpoint returns 404 or 405.- **Large tool output is stored separately.** The server moves tool output above 20,000 characters into a separate record and leaves a `tool_output_ref`. Plugins raise their own limit (`captureToolMaxChars`) to 1,000,000 only as a safety net.diff --git a/docs/en/agent-integrations/17-dsh.md b/docs/en/agent-integrations/17-dsh.mdindex f09a090a8..66257b85a 100644--- a/docs/en/agent-integrations/17-dsh.md+++ b/docs/en/agent-integrations/17-dsh.md@@ -52,7 +52,7 @@ For MCP proxy diagnostics, set `OPENVIKING_DEBUG=1` and `OPENVIKING_DEBUG_LOG=/t## How it works-The bundle runs inside DSH as a Cordis plugin rather than as external hooks, so it follows the session in-process. At session start it injects your OpenViking profile block, an index of available memories, and an `<available-skills>` catalog of your OpenViking skills. When a model step takes new user input, it searches OpenViking with the text the user typed and appends what it finds to that step as a durable message, so the injection replays with the session and is visible to compaction. Context that DSH or other plugins inject (for example `time-context` or job notices) and tool results neither trigger recall nor enter the query. It captures user, assistant, and (optionally) tool-result messages straight from DSH's event stream, skipping injected context, and commits to OpenViking once pending tokens cross the threshold, keeping the ten most recent messages live. Writes that fail land in a pending queue and replay at the next session start.+The bundle runs inside DSH as a Cordis plugin rather than as external hooks, so it follows the session in-process. At session start it injects your OpenViking profile block, an index of available memories, and an `<available-skills>` catalog of your OpenViking skills. When a model step takes new user input, it searches OpenViking with the text the user typed and appends what it finds to that step as a durable message, so the injection replays with the session and is visible to compaction. Context that DSH or other plugins inject (for example `time-context` or job notices) and tool results neither trigger recall nor enter the query. It captures user, assistant, and (optionally) tool-result messages straight from DSH's event stream, skipping injected context, and commits to OpenViking once pending tokens cross the threshold, archiving every captured message. Writes that fail land in a pending queue and replay at the next session start.Each DSH session maps to `dsh-<session-id>` in OpenViking, and every subagent gets its own session.diff --git a/docs/zh/agent-integrations/10-opencode.md b/docs/zh/agent-integrations/10-opencode.mdindex bb56d440e..5038c2592 100644--- a/docs/zh/agent-integrations/10-opencode.md+++ b/docs/zh/agent-integrations/10-opencode.md@@ -114,7 +114,6 @@ node examples/opencode-plugin/scripts/setup.mjs"recallTokenBudget": 2000,"minQueryLength": 3,"commitTokenThreshold": 20000,- "commitKeepRecentCount": 10,"profileTokenBudget": 10000,"skillCatalog": true,"skillCatalogTokenBudget": 1200,diff --git a/docs/zh/agent-integrations/11-pi.md b/docs/zh/agent-integrations/11-pi.mdindex 64bb12655..31f22f97c 100644--- a/docs/zh/agent-integrations/11-pi.md+++ b/docs/zh/agent-integrations/11-pi.md@@ -71,7 +71,6 @@ node ~/.pi/agent/extensions/openviking/scripts/setup.mjs"skillCatalogTokenBudget": 1200,"resumeContextBudget": 32000,"commitTokenThreshold": 20000,- "commitKeepRecentCount": 10,"captureAssistantTurns": true,"pi": {"workspacePeer": true,@@ -90,6 +89,8 @@ node ~/.pi/agent/extensions/openviking/scripts/setup.mjs配置项按优先级从高到低解析:`OPENVIKING_*` 环境变量、工作区的 `.openviking/config.json` 与 `config.local.json`、`plugin.pi`、`plugin`,最后是内置默认值。`autoCapture: false`(本扩展的旧拼写是 `syncTurns`)让它不再回写对话,`autoRecall: false` 让它不再检索。+`commitKeepRecentCount`(`OPENVIKING_COMMIT_KEEP_RECENT_COUNT`)已不再生效:takeover 之外的 commit 会归档全部已捕获的消息,takeover 则发送它保留的那几轮对应的确切消息数。现有配置里的这个键可以直接删掉。+`profileTokenBudget` 只管 session 开始时注入的 profile 和记忆索引。`<available-skills>` skill 清单有独立的预算 `skillCatalogTokenBudget`(默认 `1200`,环境变量 `OPENVIKING_SKILL_CATALOG_TOKEN_BUDGET`):先列你自己的 skill,再列 `viking://agent/skills` 下共享的 skill;共享 skill 与你自己的 skill 同名时不再列出。放不下描述时只列 skill 名,名字也列不全时末尾注明 `... +N more`;连一个名字都放不下时,只写一行 skill 总数。设置 `skillCatalog: false`(`OPENVIKING_SKILL_CATALOG=0`)或把预算设为 `0` 即可关闭 skill 清单;没有 skill,或服务端没有 `GET /api/v1/skills` 接口时,这一块会直接省略。`OPENVIKING_PEER_ID` 优先于所有配置文件。在它之下,更具体的一层胜出:workspace 的 `peer.id` 和 `plugin` 段里写的 `peerId` 都优先于 `ovcli.conf` 的 `actor_peer_id` 和 `ov.conf` 的 `pi.peerId`。任何一层给出的显式 peer 又都优先于 workspace 派生值。只有启用 `workspacePeer` 且所有层都未给出 peer 时,才会从工作区派生。diff --git a/docs/zh/agent-integrations/16-capability-reference.md b/docs/zh/agent-integrations/16-capability-reference.mdindex be2492c09..facd95368 100644--- a/docs/zh/agent-integrations/16-capability-reference.md+++ b/docs/zh/agent-integrations/16-capability-reference.md@@ -296,7 +296,7 @@ Claude Code 和 Codex 默认 `auto`,其他集成默认 `off`。支持服务端- **会话隐式创建**。服务端收到某个会话的第一条消息时创建该会话;带该会话 ID 的第一次 context 模式召回也会创建。DSH 是唯一显式创建会话的集成。- **提交分两个阶段**。`POST /api/v1/sessions/{id}/commit` 在第一阶段归档消息后返回。响应中带有第二阶段(记忆抽取)的 `task_id`,抽取在后台运行。提交请求成功不代表抽取已经完成。-- **`keep_recent_count`** 决定提交后会话中保留多少条最近的消息。服务端默认 0,即全部归档。Claude Code、Codex、OpenCode 和 DSH 在阈值提交时发送 10;Cursor、TRAE、TRAE CN、ZCode 和 Hermes 发送 0;pi 在 takeover 模式下发送最近 3 个用户轮对应的确切消息数,其他情况发送 10;OpenClaw 在阈值提交时发送 10,在 reset、`memory_store` 和压缩时发送 0。+- **`keep_recent_count`** 决定提交后会话中保留多少条最近的消息。服务端默认 0,即全部归档。Claude Code、Codex、OpenCode、DSH、Cursor、TRAE、TRAE CN、ZCode 和 Hermes 发送 0;pi 在 takeover 模式下发送最近 3 个用户轮对应的确切消息数,其他情况发送 0;OpenClaw 在阈值提交时发送 10,在 reset、`memory_store` 和压缩时发送 0。- **服务端自动提交默认关闭**。`memory.session_auto_commit.enabled` 默认 `false`,关闭时空闲扫描器不会启动。新会话仍可以从 `server.user_config_defaults.auto_commit_policy` 获得策略,也可以通过 `POST /api/v1/sessions`、`PATCH /api/v1/sessions/{id}/config`、SDK,或 `ov session new --auto-commit-policy-json` 与 `ov session config set` 显式设置。策略的默认值是:待提交 token 150,000(严格大于)、100 条消息、86,400 秒空闲超时、`keep_recent_count` 0、无最小间隔。空闲超时还需要 `memory.session_auto_commit.enabled=true`。记忆插件不发送策略,所以没有上述设置时,只有客户端会提交。- **批量写入**。共享插件每次 `POST /messages/batch` 最多发送 100 条消息,与服务端上限一致;批量接口返回 404 或 405 时改为逐条发送。- **大块工具输出单独存放**。服务端把超过 20,000 字符的工具输出移到单独的记录中,留下 `tool_output_ref`。插件把自己的上限(`captureToolMaxChars`)提高到 1,000,000,只作为兜底。diff --git a/docs/zh/agent-integrations/17-dsh.md b/docs/zh/agent-integrations/17-dsh.mdindex b9f104866..96c8b6977 100644--- a/docs/zh/agent-integrations/17-dsh.md+++ b/docs/zh/agent-integrations/17-dsh.md@@ -52,7 +52,7 @@ curl -fsSL https://openviking.ai/install | bash## 工作方式-插件以 Cordis 插件的形式跑在 DSH 进程内,而不是外挂 hook,因此能贴着会话走。会话开始时注入 OpenViking 画像块、可用记忆索引和 OpenViking 技能清单 `<available-skills>`;模型步骤带有新的用户输入时,用用户输入的文本做语义检索,把结果作为持久消息追加到同一步骤,因此注入会随会话重放,也对压缩可见。DSH 或其他插件注入的上下文(例如 `time-context`、job 通知)和工具结果既不触发召回,也不拼进检索文本。它直接从 DSH 的事件流捕获 user、assistant 以及(可选的)工具结果消息,并跳过注入的上下文,待同步 token 超过阈值即 commit,并保留最近十条消息在本地上下文中。写入失败会进入待写队列,在下次会话开始时重放。+插件以 Cordis 插件的形式跑在 DSH 进程内,而不是外挂 hook,因此能贴着会话走。会话开始时注入 OpenViking 画像块、可用记忆索引和 OpenViking 技能清单 `<available-skills>`;模型步骤带有新的用户输入时,用用户输入的文本做语义检索,把结果作为持久消息追加到同一步骤,因此注入会随会话重放,也对压缩可见。DSH 或其他插件注入的上下文(例如 `time-context`、job 通知)和工具结果既不触发召回,也不拼进检索文本。它直接从 DSH 的事件流捕获 user、assistant 以及(可选的)工具结果消息,并跳过注入的上下文,待同步 token 超过阈值即 commit,每次 commit 都归档全部已捕获的消息。写入失败会进入待写队列,在下次会话开始时重放。每个 DSH 会话映射为 OpenViking 中的 `dsh-<session-id>`,子 agent 各自拥有独立会话。diff --git a/examples/claude-code-memory-plugin/scripts/auto-capture.mjs b/examples/claude-code-memory-plugin/scripts/auto-capture.mjsindex 183cfd38b..7bb81b504 100644--- a/examples/claude-code-memory-plugin/scripts/auto-capture.mjs+++ b/examples/claude-code-memory-plugin/scripts/auto-capture.mjs@@ -410,9 +410,7 @@ async function main({ cfg, input, cwd }) {totalMessageCount = Number(meta?.total_message_count || 0);log("pending_tokens", { ovSessionId, pending: pendingTokens, threshold: cfg.commitTokenThreshold });if (pendingTokens >= cfg.commitTokenThreshold) {- const commitRes = await commitSession(fetchJSON, ovSessionId, {- keep_recent_count: cfg.commitKeepRecentCount,- });+ const commitRes = await commitSession(fetchJSON, ovSessionId, { keep_recent_count: 0 });committed = commitRes.ok;commitTraceId = commitRes.traceId || commitRes.result?.trace_id || "";if (committed) commitCount += 1;@@ -421,7 +419,6 @@ async function main({ cfg, input, cwd }) {ok: commitRes.ok,trace_id: commitTraceId || undefined,pending: pendingTokens,- keepRecentCount: cfg.commitKeepRecentCount,});}}diff --git a/examples/claude-code-memory-plugin/scripts/auto-capture.test.mjs b/examples/claude-code-memory-plugin/scripts/auto-capture.test.mjsindex 786d3a223..7b55d9177 100644--- a/examples/claude-code-memory-plugin/scripts/auto-capture.test.mjs+++ b/examples/claude-code-memory-plugin/scripts/auto-capture.test.mjs@@ -126,6 +126,54 @@ test("failed non-retryable capture keeps the cursor for a later retry", async ()}});+test("threshold commit archives every captured message", async () => {+ const root = await mkdtemp(join(tmpdir(), "ov-cc-capture-commit-"));+ const transcriptPath = join(root, "transcript.jsonl");+ const commits = [];++ try {+ await writeTranscript(transcriptPath);+ await withMockOpenViking(async (req, res) => {+ const url = new URL(req.url, "http://127.0.0.1");+ if (req.method === "GET" && url.pathname === "/health") {+ writeJson(res, { status: "ok", result: { healthy: true } });+ return;+ }+ if (req.method === "POST" && url.pathname.endsWith("/messages/batch")) {+ const body = await readRequestBody(req);+ writeJson(res, { status: "ok", result: { added: body.messages.length } });+ return;+ }+ if (req.method === "GET" && url.pathname === "/api/v1/sessions/cc-capture-commit") {+ writeJson(res, {+ status: "ok",+ result: { message_count: 2, pending_tokens: 5000, commit_count: 0 },+ });+ return;+ }+ if (req.method === "POST" && url.pathname === "/api/v1/sessions/cc-capture-commit/commit") {+ commits.push(await readRequestBody(req));+ writeJson(res, { status: "ok", result: { status: "accepted" } });+ return;+ }+ writeJson(res, { status: "error", error: { code: "NOT_FOUND" } }, 404);+ }, async (baseUrl) => {+ await runAutoCapture(+ { session_id: "capture-commit", transcript_path: transcriptPath, cwd: root },+ {+ ...hookEnv(root, baseUrl),+ OPENVIKING_COMMIT_TOKEN_THRESHOLD: "1000",+ OPENVIKING_COMMIT_KEEP_RECENT_COUNT: "10",+ },+ );+ });++ assert.deepEqual(commits, [{ keep_recent_count: 0 }]);+ } finally {+ await rm(root, { recursive: true, force: true });+ }+});+test("legacy advanced cursor rewinds when the server session is empty", async () => {const root = await mkdtemp(join(tmpdir(), "ov-cc-capture-rewind-"));const transcriptPath = join(root, "transcript.jsonl");diff --git a/examples/codex-memory-plugin/DESIGN.md b/examples/codex-memory-plugin/DESIGN.mdindex 4f8bfe456..ec7eb163c 100644--- a/examples/codex-memory-plugin/DESIGN.md+++ b/examples/codex-memory-plugin/DESIGN.md@@ -226,10 +226,10 @@ available until that catch-up succeeds.After a complete append, Stop reads session meta and commits when`pending_tokens >= OPENVIKING_COMMIT_TOKEN_THRESHOLD` (default 20000).The threshold commit passes-`keep_recent_count=OPENVIKING_COMMIT_KEEP_RECENT_COUNT` (default 10) so-the newest turns stay live after archive/extract. This keeps long-running-sessions from waiting until PreCompact/SessionStart while still avoiding-commit-on-every-turn fragmentation.+`keep_recent_count=0`: Codex keeps its own transcript, so a live tail in+OpenViking would only delay extraction. Committing at the threshold+keeps long-running sessions from waiting until PreCompact/SessionStart+while still avoiding commit-on-every-turn fragmentation.## Injected context boundarydiff --git a/examples/codex-memory-plugin/README.md b/examples/codex-memory-plugin/README.mdindex c65b43d22..f9bf3482a 100644--- a/examples/codex-memory-plugin/README.md+++ b/examples/codex-memory-plugin/README.md@@ -15,7 +15,7 @@ This is the Codex counterpart to [`claude-code-memory-plugin`](../claude-code-me- **Auto-recall** relevant memories on every `UserPromptSubmit` and inject them via `hookSpecificOutput.additionalContext`- **OV-Usage source summaries** after each answer: show sources made available through automatic recall and explicit OpenViking lookups, with optional source URI and query details.- **`viking://` notice on `PreToolUse` (`Bash`)**: a shell command that carries a `viking://` URI still runs, and the model is told that the URI is an OpenViking virtual path and which MCP tool reads it.-- **Incremental capture on `Stop`** (turn end): append the new user/assistant turns to a deterministic OpenViking session id `cx-<codex_session_id>`. When `pending_tokens` reaches `OPENVIKING_COMMIT_TOKEN_THRESHOLD`, commit while keeping a recent live tail.+- **Incremental capture on `Stop`** (turn end): append the new user/assistant turns to a deterministic OpenViking session id `cx-<codex_session_id>`. When `pending_tokens` reaches `OPENVIKING_COMMIT_TOKEN_THRESHOLD`, commit and archive every captured message.- **Commit on `PreCompact`**: trigger OpenViking's memory extractor on the full pre-compact transcript before Codex summarizes it.- **Commit on `SessionEnd`** (Codex ≥ 0.145): when a thread shuts down gracefully, catch up any turns `Stop` never sent and commit the OV session, so the extractor runs on the whole conversation the moment you leave.- **Fallback sweep on `SessionStart` (source=startup|clear)**: commit state files that carry an end marker whose commit did not go through, or that have been idle past `OPENVIKING_CODEX_IDLE_TTL_MS`. `source=resume` never commits or sweeps; if the live OV session was already committed, it combines the profile block with the latest archive summary for continuity. See `DESIGN.md` for the full decision tree.@@ -391,7 +391,7 @@ Nothing is denied: Codex edits files through `apply_patch`, whose input is a pat`auto-capture.mjs` derives one long-lived OpenViking session id per Codex `session_id` as `cx-<safe-session-id>` and incrementally appends every new user/assistant turn via `/api/v1/sessions/{id}/messages`. The `/messages` endpoint auto-creates the session on first append. Per-codex-session state lives at `~/.openviking/codex-plugin-state/<safe-session-id>.json`. Capture sanitizes obvious hook noise, metadata wrappers, and plugin-injected `<openviking-context ...>` blocks before append. Tool calls and results become dedicated `tool` parts and `tool_output` is reported verbatim — the server externalizes anything larger than `tool_output_externalization.threshold_chars` (default `20000`) and leaves a synopsis stub plus `tool_output_ref`, so the original stays readable via `/api/v1/sessions/{id}/tool-results`. `OPENVIKING_CAPTURE_TOOL_MAX_CHARS` (default `1000000`) is only a guard against pathological payloads. Configured `captureFilters` rules run last, just before the payload is sent — see [Input filters](#input-filters).-After a successful append, Stop reads the session meta and commits when `pending_tokens >= OPENVIKING_COMMIT_TOKEN_THRESHOLD` (default `20000`). Threshold commits pass `keep_recent_count=OPENVIKING_COMMIT_KEEP_RECENT_COUNT` (default `10`) so the newest turns remain live for continuity while older context is archived and extracted. `PreCompact` still commits everything before compaction.+After a successful append, Stop reads the session meta and commits when `pending_tokens >= OPENVIKING_COMMIT_TOKEN_THRESHOLD` (default `20000`). Threshold commits pass `keep_recent_count=0`: Codex keeps its own transcript, so every captured message is archived and extracted. `PreCompact` also commits everything before compaction, whatever `pending_tokens` is.### PreCompact (deterministic commit)diff --git a/examples/codex-memory-plugin/scripts/auto-capture.mjs b/examples/codex-memory-plugin/scripts/auto-capture.mjsindex b0dc82f24..dafd26ece 100644--- a/examples/codex-memory-plugin/scripts/auto-capture.mjs+++ b/examples/codex-memory-plugin/scripts/auto-capture.mjs@@ -11,8 +11,8 @@* id (`cx-<codex-session-id>`) and remember it in state.* 2. Read transcript_path, parse JSONL rollout, append every new* user/assistant turn since last capture via add_message.- * 3. If session pending_tokens crosses commitTokenThreshold, commit while- * keeping a recent live tail for continuity.+ * 3. If session pending_tokens crosses commitTokenThreshold, commit and+ * archive every captured message.** A Stop for this session also proves the thread is alive again, so the* SessionEnd marker (if any) is cleared before anything else. Committing is@@ -70,14 +70,13 @@ async function maybeCommitByThreshold(ovSessionId, added) {ovSessionId,pending: pendingTokens,threshold: cfg.commitTokenThreshold,- keepRecentCount: cfg.commitKeepRecentCount,});if (pendingTokens < cfg.commitTokenThreshold) {return { committed: false, pendingTokens, commitCount, totalMessageCount, traceId: "" };}const commit = await fetchJSONRes(`/api/v1/sessions/${encodeURIComponent(ovSessionId)}/commit`, {method: "POST",- body: JSON.stringify({ keep_recent_count: cfg.commitKeepRecentCount }),+ body: JSON.stringify({ keep_recent_count: 0 }),});const committed = commit.ok;const traceId = commit.traceId || commit.result?.trace_id || "";diff --git a/examples/codex-memory-plugin/scripts/auto-capture.test.mjs b/examples/codex-memory-plugin/scripts/auto-capture.test.mjsindex e55dca1a4..d00fed675 100644--- a/examples/codex-memory-plugin/scripts/auto-capture.test.mjs+++ b/examples/codex-memory-plugin/scripts/auto-capture.test.mjs@@ -155,7 +155,7 @@ test("auto-capture commits when pending tokens cross threshold", async () => {const commitCall = calls.find((call) => call.path.endsWith("/commit"));const debugLog = await readFile(debugLogPath, "utf-8").catch(() => "");assert.ok(commitCall, `expected threshold commit call; calls=${JSON.stringify(calls)} debug=${debugLog}`);- assert.deepEqual(commitCall.body, { keep_recent_count: 7 });+ assert.deepEqual(commitCall.body, { keep_recent_count: 0 });assert.match(debugLog, /"trace_id":"trace-codex-commit"/);const batchCall = calls.find((call) => call.path.endsWith("/messages/batch"));diff --git a/examples/dsh-memory-plugin/client.mjs b/examples/dsh-memory-plugin/client.mjsindex 329972da0..a97d15221 100644--- a/examples/dsh-memory-plugin/client.mjs+++ b/examples/dsh-memory-plugin/client.mjs@@ -49,7 +49,7 @@ export class OpenVikingClient {`/api/v1/sessions/${encodeURIComponent(sessionId)}/commit`,{method: "POST",- body: JSON.stringify({ keep_recent_count: this.config.commitKeepRecentCount }),+ body: JSON.stringify({ keep_recent_count: 0 }),},{ timeoutMs: options.timeoutMs ?? 30000, actorPeerId },);diff --git a/examples/dsh-memory-plugin/client.test.mjs b/examples/dsh-memory-plugin/client.test.mjsindex bdea87908..ee4a7ef80 100644--- a/examples/dsh-memory-plugin/client.test.mjs+++ b/examples/dsh-memory-plugin/client.test.mjs@@ -37,6 +37,7 @@ test("client sends OpenViking identity headers and preserves response trace ids"assert.equal(response.ok, true);assert.equal(response.traceId, "trace-123");assert.equal(seen.url, "http://127.0.0.1:1933/api/v1/sessions/dsh-1/commit");+ assert.deepEqual(JSON.parse(seen.init.body), { keep_recent_count: 0 });assert.equal(seen.init.headers.Authorization, "Bearer secret");assert.equal(seen.init.headers["X-OpenViking-Account"], "account-a");assert.equal(seen.init.headers["X-OpenViking-User"], "user-a");@@ -60,7 +61,6 @@ test("per-session actor peer overrides the process default", async () => {peerId: "process-peer",userAgent: "",requestTimeoutMs: 1000,- commitKeepRecentCount: 10,});await client.ensureSessionResult("dsh-2", "workspace-peer");@@ -84,7 +84,6 @@ test("client normalizes non-2xx OpenViking envelopes", async () => {peerId: "",userAgent: "",requestTimeoutMs: 1000,- commitKeepRecentCount: 10,});const response = await client.fetchJSON("/probe");diff --git a/examples/dsh-memory-plugin/live-recall.test.mjs b/examples/dsh-memory-plugin/live-recall.test.mjsindex 548094530..33d05c883 100644--- a/examples/dsh-memory-plugin/live-recall.test.mjs+++ b/examples/dsh-memory-plugin/live-recall.test.mjs@@ -14,9 +14,7 @@ import { buildRecallBlock } from "./shared/recall-core.mjs";const enabled = process.env.OPENVIKING_E2E === "1";test("live recall returns a hit for a memory stored by this test", { skip: !enabled, timeout: 300_000 }, async () => {- // keepRecentCount 0: with the default (10) a single-message session keeps- // its whole tail verbatim and extraction has nothing to mine.- const config = resolveConfig({ workspacePeer: false, scoreThreshold: 0.1, commitKeepRecentCount: 0 });+ const config = resolveConfig({ workspacePeer: false, scoreThreshold: 0.1 });const client = new OpenVikingClient(config);assert.equal((await client.healthResult()).ok, true, "OpenViking server must be reachable");diff --git a/examples/dsh-memory-plugin/runtime-drain.test.mjs b/examples/dsh-memory-plugin/runtime-drain.test.mjsindex f1d9a0e55..91778c4d7 100644--- a/examples/dsh-memory-plugin/runtime-drain.test.mjs+++ b/examples/dsh-memory-plugin/runtime-drain.test.mjs@@ -319,7 +319,6 @@ function config() {captureToolMaxChars: 1000000,captureMaxLength: 24000,captureMode: "semantic",- commitKeepRecentCount: 10,};}diff --git a/examples/dsh-memory-plugin/runtime.mjs b/examples/dsh-memory-plugin/runtime.mjsindex d64314574..4137f8d1f 100644--- a/examples/dsh-memory-plugin/runtime.mjs+++ b/examples/dsh-memory-plugin/runtime.mjs@@ -201,9 +201,7 @@ export class OpenVikingRuntime {error: response.ok ? undefined : response.error?.message || response.error?.code,});if (isRetryableFailure(response)) {- await this.enqueueFinalCommit(state, {- keep_recent_count: state.config.commitKeepRecentCount,- });+ await this.enqueueFinalCommit(state, { keep_recent_count: 0 });}});}@@ -215,9 +213,7 @@ export class OpenVikingRuntime {state.disposing = (async () => {this.enqueueWrite(state, async () => {if (!isCaptureEnabled(state.config)) return;- const commitPayload = {- keep_recent_count: state.config.commitKeepRecentCount,- };+ const commitPayload = { keep_recent_count: 0 };if (state.hasPendingWrites) {await this.enqueueFinalCommit(state, commitPayload);return;diff --git a/examples/dsh-memory-plugin/runtime.test.mjs b/examples/dsh-memory-plugin/runtime.test.mjsindex 6b74101ff..9efceb5b0 100644--- a/examples/dsh-memory-plugin/runtime.test.mjs+++ b/examples/dsh-memory-plugin/runtime.test.mjs@@ -164,11 +164,11 @@ test("once a write is queued, later messages and the final commit stay ordered o]);assert.deepEqual(pending.map(item => (- item.entry.payload.parts?.[0]?.text- || item.entry.payload.content- || item.entry.payload.keep_recent_count+ item.entry.type === "commitSession"+ ? item.entry.payload+ : item.entry.payload.parts?.[0]?.text || item.entry.payload.content)),- ["First queued message.", "Second queued message.", 10],+ ["First queued message.", "Second queued message.", { keep_recent_count: 0 }],);assert.deepEqual(pending.map(item => item.entry.createdAt),diff --git a/examples/opencode-plugin/INSTALL-ZH.md b/examples/opencode-plugin/INSTALL-ZH.mdindex 6924017ff..551964964 100644--- a/examples/opencode-plugin/INSTALL-ZH.md+++ b/examples/opencode-plugin/INSTALL-ZH.md@@ -113,7 +113,6 @@ export { OpenVikingPlugin, default } from "./openviking/index.mjs""recallTokenBudget": 2000,"minQueryLength": 3,"commitTokenThreshold": 20000,- "commitKeepRecentCount": 10,"profileTokenBudget": 10000,"skillCatalog": true,"skillCatalogTokenBudget": 1200,diff --git a/examples/opencode-plugin/INSTALL.md b/examples/opencode-plugin/INSTALL.mdindex c5d7c1ee1..9971787f4 100644--- a/examples/opencode-plugin/INSTALL.md+++ b/examples/opencode-plugin/INSTALL.md@@ -113,7 +113,6 @@ Example configuration:"recallTokenBudget": 2000,"minQueryLength": 3,"commitTokenThreshold": 20000,- "commitKeepRecentCount": 10,"profileTokenBudget": 10000,"skillCatalog": true,"skillCatalogTokenBudget": 1200,diff --git a/examples/opencode-plugin/README.md b/examples/opencode-plugin/README.mdindex 23846da09..33e0f94f7 100644--- a/examples/opencode-plugin/README.md+++ b/examples/opencode-plugin/README.md@@ -143,7 +143,6 @@ Behaviour knobs live in `~/.openviking/ovcli.conf` beside the connection fields,"recallTokenBudget": 2000,"minQueryLength": 3,"commitTokenThreshold": 20000,- "commitKeepRecentCount": 10,"profileTokenBudget": 10000,"skillCatalog": true,"skillCatalogTokenBudget": 1200,diff --git a/examples/opencode-plugin/lib/memory-session.mjs b/examples/opencode-plugin/lib/memory-session.mjsindex f025ed5dc..cdfb7011c 100644--- a/examples/opencode-plugin/lib/memory-session.mjs+++ b/examples/opencode-plugin/lib/memory-session.mjs@@ -472,7 +472,7 @@ export function createMemorySessionManager({ config, pluginRoot }) {async function commitOvSession(ovSessionId, { force = false, reason = "manual", abortSignal } = {}) {if (!force && config.commitTokenThreshold <= 0) return { status: "skipped" }- const body = { keep_recent_count: config.commitKeepRecentCount }+ const body = { keep_recent_count: 0 }const res = await fetchJSON(config, `/api/v1/sessions/${encodeURIComponent(ovSessionId)}/commit`, {method: "POST",body: JSON.stringify(body),diff --git a/examples/opencode-plugin/tests/memory-session.test.mjs b/examples/opencode-plugin/tests/memory-session.test.mjsindex c784a8ade..2e7451385 100644--- a/examples/opencode-plugin/tests/memory-session.test.mjs+++ b/examples/opencode-plugin/tests/memory-session.test.mjs@@ -613,6 +613,7 @@ test("explicit commit writes the response trace_id to the plugin log", async ()const result = await manager.commitSession("oc-explicit-trace")assert.equal(result.traceId, "trace-opencode-commit")assert.equal(requests[0].url, "/api/v1/sessions/oc-explicit-trace/commit")+ assert.deepEqual(JSON.parse(requests[0].body), { keep_recent_count: 0 })const raw = await fs.promises.readFile(join(dir, "openviking-memory.log"), "utf8")assert.match(raw, /"trace_id":"trace-opencode-commit"/)})diff --git a/examples/pi-coding-agent-extension/DESIGN.md b/examples/pi-coding-agent-extension/DESIGN.mdindex bb00b7518..ac16ab2ad 100644--- a/examples/pi-coding-agent-extension/DESIGN.md+++ b/examples/pi-coding-agent-extension/DESIGN.md@@ -84,7 +84,7 @@ The OV session id is `pi-<pi session id>`, derived locally by the shared `derive**Backlog drain.** `flushForTakeover` is the barrier takeover waits on, and it needs the queue empty for this session. Startup restores takeover state before replay, then routes the current session through the tracked Pi drainer rather than the generic replay path. Sync drains queued `addMessage` entries through the batch endpoint, `BATCH_LIMIT` per request, and also treats active `.processing` files as undelivered. The drain is bounded by wall time (`OPENVIKING_PENDING_DRAIN_BUDGET_MS`, 10s by default, narrowed further to whatever takeover's handler budget leaves) and optionally by batch count, so a huge backlog cannot block `turn_end` indefinitely; the remainder drains on later turns. Once this session's queue is empty, startup hands other sessions' entries to the generic replay; while this session still has a backlog they wait for a later start, because the generic path drops rejected entries without recording whose gap they are. Other sessions never affect this session's barrier. The same generic replay runs in every OpenViking harness plugin on the machine over the same queue, so a gap is guaranteed to be recorded only for losses this session's own drainer sees.-**Commit.** Outside takeover, sync asks the server for `pending_tokens` after each accepted turn and commits when it crosses `commitTokenThreshold` — server-side accounting, not a local estimate. A failed commit is queued for replay unless the caller passes `queueOnFailure: false`, which takeover always does, because a commit that lands later cannot justify a boundary that moved now.+**Commit.** Outside takeover, every commit archives all captured messages (`keep_recent_count: 0`): pi keeps its recent turns in its own transcript, so the server holds back no live tail. Outside takeover, sync asks the server for `pending_tokens` after each accepted turn and commits when it crosses `commitTokenThreshold` — server-side accounting, not a local estimate. A failed commit is queued for replay unless the caller passes `queueOnFailure: false`, which takeover always does, because a commit that lands later cannot justify a boundary that moved now.### takeover.tsdiff --git a/examples/pi-coding-agent-extension/README.md b/examples/pi-coding-agent-extension/README.mdindex 9f4aa4e82..2658a0af6 100644--- a/examples/pi-coding-agent-extension/README.md+++ b/examples/pi-coding-agent-extension/README.md@@ -185,7 +185,7 @@ integrations should configure category `quotas` when they need exact ceilings.| `captureToolResults` | `false` | Declared in the shared schema, but this extension never reads it: `lib/capture-adapter.mjs` keeps every structured tool part, so tool results are captured either way, bounded by `captureToolMaxChars` || `captureToolMaxChars` | `1000000` | Guard cap on one tool part's `tool_output`; the server externalizes oversized output || `commitTokenThreshold` | `20000` | Pending-token threshold for client-driven commit |-| `commitKeepRecentCount` | `10` | Live tail kept after commit |+| `commitKeepRecentCount` | `10` | Not read: commits outside takeover archive every captured message (`keep_recent_count` 0); takeover sends the exact message count of the turns it keeps |### Context takeoverdiff --git a/examples/pi-coding-agent-extension/client.ts b/examples/pi-coding-agent-extension/client.tsindex 13787166f..ca2badb1d 100644--- a/examples/pi-coding-agent-extension/client.ts+++ b/examples/pi-coding-agent-extension/client.ts@@ -122,7 +122,7 @@ export class OVClient {/** POST /api/v1/sessions/{id}/commit — commit session for archiving + extraction */async commitSessionResponse(sessionId: string,- keepRecentCount = this.cfg.commitKeepRecentCount,+ keepRecentCount = 0,timeoutMs = 30000,enableWorkingMemory?: boolean,): Promise<OVCommitResponse> {diff --git a/examples/pi-coding-agent-extension/index.ts b/examples/pi-coding-agent-extension/index.tsindex c07e6ee05..ee4bc9cfb 100644--- a/examples/pi-coding-agent-extension/index.ts+++ b/examples/pi-coding-agent-extension/index.ts@@ -474,7 +474,7 @@ export default async function (pi: ExtensionAPI) {const reason = config.takeoverEnabled? takeover.lastFailure: skipped- ? describeSkip(String(commitResult?.reason || ""), config.commitKeepRecentCount)+ ? describeSkip(String(commitResult?.reason || "")): sync.lastCommitError;logger.log("commit", { ok: false, manual: true, reason: reason || "unknown" });if (reason.startsWith("nothing")) {diff --git a/examples/pi-coding-agent-extension/sync.ts b/examples/pi-coding-agent-extension/sync.tsindex 7775b1652..79ec41168 100644--- a/examples/pi-coding-agent-extension/sync.ts+++ b/examples/pi-coding-agent-extension/sync.ts@@ -313,7 +313,7 @@ export class SyncManager {});if (opts.queueOnFailure !== false) {await enqueue("commitSession", this.ovSessionId, {- keep_recent_count: opts.keepRecentCount ?? this.config.commitKeepRecentCount,+ keep_recent_count: opts.keepRecentCount ?? 0,});}return null;diff --git a/examples/pi-coding-agent-extension/tests/sync-barrier.test.mjs b/examples/pi-coding-agent-extension/tests/sync-barrier.test.mjsindex c836ff091..0a0a32c95 100644--- a/examples/pi-coding-agent-extension/tests/sync-barrier.test.mjs+++ b/examples/pi-coding-agent-extension/tests/sync-barrier.test.mjs@@ -4,6 +4,7 @@ import { mkdtemp, readFile, rename, rm } from "node:fs/promises";import { join } from "node:path";import { tmpdir } from "node:os";import { SyncManager, describeCommitError } from "../sync.ts";+import { OVClient } from "../client.ts";import { enqueue, listPending } from "../shared/pending-queue.mjs";function config(overrides = {}) {@@ -129,6 +130,36 @@ test("a failed commit keeps its status and server message for /viking commit", a});});+test("a commit archives every message, both when sent and when queued for retry", async () => {+ await withPendingDir(async () => {+ const ov = new OVClient({+ endpoint: "http://127.0.0.1:1933",+ apiKey: "",+ account: "",+ user: "",+ authMode: "trusted",+ sendIdentityHeaders: false,+ peerId: "",+ userAgent: "test",+ });+ const requests = [];+ ov.fetchJSON = async (path, init) => {+ requests.push({ path, body: JSON.parse(init.body) });+ return { ok: false, result: null, status: 503, error: { message: "unavailable" } };+ };+ const sync = new SyncManager(ov, config());+ await sync.ensureSession("pi-keep-zero");++ assert.equal(await sync.commit(), null);+ assert.deepEqual(requests, [{+ path: `/api/v1/sessions/${encodeURIComponent(sync.sessionId)}/commit`,+ body: { keep_recent_count: 0 },+ }]);+ const queued = (await listPending()).map(({ entry }) => [entry.type, entry.payload]);+ assert.deepEqual(queued, [["commitSession", { keep_recent_count: 0 }]]);+ });+});+test("describeCommitError names a missing response and bounds the message", () => {assert.equal(describeCommitError(0, { message: "fetch failed" }), "no response: fetch failed");assert.equal(describeCommitError(undefined, null), "no response: unknown error");