Repository navigation
Description
Description
When Provider.getModel() throws a ModelNotFoundError during the main prompt loop, no session.error event is published to the bus. The session silently transitions to idle, leaving SSE consumers with no indication that an error occurred.
Reproduction
Configure a model with a provider that isn't loaded (e.g., "openai/gpt-5.2" without OPENAI_API_KEY), then send a prompt via prompt_async. The session goes idle with no assistant response and no error event.
Root cause
In packages/opencode/src/session/prompt.ts line 324, the loop() function calls Provider.getModel() without a try/catch:
// line 324
const model = await Provider.getModel(lastUser.model.providerID, lastUser.model.modelID)When this throws, the exception propagates out of the while(true) loop. The defer at line 278 calls cancel(sessionID), which sets the session status to "idle" at line 259 — but no session.error event is published.
Since prompt_async (packages/opencode/src/server/routes/session.ts line 765) doesn't await the prompt, the exception becomes an unhandled promise rejection:
// line 765
SessionPrompt.prompt({ ...body, sessionID }) // fire-and-forget, no awaitThe pattern already exists elsewhere in the same file
The command handler at lines 1710–1721 correctly catches ModelNotFoundError and publishes Session.Event.Error:
// lines 1710-1721
try {
await Provider.getModel(taskModel.providerID, taskModel.modelID)
} catch (e) {
if (Provider.ModelNotFoundError.isInstance(e)) {
const { providerID, modelID, suggestions } = e.data
const hint = suggestions?.length ? ` Did you mean: ${suggestions.join(", ")}?` : ""
Bus.publish(Session.Event.Error, {
sessionID: input.sessionID,
error: new NamedError.Unknown({ message: `Model not found: ${providerID}/${modelID}.${hint}` }).toObject(),
})
}
throw e
}Suggested fix
Wrap the Provider.getModel call at line 324 in a similar try/catch that publishes Session.Event.Error before re-throwing:
let model: Awaited<ReturnType<typeof Provider.getModel>>
try {
model = await Provider.getModel(lastUser.model.providerID, lastUser.model.modelID)
} catch (e) {
if (Provider.ModelNotFoundError.isInstance(e)) {
const { providerID, modelID, suggestions } = e.data
const hint = suggestions?.length ? ` Did you mean: ${suggestions.join(", ")}?` : ""
Bus.publish(Session.Event.Error, {
sessionID,
error: new NamedError.Unknown({ message: `Model not found: ${providerID}/${modelID}.${hint}` }).toObject(),
})
}
throw e
}Impact
- Headless/API consumers relying on SSE events see
session.idlewith no error, making failures indistinguishable from success - The TUI is unaffected since it catches the unhandled rejection separately
- Only
prompt_asynccallers are impacted (the synchronouspromptendpoint awaits the result)
Activity
github-actions commentedon Feb 8, 2026
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if none of these address your specific case.
ColeMurray commentedon Feb 8, 2026
confirming dupe of: #8460