Skip to content

fix(execution): opencode serve protocol — object-shaped model post + settled terminal stream - #85

Merged
pacphi merged 2 commits into
pacphi:mainfrom
robertelee78:fix/opencode-adapter-protocol
Jul 29, 2026
Merged

fix(execution): opencode serve protocol — object-shaped model post + settled terminal stream#85
pacphi merged 2 commits into
pacphi:mainfrom
robertelee78:fix/opencode-adapter-protocol

Conversation

@robertelee78

Copy link
Copy Markdown
Contributor

Summary

Two bugs in the opencode execution adapter, found by the #76 three-host live smoke where the opencode leg could not be exercised:

  1. Every configured-model worker 400'd. The adapter posted model as a bare string to POST /session/:id/prompt_async, but opencode serve's schema expects {providerID, modelID} or null:

    {"name":"BadRequest","data":{"message":"Expected object | null, got \"opencode/kimi-k3\"\n  at [\"model\"]","kind":"Payload"}}
    

    provider/model strings are now split on the first slash into the schema object (model ids may contain slashes); a model with no provider prefix is omitted so the server's own configured default applies.

  2. The CLI crashed after printing the failure verdict. When the prompt post threw, launch() stopped the owned server but left the terminal SSE promise unconsumed; its socket-close rejection surfaced as an unhandled rejection (TypeError: terminated, UND_ERR_SOCKET) and killed the process after the run verdict. A no-op second consumer is attached at creation — observe() still sees genuine terminal rejections; the owned server still gets SIGTERM.

Verification

  • Regression tests: serve-shaped model posts (incl. slash-containing model ids like openrouter/z-ai/glm-5.2, and the bare-id omission), and a 400-prompt teardown asserting no unhandled rejection while the owned server still receives SIGTERM.
  • pnpm run check exit 0 (1049 kit + 222 cjs tests), pnpm run test:surface exit 0 (25).
  • Live proof: with this fix, the opencode leg of the feat: generalize host routing and add OpenCode as a routable execution host #76 smoke completes — ak run feature with all four workers routed to opencode (kimi-k3) succeeded end-to-end, produced the sandboxed repository mutation (hello.mjs + tests/), and emitted normalized terminal evidence (observed model kimi-k3, provider opencode, per-worker durations). Smoke detail posted on feat: generalize host routing and add OpenCode as a routable execution host #76.

Refs #76

…settled terminal stream

Found by the pacphi#76 three-host live smoke, where every opencode worker failed
and the CLI then crashed:

1. prompt_async 400s: the adapter posted the configured model as a bare
   string, but opencode serve's schema expects {providerID, modelID} or
   null ("Expected object | null, got \"opencode/kimi-k3\" at
   [\"model\"]" — verified against serve 1.18.8). provider/model strings
   are now split on the first slash into the schema object (model ids may
   contain slashes); a model with no provider prefix is omitted so the
   server's own configured default applies — never a guessed provider.

2. Process crash after the failure verdict: when the prompt post threw,
   launch() stopped the owned server but left the terminal SSE promise
   unconsumed; its socket-close rejection surfaced as an unhandled
   rejection (TypeError: terminated, UND_ERR_SOCKET) that killed node
   AFTER the run verdict had printed. A no-op second consumer is attached
   at creation — observe() still sees genuine terminal rejections.

Regression tests: serve-shaped model posts (incl. slash-containing model
ids and the bare-id omission), and a 400-prompt teardown asserting no
unhandled rejection while the owned server still receives SIGTERM.

Verified end-to-end: with this fix, the opencode leg of the pacphi#76 smoke
completes — ak run feature with all four workers routed to opencode
(kimi-k3) succeeded, produced the sandboxed repo mutation, and emitted
normalized terminal evidence (observed model, provider, durations).
…tract comment

The adapter has been the ak run path for opencode workers since pacphi#82/pacphi#84;
the comment was false in a security-sensitive adapter (swarm architecture
finding).
@pacphi
pacphi merged commit c4fba73 into pacphi:main Jul 29, 2026
11 checks passed
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.

2 participants