Skip to content

JSON→SQLite session migration silently skips for incremental upgrades #13654

Closed

Description

@dylan-conlin

Bug

The one-time JSON→SQLite session migration gate (json-migration.ts) checks whether opencode.db exists to decide whether to run. But opencode.db can exist from earlier schema migrations (e.g., Jan 27) that predate the session migration commit (6d95f0d14, Feb 13).

For any user who updated incrementally (rather than fresh install), the migration is silently skipped and all pre-existing JSON session files are permanently orphaned — they exist on disk but are invisible to the current SQLite-based session code.

Reproduction

  1. Have an OpenCode installation that created opencode.db before commit 6d95f0d14 (any user who ran a version between late Jan and Feb 13)
  2. Update to a version including 6d95f0d14
  3. Start OpenCode — migration is skipped because DB already exists
  4. All JSON sessions under ~/.local/share/opencode/storage/session/ are now orphaned

Evidence

-- DB was created Jan 27, migration commit is Feb 13
sqlite3 ~/.local/share/opencode/opencode.db \
  "SELECT *, datetime(created_at/1000, 'unixepoch', 'localtime') FROM __drizzle_migrations ORDER BY created_at;"
-- → 2026-01-27 14:23 (first migration, DB created)
-- → 2026-02-13 06:41 (third migration, same release window as session migration)
# 188 JSON session files on disk, never imported
find ~/.local/share/opencode/storage/session -name "*.json" | wc -l
# → 188

Root Cause

packages/opencode/src/storage/index.ts:82-83:

const marker = path.join(Global.Path.data, "opencode.db")
if (!(await Bun.file(marker).exists())) { /* run json migration */ }

The gate assumes "DB exists = sessions already migrated." But the DB can exist from earlier schema migrations that had nothing to do with session storage.

Suggested Fix

Replace the opencode.db existence check with a dedicated migration marker (e.g., a flag in a migrations table, or a .json-migration-complete marker file). This allows the JSON import to run even when the DB already exists from prior schemas.

Activity

  1. github-actions commented on Feb 14, 2026

    @github-actions
    Contributor

    This issue might be related to other session storage issues. Please also check:

    These are distinct issues but may benefit from shared context around session persistence and migration logic.

  2. github-actions commented on Apr 16, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

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