You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
v2 server plugin: only the most recently loaded location keeps its supermemory / supermemory_recall tools #104
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")]:
constprevious=registry[OWNER_KEY];previous?.cleanup();// disposes the previous location's registrations
...
registry[OWNER_KEY]=owner;construntime=newV2Runtime(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:
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:
constowners=(registry[OWNER_KEY]??=newMap());constkey=ctx.location?.directory??"";constprevious=owners.get(key);previous?.cleanup();owners.set(key,owner);construntime=newV2Runtime(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)
Confirmed on Windows with OpenCode 2.0.29 (desktop, win-x64) + opencode-supermemory 2.0.17 — same symptom, same cause.
Evidence:
~/.opencode-supermemory.log shows 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, generation 1..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 reports Unknown tool 'supermemory', so it is not a stale-session/tool-list-snapshot issue.
The host still considers the plugin healthy: GET /api/plugin returns state: "active" with features: ["server","tui","rpc"], and opencode plugin list shows supermemory 2.0.17. So setup()/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 2 permissions: [{action:"supermemory_recall", resource:"*", effect:"allow"}], listing the plugin in bothplugin and plugins (this makes the host report Duplicate 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 processed line is {"duration":0,"firstMessageContextLength":0,"directRecallContextLength":0} at 2026-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 was 08:40:31Z with directRecallContextLength: 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.
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.