Skip to content

BUG: session_message.seq NOT NULL constraint failed on agent-switched sessions #31204

@High-cla

Description

@High-cla

Description

SQLiteError: NOT NULL constraint failed: session_message.seq

After the latest OpenCode update (migrations from June 3-5 adding session_message projection table), any session that triggers an agent switch crashes with this error. The �ppendMessage() function's code path for session.next.agent.switched does not provide a seq value when inserting into the session_message table, but the column is defined as INTEGER NOT NULL with no default value.

Error stack trace:
SQLiteError: NOT NULL constraint failed: session_message.seq at run (unknown) at #run (bun:sqlite:185:20) at appendMessage (B:/~BUN/root/chunk-j582v44c.js:2:62480) at session.next.agent.switched (B:/~BUN/root/chunk-j582v44c.js:2:56601) at SessionPrompt.createUserMessage (B:/~BUN/root/chunk-rsc45ft5.js:1677:366)

Root cause:
The session_message table schema has seq integer NOT NULL with NO DEFAULT. When �ppendMessage() is called during session.next.agent.switched, it inserts into session_message without providing the seq field.

Relevant migrations:

  • 20260603001617_session_message_projection_indexes
  • 20260603040000_session_message_projection_order
  • 20260603160727_jittery_ezekiel_stane

Evidence:

  • session_message table has 0 rows (every insert fails)
  • Old message table has 680+ rows (old system still works)
  • Error only triggers on session.next.agent.switched path
  • seq column has NOT NULL but NO DEFAULT

Workaround:
sql ALTER TABLE session_message RENAME TO session_message_old; CREATE TABLE session_message ( id text PRIMARY KEY, session_id text NOT NULL, type text NOT NULL, time_created integer NOT NULL, time_updated integer NOT NULL, data text NOT NULL, seq integer NOT NULL DEFAULT 0, CONSTRAINT fk_session_message_session_id_session_id_fk FOREIGN KEY (session_id) REFERENCES session(id) ON DELETE CASCADE ); INSERT INTO session_message SELECT * FROM session_message_old; DROP TABLE session_message_old;

Plugins

oh-my-openagent, opencode-agent-skills, aegis

OpenCode version

Recent build (auto-updated ~June 6, 2026)

Steps to reproduce

  1. Run OpenCode with oh-my-openagent plugin (agent switching behavior)
  2. Trigger a workflow that causes session.next.agent.switched
  3. Observe the error: NOT NULL constraint failed: session_message.seq

Operating System

Windows 11

Terminal

Windows Terminal / PowerShell 7

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions