Skip to content

OpenCode sometimes loses the history of open projects and sessions between restarts #14546

Closed

Description

@nukeop

Description

This is tricky because I can't tell why and when it happens.

Sometimes when I restart OpenCode and launch the web UI the recently opened projects in the sidebar are blank. If I open a project with cmd+P, then my previous sessions are usually there.

But sometimes they will also be completely blank, and I can't go back to my previous session anymore, forcing me to start from scratch. If that happens, then even going to these sessions by URL won't work.

Plugins

None

OpenCode version

1.2.10

Steps to reproduce

  • Turn off the server
  • Launch opencode web
  • Go to web UI
  • Verify if previous projects and sessions are there

Screenshot and/or share link

No response

Operating System

Mac OS

Terminal

Ghostty

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Feb 21, 2026
  2. github-actions commented on Feb 21, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If your issue is distinct from the above (e.g., it happens after a clean shutdown rather than an unexpected termination, or is specific to the web UI sidebar not reflecting existing sessions), please add a note clarifying the difference so we can track it separately.

  3. nukeop commented on Feb 21, 2026

    @nukeop
    Author

    I think this is distinct, because:

    • This is caused not by a crash, or by kill -9, but by terminating the process with ctrl-c which should clean up correctly
    • Session loss might be related, but in my case I also lose active project history, and ALL sessions, not just the one I was working on
  4. isc-tdyar commented on Feb 22, 2026

    @isc-tdyar

    I hit this on macOS after a hard restart (MacBook power loss) and was able to diagnose the root cause:

    Root cause: SQLite DB and file storage are written at different times

    opencode maintains two parallel stores for sessions:

    1. ~/.local/share/opencode/opencode.db (SQLite) — written quickly
    2. ~/.local/share/opencode/storage/session/<project_id>/<session_id>.json — written later (or lazily flushed)

    After a hard crash/restart, the SQLite DB had all sessions intact (including full message history via the message table), but the corresponding .json stub files in the file storage were never written. Since the session list UI appears to be driven by the file storage rather than the DB, those sessions were invisible — even though all data was in SQLite.

    Workaround: Reconstruct the missing .json files from the DB:

    STORAGE_DIR=~/.local/share/opencode/storage/session/<your_project_id>
    sqlite3 ~/.local/share/opencode/opencode.db \
      "SELECT id, slug, version, project_id, directory, title, time_created, time_updated, summary_additions, summary_deletions, summary_files FROM session WHERE project_id = '<your_project_id>';" \
      | while IFS='|' read id slug version projectID directory title time_created time_updated additions deletions files; do
        FILE="$STORAGE_DIR/${id}.json"
        if [ ! -f "$FILE" ]; then
          cat > "$FILE" <<EOF
    {
      "id": "$id",
      "slug": "$slug",
      "version": "$version",
      "projectID": "$projectID",
      "directory": "$directory",
      "title": "$title",
      "time": { "created": $time_created, "updated": $time_updated },
      "summary": { "additions": $additions, "deletions": $deletions, "files": $files }
    }
    EOF
          echo "Restored: $id"
        fi
      done

    Fix suggestion: Either make the session list read from SQLite (single source of truth), or ensure the .json file is written atomically before the DB record is committed. The current split-write design creates a durability window where a crash leaves the two stores out of sync.

  5. github-actions commented on Apr 24, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 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

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions