Skip to content

Auto-capture uses unreachable ctx.serverUrl in no-port OpenCode sessions #145

Description

@huilang021x

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions