Skip to content

fix(auto-capture): reuse injected opencode client#146

Closed
huilang021x wants to merge 1 commit into
tickernelz:mainfrom
huilang021x:fix-use-plugin-client-for-autocapture
Closed

fix(auto-capture): reuse injected opencode client#146
huilang021x wants to merge 1 commit into
tickernelz:mainfrom
huilang021x:fix-use-plugin-client-for-autocapture

Conversation

@huilang021x

Copy link
Copy Markdown
Contributor

Summary

  • What changed: Auto-capture now builds its structured-output session client from the injected OpenCode ctx.client instead of creating a second client from ctx.serverUrl. session.create failures now include underlying status/error details when available.
  • Why: In no-port OpenCode sessions, ctx.serverUrl can be http://localhost:4096/ even when no REST API is listening there, causing session.create returned no session id during auto-capture.
  • Current phase: Ready for review. Closes Auto-capture uses unreachable ctx.serverUrl in no-port OpenCode sessions #145.

Scope

  • In scope: Structured-output auto-capture client initialization and regression coverage for the injected-client adapter.
  • Out of scope: Provider/model timeout tuning, storage/indexing behavior, web UI behavior.
  • Risk level: Low/medium; changes the internal client used for auto-capture session create/prompt/delete while preserving the existing request shapes.

Deployment Targets

  • Impacted services: opencode-mem plugin auto-capture and user-profile structured-output paths that use the shared opencode provider client.
  • Restart/deploy needed: Users need to restart OpenCode after upgrading the plugin.
  • Target environment: OpenCode plugin runtime.
  • Rollback note: Revert this commit to restore the previous ctx.serverUrl client path.

Acceptance Plan

  • Acceptance criteria: Auto-capture should not fail with no session id solely because ctx.serverUrl points to an unreachable default port; structured-output calls should use the injected client and still pass format, system, model, and parts correctly.
  • Evidence to collect: Regression test verifies createStructuredOutputClient() maps v2-style calls onto the injected client without opening a new serverUrl client.
  • Required checks: Typecheck, build, formatter check, targeted provider tests, full test suite.
  • Manual verification needed: Optional validation in a no-port OpenCode runtime after publishing.

Validation

  • Commands run:
    • bun test tests/opencode-provider.test.ts
    • bun run format:check
    • bun run typecheck
    • bun run build
    • bun test
  • Result: All passed after formatting.
  • Evidence links/log snippets:
    • Targeted test: 12 pass, 0 fail
    • Full test suite: 157 pass, 0 fail

@tickernelz

Copy link
Copy Markdown
Owner

I tried to merge this PR into the latest main as part of a batch release, but it currently has merge conflicts in:

  • src/services/ai/opencode-provider.ts

Several structured-output / opencode-provider changes landed in the latest release, which is what this now collides with. Please rebase/merge the latest main and resolve the conflicts, and I'll merge it afterward.

@prihuda

prihuda commented Jul 8, 2026

Copy link
Copy Markdown

i need this because on 2.18.0 the problem still persist

@GraDea

GraDea commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

The goal is right: structured auto-capture should reuse OpenCode’s running host context instead of depending on a separately reachable localhost server.

I’m going to hold/close this in favor of #161, because this PR routes back through ctx.client.session.create/prompt/delete, while #140 intentionally moved away from those SDK/session helper methods due SDK shape brittleness.

The replacement approach keeps #140’s raw endpoint direction, but uses the host SDK transport (fetch/baseUrl) underneath it. It also covers the follow-up issues we found in runtime testing:

  • injected host fetch needs Request object calls
  • noReply: true suppresses structured output in current OpenCode builds
  • info.structured_output must be supported
  • diagnostics need redaction
  • stale host transport state must be reset between plugin initializations

Closing as superseded by #161, not rejected.

@GraDea GraDea closed this Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants