Skip to content

db: 2.3.0 migrations fail on V1→V2 databases ("table blob already exists") #63913

Open

Description

@panchocespedes2016

Description

After upgrading to 2.3.0 on a Raspberry Pi (Debian 13 / arm64), OpenCode Desktop exits immediately after app starting, and the bundled CLI background service (opencode serve --service) cannot boot. Both failures are caused by the same conflict: two 2.3.0 migrations create a blob table unconditionally, but the database (created by the V1→V2 migration in August) already contains a legacy blob table.

1. CLI migration 20261025123711_blob

database migration started  migration=20261025123711_blob
database migration failed   migration=20261025123711_blob durationMs=2
  error="... CREATE TABLE `blob` ( `hash` text PRIMARY KEY, `mime` text NOT NULL, ... )
          (cause: SQLiteError: table `blob` already exists)"
background service boot failed
GET /api/info 500

The legacy table is blob(id TEXT PRIMARY KEY, data BLOB NOT NULL) with 0 rows, and it is part of the V1→V2 baseline schema (it is not recorded in the migration table, whose 51 rows only go up to 20261010180456_project_time_archived). The new migration assumes the table does not exist and does a bare CREATE TABLE.

2. Desktop drafts migrations applied to the shared CLI database

The desktop app applies its own drafts migrations to ~/.config/ai.opencode.desktop/drafts.sqlite. On this machine that path is a symlink to the shared CLI database (~/.local/share/opencode/opencode.db), created by the V1→V2 data migration on 2026-08-22:

~/.config/ai.opencode.desktop/drafts.sqlite -> ~/.local/share/opencode/opencode.db
~/.local/state/opencode/opencode.db         -> ~/.local/share/opencode/opencode.db

Migration 20260906234153_drafts does CREATE TABLE \blob` (id, data)andCREATE TABLE `document` (key, value)`, and both tables already exist in the CLI database. The whole transaction fails and the app quits before showing a window:

[03:44:10] (main) app starting { version: '2.3.0', ... }
[03:45:54.351] ERROR (#3): Error: table `blob` already exists
    at file:///opt/OpenCode/resources/app.asar/out/main/index.js:1:5784
    at Array.forEach (<anonymous>)
    at De (file:///opt/OpenCode/resources/app.asar/out/main/index.js:1:5732)

Every subsequent launch fails identically, and because the failed serve --service process stays alive and keeps answering /api/info with 500, the desktop only shows "Background service failed to start" until the service process is killed and the stale service.json removed.

OpenCode version

2.3.0 — Desktop ai.opencode.desktop 2.3.0 (/opt/OpenCode, bundled opencode-cli 2.3.0) and CLI opencode 2.3.0. Before the upgrade the CLI on this machine was 2.1.4, which worked with the same database.

Plugins

None configured. ~/.config/opencode/opencode.jsonc only defines a model and a local @ai-sdk/openai-compatible provider.

Steps to reproduce

  1. Start from a database created by the V1→V2 migration (in this case 2026-08-22) where the baseline schema already contains the legacy tables blob(id TEXT PRIMARY KEY, data BLOB NOT NULL) and document(key TEXT PRIMARY KEY, value TEXT NOT NULL), and where the migration table has no 20260906234153_drafts row.
  2. Keep the V1→V2 symlink ~/.config/ai.opencode.desktop/drafts.sqlite -> ~/.local/share/opencode/opencode.db.
  3. Upgrade CLI and/or Desktop to 2.3.0 and launch Desktop.
  4. Desktop writes app starting and quits with Error: table \blob` already exists`.
  5. If the drafts symlink is removed (opencode service restart afterwards), the service then fails on migration 20261025123711_blob with the same error and /api/info returns 500.

Operating System

Debian GNU/Linux 13 (trixie), Linux 6.18.50+rpt-rpi-v8 aarch64 (Raspberry Pi 5), Raspberry Pi OS labwc/Wayland session, accessed over wayvnc.

Terminal

Not applicable (Desktop app). Diagnostics were run over SSH with bash.

Additional Context

Schema state before the fix

  • blob = CREATE TABLE blob (id TEXT PRIMARY KEY, data BLOB NOT NULL) — 0 rows
  • document = CREATE TABLE document (key TEXT PRIMARY KEY, value TEXT NOT NULL) — 3 rows
  • state, plugin, extension, blob_ref missing
  • migration table: 51 rows, latest 20261010180456_project_time_archived
  • kv contains migration.v1-v2 = {"phase":"completed"}

Workaround that restored the app

  1. Backed up the database (sqlite3/backup() copy).
  2. Replaced the drafts.sqlite symlink with a real, empty file so the desktop drafts migrations get their own database.
  3. Renamed the legacy, empty table: ALTER TABLE \blob` RENAME TO `blob_v1_legacy``.
  4. Killed the stuck opencode-cli serve --service process and removed ~/.local/state/opencode/service.json.

After that, migrations completed through 20261030054400_job, blob_ref and the new blob(hash, mime, bytes, width, height, data, time_created) were created, /api/info returned 200, and the desktop window opened with all projects and sessions intact.

Suggested fixes

  • Make the desktop drafts store independent of the shared CLI database (do not follow the V1→V2 symlink), or make its migrations IF NOT EXISTS/schema-aware.
  • Make 20261025123711_blob tolerate a pre-existing legacy blob table (rename/recreate, or record the V1→V2 baseline in migration so baseline tables are not recreated).
  • Do not leave a failed serve --service process serving 500 on /api/info, which turns a migration error into a permanently broken Desktop until the process and service.json are removed manually.

Activity

  1. added
    area/sessions-storage
    type/bug
    version/v2
    on Nov 14, 2026
  2. opencodejr commented on Nov 14, 2026

    @opencodejr
    Contributor

    Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.

    Thanks for the detailed report. I reproduced the CLI half on 2.3.0, and it still happens on the latest dev (cbe7159).

    What I did (the script below):

    1. Created a database with the real 2.1.4 CLI (opencode serve). Its last migration was 20261010180456_project_time_archived, as on your machine.
    2. Added by hand the old blob(id TEXT PRIMARY KEY, data BLOB NOT NULL) and document(key, value) tables you describe. This setup step is simulated: I don't have a real V1→V2 database.
    3. Started opencode serve from 2.3.0 on that data. Migration 20261025123711_blob failed with SQLiteError: table \blob` already existsand the server did not start. Running fromdev` source gives the same failure.

    Not checked:

    • The Desktop side (the desktop app can't run here).
    • The leftover service process that keeps answering 500. In my run, serve exited instead.
    • Where the drafts.sqlite symlink comes from: I didn't find code that creates it.

    The old blob/document tables match the desktop drafts schema exactly, which fits your symlink explanation. I've passed the details to the maintainers.

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Reproduces #63913 (CLI half): 2.3.0 migration 20261025123711_blob fails when the
    # database already has a `blob(id, data)` table (as left by the V1->V2/desktop drafts schema).
    set -u
    OLD=${OLD:-2.1.4}; NEW=${NEW:-2.3.0}
    inst() { d=/tmp/opencode/oc-$1; [ -x $d/node_modules/.bin/opencode ] || (mkdir -p $d && cd $d && bun add --trust @opencode/cli@$1 >/dev/null 2>&1); echo $d/node_modules/.bin/opencode; }
    OLDBIN=$(inst $OLD); NEWBIN=$(inst $NEW)
    export HOME=$(mktemp -d /tmp/opencode/h63913.XXXX)
    export XDG_DATA_HOME=$HOME/.local/share XDG_CONFIG_HOME=$HOME/.config XDG_STATE_HOME=$HOME/.local/state XDG_CACHE_HOME=$HOME/.cache
    mkdir -p $HOME/proj && cd $HOME/proj
    run_serve() { # $1 = command
      ( $1 serve --port 47913 --print-logs > $HOME/serve.log 2>&1 & echo $! > $HOME/pid )
      sleep 12
      echo "GET /api/info -> $(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:47913/api/info)"
      kill $(cat $HOME/pid) 2>/dev/null; sleep 1
    }
    echo "== 1. create DB with $OLD"
    $OLDBIN --version
    run_serve $OLDBIN
    DB=$(find $HOME -name opencode.db | head -1); echo "db: $DB"
    echo "== 2. add the legacy table from the report: blob(id TEXT PRIMARY KEY, data BLOB NOT NULL)"
    bun -e "const {Database}=require('bun:sqlite');const d=new Database('$DB');d.run('CREATE TABLE IF NOT EXISTS blob (id TEXT PRIMARY KEY, data BLOB NOT NULL)');d.run('CREATE TABLE IF NOT EXISTS document (key TEXT PRIMARY KEY, value TEXT NOT NULL)');console.log(d.query('select id from migration order by id desc limit 1').get())"
    export OPENCODE_DB=$DB
    echo "== 3. start ${OC_CMD:-$NEW}"
    if [ -n "${OC_CMD:-}" ]; then CMD="$OC_CMD"; else $NEWBIN --version; CMD=$NEWBIN; fi
    run_serve "$CMD"
    grep -iE "migration (started|failed)|already exists|boot failed" $HOME/serve.log | head -10

    Run it: bash repro.sh

  3. added
    status/repro-simulated
    on Nov 14, 2026
  4. ccclucky commented on Nov 14, 2026

    @ccclucky

    Taking this one.

    Confirmed on dev (cbe7159): migration 20261025123711_blob does a bare CREATE TABLE blob (...) (packages/core/src/database/migration/20261025123711_blob.ts), but databases that went through the V1→V2 data migration in August already carry the baseline blob(id, data) table, so the migration dies with table blob already exists and the background service never boots.

    A real blob(hash, ...) table cannot exist on those databases (the migration would have created it itself, and it never completed there), so the migration can detect the legacy shape and set it aside:

    1. Before creating, read PRAGMA table_info(blob): if the table exists and has no hash column — the legacy baseline shape — rename it to blob_v1_legacy instead of failing. Any rows survive, and the rename is transactional with the rest of the migration (each migration already runs in one transaction). Same guard pattern as the existing session-metadata migration.
    2. Regression test in packages/core/test/database-migration.test.ts: a database holding the legacy blob table (with a row) applies the migration successfully, ends up with the new blob(hash, ...) schema, and keeps the renamed legacy table intact.

    I'll leave the desktop drafts half to maintainers — decoupling drafts.sqlite from the shared CLI database (or making the drafts store schema-aware) is a product decision I don't want to make unilaterally. The stuck serve --service process answering 500 after a failed boot also looks like a separate error-handling issue, so I'm not folding it in here.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/sessions-storageplatform/linuxstatus/repro-simulatedtype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions