Repository navigation
Description
Summary
With OpenCode v2 (2.0.24) and opencode-supermemory@2.0.15, the plugin's tools are only available for one working directory at a time: the one whose plugin instance was loaded last. Sessions in every other directory report that supermemory and supermemory_recall are not in their tool list.
Cause
dist/server.js (setupV2) keeps a single process-wide owner in globalThis[Symbol.for("opencode-supermemory.v2.owner")]:
const previous = registry[OWNER_KEY];
previous?.cleanup(); // disposes the previous location's registrations
...
registry[OWNER_KEY] = owner;
const runtime = new V2Runtime(ctx, options, () => registry[OWNER_KEY] === owner);OpenCode v2 calls setup(ctx) once per location (directory), and one server hosts many locations. Each new location load therefore calls previous.cleanup() on a different location's runtime, which disposes its tool registrations. V2Runtime.active also becomes false, so any tool call that was already captured returns "This Supermemory plugin instance has been replaced; retry the call."
Observed
One server, sessions in several directories. ~/.opencode-supermemory.log shows the plugin re-initialising for different directories every 10 to 30 minutes, with the generation counter increasing each time:
v2 plugin init: {"generation":43,"directory":"/home/me/homelab",...}
v2 plugin init: {"generation":44,"directory":"/home/me/llm-workbench",...}
v2 plugin init: {"generation":45,"directory":"/home/me",...}
Agents in sessions whose directory was not the latest one answered: "Supermemory is not available in this session (not in my tool list)". Which directory had the tools changed over time.
Reproduction (no server needed)
Load dist/server.js and call plugin.setup(ctx) with a fake context for /a, /b and /c, counting live ctx.tool.transform registrations per ctx.location.directory.
- 2.0.15 unmodified: only the last directory loaded has a live registration. In my harness, loading
/a,/b,/cand/aagain left only/a. - Expected: one live registration per location (
/a,/band/c).
Suggested fix
Key the owner by location instead of using one global:
const owners = (registry[OWNER_KEY] ??= new Map());
const key = ctx.location?.directory ?? "";
const previous = owners.get(key);
previous?.cleanup();
owners.set(key, owner);
const runtime = new V2Runtime(ctx, options, () => owners.get(key) === owner);
// cleanup: if (owners.get(key) === owner) owners.delete(key);This still replaces a stale instance of the same location (for example after a config reload) without disposing other locations. With this change the harness above shows one live registration per directory. Running it against the real server, herald sessions in different directories all had the tools.
Environment
- opencode 2.0.24, Linux
- opencode-supermemory 2.0.15 (server entry
dist/server.js;dist/v2/index.jshas the same code) - Self-hosted Supermemory,
recallMode: advisory
Activity
qq398768650 commentedon Oct 15, 2026
Confirmed on Windows with OpenCode 2.0.29 (desktop, win-x64) + opencode-supermemory 2.0.17 — same symptom, same cause.
Evidence:
~/.opencode-supermemory.logshows 8 successive generations, one per location that got loaded (the workspace root, a subdirectory of it, the user home directory, and a few unrelated project directories):×8,
generation1..8 — exactly one per directory, only the last one keeps the tools.Sessions in any other directory get no tools:
No tool named "supermemory" is currently available. A brand-new session created after a full backend restart still reportsUnknown tool 'supermemory', so it is not a stale-session/tool-list-snapshot issue.The host still considers the plugin healthy:
GET /api/pluginreturnsstate: "active"withfeatures: ["server","tui","rpc"], andopencode plugin listshowssupermemory 2.0.17. Sosetup()/register()succeed — the registrations just get disposed for every location but the last.Tried and ruled out: clean reinstall of the plugin (2.0.17 is
latest), adding the README's OpenCode 2permissions: [{action:"supermemory_recall", resource:"*", effect:"allow"}], listing the plugin in bothpluginandplugins(this makes the host reportDuplicate plugin ID: supermemory), and a real backend restart (opencode-cli service restart).Related second symptom, in case it shares the root cause: the per-prompt recall hook stopped firing entirely after upgrading to 2.0.29 — the last
chat.message: context processedline is{"duration":0,"firstMessageContextLength":0,"directRecallContextLength":0}at2026-10-15T08:56:40Z, which is exactly when 2.0.29 was installed. Capture-on-session-end still works ([capture] conversation batch saved {reason:session_end},[activity] ◪ supermemory · saved this turn), and compaction-time injection still works. The last prompt that actually got a non-zero injection was08:40:31ZwithdirectRecallContextLength: 1472.The owner-per-location fix suggested above looks right to me. Happy to test a patched build on this setup (Windows, OpenCode 2.0.29) if that helps.