Skip to content

Session silently stops on empty LLM response (finish: unknown, 0 tokens) #41469

Description

@3351163616

Description

When the model provider returns an empty completion (0 tokens, no text/reasoning/tool output, finish reason maps to unknown), opencode treats it as a normal completed turn:

  • the session loop exits silently (packages/opencode/src/session/prompt.ts breaks on any finish that isn't tool-calls)
  • no error is surfaced to the user, no retry happens
  • the conversation appears to "suddenly stop" mid-task

Observed with the opencode-go gateway (deepseek-v4-flash) returning an empty response: the session went idle with the last assistant message recorded as finish: unknown with 0 tokens.

Repro

  • Provider returns an SSE stream with no content/tool deltas and an unknown finish reason.
  • After processing, the loop exits and the session goes idle with no error.

Expected

An empty response should be retried (or surfaced as an error), not silently treated as a completed turn.

Related: #40531 (upstream PR with the same fix, currently conflicting with dev).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions