[Bug]: the MCP server takes every project's pending events.md into its own store, so resume snapshots are lost or land in the wrong project
Platform
Other. I reproduced this against server.bundle.mjs on next, not through a client. The code path is shared by every platform.
context-mode version
1.0.169 (next at e31360dc860594d9bb70664ccc992c3dda5120d7; main at a2fda46 has the same code)
Summary
All projects write their resume snapshot to one shared sessions directory. The first MCP server that calls getStore() picks up every pending *-events.md there, no matter which project wrote it, indexes each one into its own project's store under the label session-events, and deletes the file. Indexing replaces any earlier source with the same label, so only the last file survives.
So when project B resumes or compacts a session while project A's server is running, and A's server handles a tool call first, it takes B's snapshot. If A had a pending snapshot too, only one of the two survives, and B's session never finds its snapshot because the file is gone.
It should only index its own project's <hash><suffix>-events.md and leave other projects' files alone.
Where
src/server.ts:509-522:readdirSync(sessionsDir).filter(f => f.endsWith("-events.md")), thenstore.index({ path, source: "session-events" })andunlinkSyncfor each file.src/store.ts:1049-1052:indexdeletes every earlier source with the same label before inserting.src/server.ts:697: the store is per project (resolveContentStorePath({ projectDir: getProjectDir() })), while the sessions dir fromsrc/server.ts:583-585is shared.- The comment at
src/server.ts:503-505says the server can't know the project dir.getProjectDir()(src/server.ts:598) now readsCONTEXT_MODE_PROJECT_DIR, whichstart.mjs:49-50sets, andhooks/session-helpers.mjs:417-419already computes the per-project events path.
Exact prompt that triggered the bug
No prompt is needed. The trigger is two projects with pending snapshots when one server handles any ctx_* call.
Full error output
There is none. Nothing throws. The snapshot is lost silently.
Steps to reproduce
In a clone of next after npm install, save this as repro-events.mjs and run node repro-events.mjs ./server.bundle.mjs. It starts the real server for project A with a throwaway CONTEXT_MODE_DIR, puts one pending snapshot per project in the sessions dir, and searches for a word from each.
import { spawn } from "node:child_process";
import { mkdtempSync, mkdirSync, writeFileSync, readdirSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
const root = mkdtempSync(join(tmpdir(), "cm-events-"));
const sessions = join(root, "sessions");
mkdirSync(sessions, { recursive: true });
mkdirSync(join(root, "projA"));
writeFileSync(join(sessions, "aaaaaaaaaaaaaaaa-events.md"), "# Session resume\n\nproject A was fixing the zebrafinch parser\n");
writeFileSync(join(sessions, "bbbbbbbbbbbbbbbb-events.md"), "# Session resume\n\nproject B was fixing the kookaburra renderer\n");
console.log("before:", readdirSync(sessions));
const server = spawn(process.execPath, [process.argv[2]], {
env: { ...process.env, HOME: root, CONTEXT_MODE_DIR: root, CONTEXT_MODE_PROJECT_DIR: join(root, "projA") },
stdio: ["pipe", "pipe", "ignore"],
});
let buf = "";
const waiting = new Map();
server.stdout.on("data", (d) => {
buf += d;
let i;
while ((i = buf.indexOf("\n")) >= 0) {
const msg = JSON.parse(buf.slice(0, i));
buf = buf.slice(i + 1);
waiting.get(msg.id)?.(msg);
}
});
let next = 1;
const rpc = (method, params) => new Promise((res) => {
const id = next++;
waiting.set(id, res);
server.stdin.write(JSON.stringify({ jsonrpc: "2.0", id, method, params }) + "\n");
});
await rpc("initialize", { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "repro", version: "0" } });
server.stdin.write(JSON.stringify({ jsonrpc: "2.0", method: "notifications/initialized" }) + "\n");
for (const q of ["zebrafinch", "kookaburra"]) {
const r = await rpc("tools/call", { name: "ctx_search", arguments: { queries: [q], source: "session-events" } });
console.log(`ctx_search ${q}:`, JSON.stringify(r.result.content[0].text.slice(0, 160)));
}
console.log("after:", readdirSync(sessions));
server.kill();Output on macOS, Node 26.7.0:
before: [ 'aaaaaaaaaaaaaaaa-events.md', 'bbbbbbbbbbbbbbbb-events.md' ]
ctx_search zebrafinch: "## zebrafinch\nNo results found.\n\n> Throttle: call #1/8 in this window. 2 call(s) before soft cap. Prefer ctx_search(queries: [...]) array form for multi-query w"
ctx_search kookaburra: "## kookaburra\n\n--- [current-session | 2026-09-27 09:11 | session-events] ---\n### Session resume\n\n# Session resume\n\nproject B was fixing the kookaburra renderer\n"
after: [ 'stats-pid-1817.json' ]Project A's server returns project B's snapshot, cannot find its own, and both files are gone from disk.
What have you tried to fix it?
I traced it to the lines above. The fix I have in mind is to resolve this project's own events path the way the hooks do and index only that file, keeping the session-events label so the snapshot's search hint still matches. If that shape works for you I can open a PR against next.
Operating System
macOS (Apple Silicon)
JS Runtime
Node 26.7.0
Claude (via omp) found this and wrote the repro script.
Source: mksglu/context-mode