plannotator icon indicating copy to clipboard operation
plannotator copied to clipboard

Ask AI (OpenCode 2): "Timeout waiting for server to start" — AI provider uses the v1-era @opencode-ai/sdk, incompatible with OpenCode ≥ 2.0

Open MartinNeudecker opened this issue 1 month ago • 3 comments

Summary

On plannotator 0.28.19 with OpenCode v2.0.29, clicking Ask AI fails every time with Timeout waiting for server to start after 5000ms. The spawned server is healthy — the readiness detection is what fails.

Root cause

Ask AI's OpenCode provider is built on @opencode-ai/[email protected] — the v1-era SDK. Its createOpencodeServer() spawns opencode serve and resolves only when a stdout line starts with opencode server listening. OpenCode ≥ 2.0 prints server listening on http://… (prefix dropped), so the promise never resolves and the 5s timeout kills the working server (~1s startup, verified locally).

For OpenCode 2 the correct packages are @opencode/sdk / @opencode/client (v2.0.29), which avoid stdout parsing entirely — the SDK hosts the router in-process, and the client discovers an existing service via the XDG registration file.

Impact

As far as I can tell, this affects every OpenCode ≥ 2.0 user, deterministically, on every Ask AI use.

Suggested fixes

  1. Migrate the Ask AI provider to @opencode/sdk/@opencode/client v2 — this also makes reusing an already-running opencode service the default behavior via the registration-file discovery (the review flows already reuse the local server, #567 / #513).
  2. Stopgap if a full migration is heavy: patch the vendored provider's matcher to accept both log lines, or poll HTTP readiness. Note the legacy package line is at its end (1.19.0), so this buys time only.

Environment

plannotator 0.28.19, OpenCode 2.0.29, macOS.

Related issues

  • #1413 — Ask AI on OpenCode 2, but a post-start SSE failure ("Failed to fetch"), not this spawn-timeout
  • #567 / #513 — precedent for reusing an existing local server
  • #1194 — OpenCode 2 adapter context

MartinNeudecker avatar Oct 15 '26 16:10 MartinNeudecker

Update after #2449: with plannotator 0.28.67 and 0.29.0 against OpenCode 2.3.0 and 2.3.2, Ask AI with the OpenCode provider now gets past server startup (the readiness-line fix works), but fails later in createSession() with OpenCode did not return session data.

Verified locally by probing the spawned opencode serve directly:

  • POST /session (the v1-era route the bundled @opencode-ai/[email protected] still calls via client.session.create()) → 405. It is not an API route on OpenCode ≥ 2.0: GET on the same path returns the web SPA HTML, POST returns 405, and the server logs http.url=/session http.status=405.
  • POST /api/session (HTTP Basic auth, opencode:<password>) → 201, returns the session JSON.

So the readiness fix uncovered the second half of the incompatibility: the provider's requests never reach the v2 API, which lives under /api/. Notably, plannotator's own Inbox launch path already calls POST /api/session directly — Ask AI could do the same, or the vendored SDK patch could point session.create at the v2 path.

Workaround for anyone hitting this: pick a non-OpenCode provider in the Ask AI "To:" menu.

cvelezprecurly avatar Nov 18 '26 22:11 cvelezprecurly

Follow-up: we built a working local compatibility shim, which turned the "suggested fix" into a precise migration checklist. The v1→v2 incompatibilities are not just the route prefix — there are five layers:

  1. Route prefix + auth: v2 serves the API under /api/ and requires HTTP Basic auth (opencode:<password>), not Bearer.
  2. Bodyless POSTs: the v1 SDK sends POSTs with Content-Type: application/json but an empty body (session.create); v2 answers 400 InvalidRequestError: Expected object. Needs a {} body.
  3. Response envelope: v2 wraps successful JSON responses in {data: ...}; the v1 SDK's result.data must BE the object. Without unwrapping, session.create "succeeds" with id: undefined and the next call goes out as the literal path /session/{id}/prompt_async → 404 (this is what surfaces as "OpenCode did not return session data." in one variant and "OpenCode rejected prompt: HTTP 404" in another).
  4. prompt_async is gone: v2 replaced it with POST /session/{id}/prompt taking {text, system?, model?: {providerID, modelID}} instead of {parts: [...], model: "provider/id", system}.
  5. SSE event names changed: message.part.delta → session.text.delta ({sessionID, delta}), terminal session.status {status:{type:"idle"}} → session.execution.succeeded, plus session.text.ended, session.execution.failed, etc.

Our shim (an opencode PATH wrapper that spawns the real opencode serve, then reverse-proxies with the translations above) makes Ask AI on OpenCode 2.3.2 work end-to-end — streaming text included. Happy to share the ~200-line prototype if useful.

So the real fix in plannotator is a provider migration to the v2 SDK/client rather than a patched vendored SDK.

cvelezprecurly avatar Nov 18 '26 23:11 cvelezprecurly

Verified: the fix works end-to-end. On plannotator 0.29.4 against OpenCode 2.4.1, Ask AI with the OpenCode provider answers normally — streaming included — with no local workaround. Thanks @JasonOA888 for the clean transport detection (the /api/info gate saved us from caring about which CLI is installed). One small observation from the verification run: a permission reply POST got a 404 against 2.4.1 without breaking the answer — possibly API drift worth a look if permission flows matter for Ask AI.

cvelezprecurly avatar Nov 25 '26 18:11 cvelezprecurly