Skip to content

SQLite migration missed legacy JSON sessions after Windows path normalization #36178

Closed as not planned

Description

@lvdansara

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

Activity

  1. github-actions commented on Jul 10, 2026

    @github-actions
    Contributor

    This issue does not fully meet our contributing guidelines.

    What needs to be fixed:

    • The issue title appears to be a raw gh issue create CLI command rather than a descriptive title.
    • The Description field contains only a file attachment link — please paste the actual description text directly into the issue body so it is readable without downloading a file.
    • OpenCode version is empty — this is required for bug reports.
    • Steps to reproduce is empty — please describe how to trigger the issue.

    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:

    If you believe this was flagged incorrectly, please let a maintainer know.

  2. changed the title [-]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[/+] on Jul 10, 2026
  3. github-actions commented on Jul 10, 2026

    @github-actions
    Contributor

    Thanks for updating the issue. Unfortunately it still needs a few fixes before it meets our contributing guidelines:

    1. Description field: The description only links to an attached file rather than providing inline content. Please paste the relevant details directly into the issue body so reviewers can read it without downloading a file.
    2. Steps to reproduce: This required field is empty. Please describe how to reproduce the issue (e.g. what you did before the migration ran, what opencode version you came from, etc.).
    3. OpenCode version: Please fill in the version you are running (e.g. output of opencode --version).

    Once you've added that information inline, we'll be happy to re-review. Thank you!

  4. github-actions commented on Jul 10, 2026

    @github-actions
    Contributor

    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.

  5. kvnloo commented on Aug 24, 2026

    @kvnloo

    Thanks for the detailed diagnostics — the id divergence you show (SQLite row 771729... vs legacy JSON project file 7f7996... 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:

    1. In the migrator, derive/lookup project ids by trying both raw and normalized forms of the worktree before skipping.
    2. Fail loud instead of silent: report a count of unmigrated legacy sessions at startup so users know data exists but wasn't imported.

    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.

  6. marketfauna commented on Sep 20, 2026

    @marketfauna

    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.resolve tries 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>.json filename; 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.

  7. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    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 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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