Summary
opencode-mem auto-capture can fail with:
opencode-mem: session.create returned no session id; cannot generate structured output
when OpenCode is started without an explicit --port.
Root cause observed
In a no-port OpenCode session, the plugin received:
ctx.serverUrl = http://localhost:4096/
but no OpenCode REST API was listening there. The structured-output path creates a fresh SDK client from ctx.serverUrl and calls client.session.create(), so the request fails before a session id is returned.
A local diagnostic patch showed the underlying SDK result was an error result, not a successful session response:
{
"topKeys": ["error", "request", "response"],
"hasDataId": false,
"hasError": true,
"requestPath": "/session",
"errorMessage": "Unable to connect. Is the computer able to access the url?"
}
The current user-facing error hides this underlying connection failure because generateStructuredOutput() only checks created?.data?.id.
Control case
When starting OpenCode with an explicit port, for example --port 61234, the plugin received:
ctx.serverUrl = http://127.0.0.1:61234/
and session.create succeeded with created.data.id present.
Expected behavior
Auto-capture should not depend on an unreachable default ctx.serverUrl when OpenCode already injects a working ctx.client. The structured-output path should reuse the injected client or otherwise surface the real connection error.
Environment
- OpenCode: 1.17.11
- opencode-mem: 2.17.4
- Node: 22.22.1
- OS: Linux
Proposed fix
Reuse the injected ctx.client through a small adapter for session.create, session.prompt, and session.delete, instead of creating a second SDK client from ctx.serverUrl. Also include the underlying SDK error details when session.create returns no id.
I have a PR ready with a regression test.
Summary
opencode-memauto-capture can fail with:when OpenCode is started without an explicit
--port.Root cause observed
In a no-port OpenCode session, the plugin received:
but no OpenCode REST API was listening there. The structured-output path creates a fresh SDK client from
ctx.serverUrland callsclient.session.create(), so the request fails before a session id is returned.A local diagnostic patch showed the underlying SDK result was an error result, not a successful session response:
{ "topKeys": ["error", "request", "response"], "hasDataId": false, "hasError": true, "requestPath": "/session", "errorMessage": "Unable to connect. Is the computer able to access the url?" }The current user-facing error hides this underlying connection failure because
generateStructuredOutput()only checkscreated?.data?.id.Control case
When starting OpenCode with an explicit port, for example
--port 61234, the plugin received:and
session.createsucceeded withcreated.data.idpresent.Expected behavior
Auto-capture should not depend on an unreachable default
ctx.serverUrlwhen OpenCode already injects a workingctx.client. The structured-output path should reuse the injected client or otherwise surface the real connection error.Environment
Proposed fix
Reuse the injected
ctx.clientthrough a small adapter forsession.create,session.prompt, andsession.delete, instead of creating a second SDK client fromctx.serverUrl. Also include the underlying SDK error details whensession.createreturns no id.I have a PR ready with a regression test.