You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JSON→SQLite session migration silently skips for incremental upgrades #13654
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
Have an OpenCode installation that created opencode.db before commit 6d95f0d14 (any user who ran a version between late Jan and Feb 13)
Update to a version including 6d95f0d14
Start OpenCode — migration is skipped because DB already exists
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:
constmarker=path.join(Global.Path.data,"opencode.db")if(!(awaitBun.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
github-actions commentedon Feb 14, 2026
This issue might be related to other session storage issues. Please also check:
opencode serve#13611: Session JSON→SQLite migration running in non-interactive mode (opencode serve)These are distinct issues but may benefit from shared context around session persistence and migration logic.
github-actions commentedon Apr 16, 2026
To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.
feat(ai-backup): doc-backed manifest scope for AI-state backup
feat(ai-backup): doc-backed manifest scope for AI-state backup
feat(ai-backup): doc-backed manifest scope for AI-state backup