Description
OpenCode SQLite migration misses legacy JSON sessions after path normalization
Summary
After upgrading OpenCode from an older file-storage based version to 1.17.16, the SQLite migration only imported a small subset of existing sessions. The original JSON session and message files remain intact, but most sessions are not visible in the OpenCode session picker because corresponding SQLite session rows were not created.
This appears related to project path normalization / project ID recalculation during migration.
Environment
- OS: Windows
- OpenCode version:
1.17.16
- Current project path:
D:\LD\PycharmProjects\PythonProject
- OpenCode data directory:
C:\Users\lvdan\.local\share\opencode
Observed behavior
Running OpenCode from:
cd D:\LD\PycharmProjects\PythonProject
opencode
The session picker shows only 45 sessions.
However, legacy JSON storage still contains hundreds of sessions and message directories.
Diagnostic details
SQLite project table currently contains:
id: 771729023af5c523c0b1de537ff1b06f9c818ae7
worktree: D:/LD/PycharmProjects/PythonProject
Legacy JSON project file exists at:
C:\Users\lvdan\.local\share\opencode\storage\project\7f7996ca0dc3437c35483230cda0ac4c0b408a24.json
That legacy project file contains:
{
"id": "7f7996ca0dc3437c35483230cda0ac4c0b408a24",
"worktree": "D:\\LD\\PycharmProjects\\PythonProject",
"vcs": "git"
}
So the same project appears to have been assigned a different project ID after path normalization:
old project id: 7f7996ca0dc3437c35483230cda0ac4c0b408a24
new project id: 771729023af5c523c0b1de537ff1b06f9c818ae7
Counts observed before any manual import attempt:
SQLite session rows: 45
legacy session JSON files copied/available for current project id: 582
session JSON files present but missing from SQLite: 540
Examples of missing sessions that exist as JSON but are absent from SQLite:
ses_0ba670a95ffeEZNDm0sqFEM7bF | Compare OPS RCT old (@general subagent) | 2026-07-09 06:38:00
ses_0ba670a96ffe6YdLwYNEwU8l42 | Compare OPS h2h (@general subagent) | 2026-07-09 06:38:00
ses_0ba670a97ffePI9p1XB6dR36iQ | Compare OPS outline (@general subagent) | 2026-07-09 06:38:00
ses_0bb50222cffdGjmL4CbaTP1I0i | Compare H2H reports (@general subagent) | 2026-07-09 02:23:24
For missing sessions, corresponding legacy message directories exist, for example:
C:\Users\lvdan\.local\share\opencode\storage\message\ses_0ba670a95ffeEZNDm0sqFEM7bF\
But SQLite has no session row and no message rows for those session IDs.
Relevant migration state
The SQLite migration table includes completed migrations such as:
20260601010001_normalize_storage_paths
20260602182828_add_project_directories
The migration appears to have completed, but it did not import all matching legacy JSON sessions/messages.
Expected behavior
When migrating JSON storage to SQLite, all legacy sessions and their messages for the same project should be imported, even if project path normalization changes the project hash from backslash-style Windows paths to slash-normalized paths.
Alternatively, OpenCode should provide a safe repair command, such as:
opencode migrate
opencode repair
to rescan storage/session/* and storage/message/* and rebuild missing SQLite records.
Actual behavior
Only 45 sessions appear in the session picker. Around 540 legacy session JSON files remain present on disk with corresponding message directories, but are not visible in the UI because SQLite lacks the records.
Safety notes
No JSON files were deleted. A full backup of the OpenCode data directory was created before further troubleshooting.
Suggested labels
sqlite
migration
windows
data-loss or data-visibility
I can provide sanitized metadata or run additional diagnostics if needed, but I will not upload the raw opencode.db publicly because it may contain private session data.
Plugins
No response
OpenCode version
1.17.16
Steps to reproduce
自动更新后,sessions消失
Screenshot and/or share link
No response
Operating System
windows 11
Terminal
powershell7
Description
OpenCode SQLite migration misses legacy JSON sessions after path normalization
Summary
After upgrading OpenCode from an older file-storage based version to
1.17.16, the SQLite migration only imported a small subset of existing sessions. The original JSON session and message files remain intact, but most sessions are not visible in the OpenCode session picker because corresponding SQLitesessionrows were not created.This appears related to project path normalization / project ID recalculation during migration.
Environment
1.17.16D:\LD\PycharmProjects\PythonProjectC:\Users\lvdan\.local\share\opencodeObserved behavior
Running OpenCode from:
The session picker shows only 45 sessions.
However, legacy JSON storage still contains hundreds of sessions and message directories.
Diagnostic details
SQLite project table currently contains:
Legacy JSON project file exists at:
That legacy project file contains:
{ "id": "7f7996ca0dc3437c35483230cda0ac4c0b408a24", "worktree": "D:\\LD\\PycharmProjects\\PythonProject", "vcs": "git" }So the same project appears to have been assigned a different project ID after path normalization:
Counts observed before any manual import attempt:
Examples of missing sessions that exist as JSON but are absent from SQLite:
For missing sessions, corresponding legacy message directories exist, for example:
But SQLite has no
sessionrow and nomessagerows for those session IDs.Relevant migration state
The SQLite migration table includes completed migrations such as:
The migration appears to have completed, but it did not import all matching legacy JSON sessions/messages.
Expected behavior
When migrating JSON storage to SQLite, all legacy sessions and their messages for the same project should be imported, even if project path normalization changes the project hash from backslash-style Windows paths to slash-normalized paths.
Alternatively, OpenCode should provide a safe repair command, such as:
to rescan
storage/session/*andstorage/message/*and rebuild missing SQLite records.Actual behavior
Only 45 sessions appear in the session picker. Around 540 legacy session JSON files remain present on disk with corresponding message directories, but are not visible in the UI because SQLite lacks the records.
Safety notes
No JSON files were deleted. A full backup of the OpenCode data directory was created before further troubleshooting.
Suggested labels
sqlitemigrationwindowsdata-lossordata-visibilityI can provide sanitized metadata or run additional diagnostics if needed, but I will not upload the raw opencode.db publicly because it may contain private session data.
Plugins
No response
OpenCode version
1.17.16
Steps to reproduce
自动更新后,sessions消失
Screenshot and/or share link
No response
Operating System
windows 11
Terminal
powershell7