anomalyco / anomalyco/opencode

SQLite NOT NULL constraint failed: session_message.seq crash on first prompt after /model switch — silently breaks all further input

Open
#39,165 4 comments 1 reaction 1 assignee View on GitHub

@kitlangton is already working on this.

Since Jul 27, 2026.

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

Description

Description
Description

Switching the active model mid-session via /model corrupts the session's message-sequencing state. The very next message sent afterward fails server-side with a SQLite NOT NULL constraint violation on session_message.seq, and the request handler throws before responding. The TUI shows no error, no output, and no response at all — the session appears completely dead, for both slash commands and regular chat messages.

Environment
  • opencode version: 1.18.7 / 2.7 (reproduced on both)
  • Installed via: Homebrew (anomalyco/tap/opencode)
  • OS: macOS 26.5.2 (Darwin 25.5.0, arm64 / Apple Silicon)
Steps to Reproduce
  1. Start a new session and send a message.
  2. Wait for the response to complete normally.
  3. Run /model and switch to a different model.
  4. Send any message or slash command.

This is a clean, deterministic repro — it does not require hitting a rate limit or any request being in-flight/cancelled.

Actual Behavior

The server throws and the client receives nothing:

ERROR service=server ref=err_d74f3a01 error=NOT NULL constraint failed: session_message.seq cause=SQLiteError: NOT NULL constraint failed: session_message.seq
    at run (unknown)
    at #run (bun:sqlite:185:20)
    at appendMessage (/$bunfs/root/chunk-ppexnrrz.js:2:62553)
    at session.next.model.switched (/$bunfs/root/chunk-ppexnrrz.js:2:56852)
    at pP (/$bunfs/root/chunk-ppexnrrz.js:2:56619)
    at Fn (/$bunfs/root/chunk-ppexnrrz.js:2:62595)
    at SessionPrompt.createUserMessage (/$bunfs/root/chunk-gdpmt2mk.js:1687:365)
    at SessionPrompt.prompt (/$bunfs/root/chunk-ppexnrrz.js:2:240249)
    at SessionHttpApi.prompt (/$bunfs/root/chunk-ppexnrrz.js:2:92058)
    failed

The session.next.model.switched frame indicates the model-switch handler leaves the session's message-sequence counter (session_message.seq) unset/null. The next appendMessage call (creating the new user message) then violates the DB's NOT NULL schema constraint, and the whole prompt request fails silently before any LLM call or TUI feedback occurs.

Expected Behavior

Switching models should not corrupt session message sequencing. The next message should be appended and processed normally (or, at minimum, any resulting error should be surfaced in the TUI instead of being silently dropped).

Suggested area to investigate

appendMessage and the session.next.model.switched handler — likely missing re-fetch or increment of the last seq value for session_message when constructing the next message row immediately after a model change.

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

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.