Skip to content

core: continuing a V1-created session fails with UNIQUE constraint on event seq #52395

Description

@edward-ong-tiliter

Summary

After upgrading from OpenCode 1.18.20 to 2.0.20, continuing a session that was created under V1 permanently fails: every event insert for that session hits UNIQUE constraint failed: event.aggregate_id, event.seq. The event_sequence row for the session is behind the actual max(seq) in the event table, so writes can never succeed and the session becomes write-dead (messages sent to it are not persisted).

Environment

  • opencode version: 2.0.20 (channel: latest)
  • OS: macOS Darwin 25.5.0, arm64
  • Terminal: tmux (TERM=tmux-256color, COLORTERM=truecolor)
  • Shell: /bin/zsh
  • Install/channel: latest
  • Active plugins: @tarquinen/opencode-dcp@latest

Reproduction

  1. Use opencode 1.18.20 (SQLite-based storage in ~/.local/share/opencode/opencode.db) and create a session.
  2. Upgrade to opencode 2.0.20 and reopen the same session.
  3. Send a message.
  4. Observe the error in ~/.local/share/opencode/log/opencode.log:
EffectDrizzleQueryError: Failed query: insert into "event" ("id", "aggregate_id", "seq", "type", "data") values (?, ?, ?, ?, ?)
cause: SQLiteError: UNIQUE constraint failed: event.aggregate_id, event.seq

Expected Behavior

V2 should resume the per-session event sequence for pre-existing (V1-created) sessions at max(seq) + 1, or re-sync event_sequence with the event table on startup, so V1 sessions can be continued.

Actual Behavior

V2 inserts events at sequence numbers that already exist for the aggregate, so every write fails. The session cannot accept new messages.

Observed for session ses_f1066f4c8ffeSqEdL7iA67Ujnf (created 2026-09-29 under 1.18.20, directory ~):

  • event_sequence row for that aggregate: seq = 558
  • event table for that aggregate: 624 rows, max(seq) = 678
  • Errors logged at 2026-09-30T00:16:36Z and 2026-09-30T00:21:58Z:
timestamp=2026-09-30T00:21:58.895Z level=ERROR message=failed error="EffectDrizzleQueryError: Failed query: insert into \"event\" ... (cause: SQLiteError: UNIQUE constraint failed: event.aggregate_id, event.seq)"

Additional Context

  • The 1.18.x V1 line already used the same SQLite DB, so this looks like V2 initializing/tracking the per-aggregate sequence independently of rows written by V1.
  • Workaround: do not continue V1-created sessions; start new ones.
  • Everything else works: the session list is intact (3,700+ sessions readable), only writes to affected sessions fail.

Activity

github-actions commented on Sep 30, 2026

@github-actions
Contributor

This issue doesn’t fully meet our contributing guidelines.

What needs to be fixed:

  • Please use the Bug Report template and put the report under its required Description field; the current content is under Summary instead.

Please edit this issue to address the above within 2 hours, or it will be automatically closed.


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

  • #51411: stale event sequence permanently rejects new events; closely matches the sequence-cursor mismatch described here.
  • #51316: sessions become permanently unusable after UNIQUE constraint failed: event.aggregate_id, event.seq.
  • #51798: session event writes fail on an event-sequence collision, reported around configuration reloads.

If you believe this was flagged incorrectly, please let a maintainer know.

github-actions commented on Oct 1, 2026

@github-actions
Contributor

This issue has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new issue that follows our issue templates.

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

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