Skip to content

v2 server plugin: only the most recently loaded location keeps its supermemory / supermemory_recall tools #104

Description

@lehneres

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions