Repository navigation
Description
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
opencodeThe 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
sqlitemigrationwindowsdata-lossordata-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
Activity
github-actions commentedon Jul 10, 2026
This issue does not fully meet our contributing guidelines.
What needs to be fixed:
gh issue createCLI command rather than a descriptive title.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:
~/.local/share/opencodeand did not migrate legacy sessionsIf you believe this was flagged incorrectly, please let a maintainer know.
[-]gh issue create --repo sst/opencode --title "SQLite migration missed legacy JSON sessions after Windows path normalization" --body-file opencode_sqlite_migration_issue.md[/-][+]SQLite migration missed legacy JSON sessions after Windows path normalization[/+]github-actions commentedon Jul 10, 2026
Thanks for updating the issue. Unfortunately it still needs a few fixes before it meets our contributing guidelines:
opencode --version).Once you've added that information inline, we'll be happy to re-review. Thank you!
github-actions commentedon Jul 10, 2026
Thank you for updating the issue! The description now includes clear diagnostic details, environment information, and version context. The issue looks good — we appreciate the thorough write-up.
kvnloo commentedon Aug 24, 2026
Thanks for the detailed diagnostics — the id divergence you show (SQLite row
771729...vs legacy JSON project file7f7996...for the same worktree) pins this to path normalization differing between the JSON-era project-id derivation and the SQLite migrator: one hashed a normalized forward-slash path, the other the raw Windows backslash form, so every session keyed under the old project id is skipped silently.Two suggestions that would make the fix robust rather than point:
This should be unit-testable cross-platform with synthetic legacy-storage fixtures (no Windows machine needed). Happy to help with a PR if maintainers want it.
marketfauna commentedon Sep 20, 2026
AI-assisted source check; I haven't reproduced this against your backup.
The reported version has another project-ID path worth distinguishing from slash normalization: v1.17.16
Project.resolvetries a remote-derived ID, then the cached ID, then a Git root commit. The named path-normalization migration updates path fields, not project/session IDs. The two different IDs alone therefore don't establish that raw versus normalized path hashing caused this case.In the historical JSON importer, a session's parent directory name must match a readable
project/<id>.jsonfilename; otherwise it increments the orphan counter and skips the session. A useful next distinction in the preserved backup is whether the missing session IDs are under directories with or without that matching project file. Counts of those two groups can be shared without session text or the database.That importer is historical evidence, not a verified repair for 1.17.16. I wouldn't rewrite IDs or move legacy files on this evidence.
thdxr commentedon Oct 11, 2026
Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (
opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊