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, /c and /a again left only /a.
- Expected: one live registration per location (
/a, /b and /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.js has the same code)
- Self-hosted Supermemory,
recallMode: advisory
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 thatsupermemoryandsupermemory_recallare not in their tool list.Cause
dist/server.js(setupV2) keeps a single process-wide owner inglobalThis[Symbol.for("opencode-supermemory.v2.owner")]:OpenCode v2 calls
setup(ctx)once per location (directory), and one server hosts many locations. Each new location load therefore callsprevious.cleanup()on a different location's runtime, which disposes its tool registrations.V2Runtime.activealso 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.logshows the plugin re-initialising for different directories every 10 to 30 minutes, with the generation counter increasing each time: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.jsand callplugin.setup(ctx)with a fake context for/a,/band/c, counting livectx.tool.transformregistrations perctx.location.directory./a,/b,/cand/aagain left only/a./a,/band/c).Suggested fix
Key the owner by location instead of using one global:
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
dist/server.js;dist/v2/index.jshas the same code)recallMode: advisory