API doesn't report invalid model errors via event stream #5792

Closed
opened 2026-02-16 17:56:51 -05:00 by yindo · 0 comments
Owner

Originally created by @surma on GitHub (Jan 14, 2026).

Originally assigned to: @thdxr on GitHub.

Description

API doesn't report invalid model errors via event stream

Bug

When sending a message via the API with an invalid provider/model ID, no error is surfaced to the client. The session silently goes from busy to idle with no indication that anything went wrong.

Reproduction

  1. Start opencode server
  2. Listen to events: curl http://localhost:4096/event
  3. Send a message with an invalid provider:
    curl -X POST http://localhost:4096/session/{sessionID}/message \
      -H "Content-Type: application/json" \
      -d '{"model": {"providerID": "invalid", "modelID": "some-model"}, "parts": [{"type": "text", "text": "hello"}]}'
    
  4. Observe: HTTP 200, session goes busy → idle, no session.error event

Expected

A session.error event should be published with a message like "Model not found: invalid/some-model. Did you mean: ...?"

Cause

Provider.getModel() is called inside loop() after the HTTP response has already started streaming. The error is thrown but never converted to a session.error event.

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Originally created by @surma on GitHub (Jan 14, 2026). Originally assigned to: @thdxr on GitHub. ### Description # API doesn't report invalid model errors via event stream ## Bug When sending a message via the API with an invalid provider/model ID, no error is surfaced to the client. The session silently goes from `busy` to `idle` with no indication that anything went wrong. ## Reproduction 1. Start opencode server 2. Listen to events: `curl http://localhost:4096/event` 3. Send a message with an invalid provider: ```bash curl -X POST http://localhost:4096/session/{sessionID}/message \ -H "Content-Type: application/json" \ -d '{"model": {"providerID": "invalid", "modelID": "some-model"}, "parts": [{"type": "text", "text": "hello"}]}' ``` 4. Observe: HTTP 200, session goes busy → idle, no `session.error` event ## Expected A `session.error` event should be published with a message like "Model not found: invalid/some-model. Did you mean: ...?" ## Cause `Provider.getModel()` is called inside `loop()` after the HTTP response has already started streaming. The error is thrown but never converted to a `session.error` event. ### Plugins _No response_ ### OpenCode version _No response_ ### Steps to reproduce _No response_ ### Screenshot and/or share link _No response_ ### Operating System _No response_ ### Terminal _No response_
yindo added the bug label 2026-02-16 17:56:51 -05:00
yindo closed this issue 2026-02-16 17:56:51 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#5792