Skip to content

Aborted assistant turn persisted with zero content bricks the session: empty assistant message replayed to provider (400 "must not be empty") #37946

Description

@Oloompa

Description

A turn was aborted mid-stream (the TUI had frozen after an OS suspend/resume, so I aborted). OpenCode persisted the aborted assistant message with error: MessageAbortedError and only step-start / reasoning / patch parts — no text, no tool call.

From then on, every subsequent prompt replays this message in the history as an assistant message with empty content. Moonshot (via OpenRouter) rejects the whole request:

[Moonshot AI] Invalid request: the message at position 29 with role 'assistant' must not be empty (400)

It snowballs: each failed retry persists another empty assistant message with error: APIError, so the failing position advances (29 → 30 → …) and the session is permanently unusable. I had to manually delete the artifact messages from opencode.db to recover the session.

Expected behavior: an aborted/errored assistant turn with no serializable content should either not be persisted, or be filtered out when building the model messages (the assistant-side equivalent of the guard requested in #31046 for empty text parts).

Steps to reproduce

  1. Session with a strict provider (openrouter / moonshotai/kimi-k3)
  2. Abort a turn while the model is still in reasoning, before any text or tool part is emitted
  3. Send any new message → 400 "must not be empty"; each retry fails the same way and appends a new empty artifact message

Environment

  • OpenCode version: 1.18.3
  • OS: Linux
  • Plugins: oh-my-opencode

Related

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