anomalyco / anomalyco/opencode

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

Open
#37,946 5 comments 2 reactions 1 assignee View on GitHub

@jlongster is already working on this.

Since Jul 20, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

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

  • #37887 (same symptom with Kimi K3, auto-closed for template non-compliance)
  • #31046 (empty text parts — different root cause)
  • #28507 (empty assistant message loop after tool call)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.