Skip to content

Cancelling agent mid-response bricks session with "content field is empty" error #16220

Closed

Description

@ddemarteleire

Description

When an agent is cancelled while generating a response, OpenCode persists the assistant message with an empty text content block ("text": ""). On the next message in that session, this empty block is replayed to the model API which rejects it, permanently bricking the session.

Root cause (from manual DB inspection): The part table contains a row with {"type":"text","text":"","time":{"start":...}} belonging to a MessageAbortedError assistant message. This empty text block is sent as-is to the model API when the session history is replayed.

Workaround: Manually update the SQLite database at ~/.local/share/opencode/opencode.db:

-- Find the broken part
SELECT p.id, p.data
FROM part p
JOIN message m ON m.id = p.message_id
WHERE m.session_id = '<your-session-id>'
  AND json_extract(p.data, '$.type') = 'text'
  AND json_extract(p.data, '$.text') = '';

-- Fix it
UPDATE part SET data = json_set(data, '$.text', '[aborted]')
WHERE id = '<part-id>';

Plugins

No response

OpenCode version

1.2.16

Steps to reproduce

Start a session and prompt the agent with a task that involves tool use / a todo list

  1. While the agent is actively generating a response, cancel it
  2. Send any new message in the same session
  3. Expected behavior: OpenCode should either:

Strip or not persist empty content blocks from aborted messages, or

  • Filter out empty content blocks when replaying session history to the model API
  • Actual behavior: Every subsequent message in the session fails immediately with:

The content field in the Message object at messages.N is empty.

  • Add a ContentBlock object to the content field and try again.
  • The session becomes permanently unrecoverable from the UI. There is no way to unarchive or repair the session through the UI or CLI (opencode export also fails for archived sessions).

Environment:

  • Platform: macOS
  • Provider: Amazon Bedrock (us.anthropic.claude-sonnet-4-6)

Screenshot and/or share link

No response

Operating System

macOS

Terminal

Desktop

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 5, 2026
  2. github-actions commented on Mar 5, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of an existing issue. Please check:

  3. ddemarteleire commented on Mar 6, 2026

    @ddemarteleire
    Author

    Duplicate of #15371

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions