OpenCode plugin can record observations without ever creating the session
Summary
With the OpenCode plugin, observations can be captured successfully while the corresponding session is never created in agentmemory. The result is:
/agentmemory/observerequests succeed- observations appear in server logs
memory_sessionsdoes not show the new session- later summarize calls fail with
Session not found for summarize
This showed up after fixing an unrelated infrastructure problem where agentmemory mcp had silently fallen back to local InMemoryKV because /agentmemory/livez was not reachable. Once the real server was running, the remaining bug was in the plugin/session-start path.
Environment
- OpenCode
1.15.10 - agentmemory
0.9.21 - WSL2 / Linux
- plugin:
plugin/opencode/agentmemory-capture.ts
Observed behavior
The server receives plugin events for the new OpenCode session, for example:
prompt_submitpost_tool_useassistant_messagesession_statussession_diffsession_updatedpatch_applied
But the session itself is missing from /agentmemory/sessions / memory_sessions.
Server log excerpt:
[agentmemory] info Observation captured {"obsId":"...","sessionId":"ses_...","hook":"prompt_submit","compress":"synthetic"}
[agentmemory] info Observation captured {"obsId":"...","sessionId":"ses_...","hook":"post_tool_use","compress":"synthetic"}
[agentmemory] warn Session not found for summarize {"sessionId":"ses_..."}
So the server is clearly receiving events for a session ID that was never registered via /agentmemory/session/start.
Expected behavior
Once the first event for a session arrives, that session should exist in agentmemory and be visible via memory_sessions.
Why this seems to happen
The plugin currently depends on session.created to call /agentmemory/session/start.
However, in practice it is possible for later hooks to arrive and be processed even though the session-start path did not successfully establish the session record.
That leaves the system in a half-working state:
- observations continue to be captured
- the session table remains empty for that session
- summarize/end flows later fail because the session was never created
Repro outline
- Start a real
agentmemoryserver so MCP is not using fallback mode. - Configure OpenCode with:
- MCP:
agentmemory mcp - plugin:
plugin/opencode/agentmemory-capture.ts
- MCP:
- Start a fresh OpenCode session.
- Send a few prompts / run a few tools.
- Check
memory_sessions.
Observed:
- new session not listed
- but server logs show observations for a new
ses_...session ID
Suggested fix
Make the plugin resilient to missing/late session.created handling by lazily bootstrapping the session on first event.
In other words:
- before
observe(...), ensure the session exists - if it does not, call
/agentmemory/session/startusing the currentsessionId - then proceed with
/observe
This makes the plugin robust even if session.created is missed, delayed, or shaped differently than expected.
A smaller but also useful improvement: make post() treat non-2xx responses as failures. Right now it can silently ignore HTTP errors because it only catches fetch exceptions.
Additional note
This is distinct from the agentmemory mcp fallback behavior. We also confirmed separately that if /agentmemory/livez is unavailable, the MCP bridge silently falls back to local InMemoryKV, which can mask server/plugin issues during debugging.
I would accept a pr on this.
actually in archive.md it was marked as subpar. @Axorax do you know why this was? from surface level it seems fine.
actually in
archive.mdit was marked as subpar. @Axorax do you know why this was? from surface level it seems fine.
Because the site was mainly in Russian. I think it just got added there with Yandex. We can reconsider adding it.
oh shoot your right my browser was autotranslating. i'm sure there are better ones
Better alternatives available. Seems to be mainly Russian.