Skip to content

Desktop/Windows: newly opened project has sessions in SQLite but missing history/sidebar because opencode.global.dat is not updated #26207

Description

@gavlovsky

Description

Description

On OpenCode Desktop for Windows, newly opened projects sometimes have their sessions correctly stored in the SQLite database, but the Desktop UI does not show the project/session history in the sidebar after restart or project switch.

The database is not corrupted: the session exists in:

%USERPROFILE%\.local\share\opencode\opencode.db
But the Desktop state in:

%APPDATA%\ai.opencode.desktop\opencode.global.dat
is missing or stale for the project.

In affected cases, manually repairing the Desktop global state restores the sidebar/history immediately.

Environment
OpenCode Desktop: observed on v1.14.32
OS: Windows
Data paths:
DB: %USERPROFILE%\.local\share\opencode\opencode.db
Desktop global state: %APPDATA%\ai.opencode.desktop\opencode.global.dat
Actual behavior
After creating/opening a new local project and starting a session:

session rows exist in SQLite table session
messages exist in message / part
but Desktop sidebar/history does not show the project/session correctly
closing/reopening projects may remove the project from the Desktop project list again
The missing/stale state is in Desktop persisted global state, specifically project/session mapping and project list state.

In my installed version, the repair required updating:

layout.page.lastProjectSession[<project-directory>] = {
  "directory": "<project-directory>",
  "id": "<latest-session-id>",
  "at": <timestamp>
}
and ensuring:

server.projects.local[] includes {
  "worktree": "<project-directory>",
  "expanded": true
}
and optionally:

server.lastProject.local = "<project-directory>"
Expected behavior
When a local project is opened and a session is created, Desktop should persist enough global state so that after restart/project switch:

the project remains in the sidebar/project list
its latest session/history is visible
the UI does not require manual repair of opencode.global.dat
Reproduction outline
Run OpenCode Desktop on Windows.
Open/create a new local project, e.g.:
D:\Documents\(Source)\repos\some-new-project
Start a session and send at least one message.
Close/restart OpenCode Desktop or switch projects.
Observe that the project/session history is missing from the Desktop sidebar.
Inspect SQLite DB:
session contains a row for the project directory
message / part contain conversation data
Inspect Desktop global state:
opencode.global.dat is missing the project in the persisted project list and/or latest-session mapping.
Evidence / diagnostics
A local read-only SQLite diagnostic showed:

PRAGMA quick_check = ok
sessions exist in session
messages exist in message
parts exist in part
Manual workaround:

Read latest session for target directory from SQLite.
Add/update project/session mapping in %APPDATA%\ai.opencode.desktop\opencode.global.dat.
Restart Desktop.
Sidebar/history becomes visible again.
This indicates the bug is likely in Desktop/app persistence, not in SQLite session storage.

Suspected source areas
Likely related source files:

packages/app/src/context/server.tsx
Persist.global("server", ["server.v3"])
server.projects.open(directory)
server.projects.touch(directory)
server.projects.list()
packages/app/src/context/layout.tsx
layout.projects.open(directory)
sidebar/project list
loading sessions for server.projects.list()
packages/app/src/pages/home.tsx
openProject(directory) calls:
layout.projects.open(directory)
server.projects.touch(directory)
packages/app/src/utils/persist.ts
GLOBAL_STORAGE = "opencode.global.dat"
Persist.global(...)
Desktop storage bridge:
packages/desktop/src/renderer/index.tsx
packages/desktop/src/main/ipc.ts
packages/desktop/src/main/store.ts
Possible cause
The project/session exists in backend/global SQLite state, but the client-side Desktop persisted state is not always updated or is later overwritten.

This looks related to the sidebar project list being derived from persisted server.projects.* state instead of being reconciled with projects/sessions that exist in the server/SQLite database.

Related issues
Possibly related:

#26165 — direct project navigation does not add project to sidebar
#25131 — stale Desktop session IDs / lastProjectSession state
#25629 — Desktop stalls during storage writes to opencode.global.dat
Suggested fix
When a project/session is opened or loaded successfully:

ensure the project is present in persisted server.projects[local]
ensure the latest valid session is associated with that project
reconcile persisted Desktop project list with server/SQLite project/session data
normalize Windows path casing consistently
if a persisted session reference is missing/stale, clear it and recover instead of hiding/crashing

### Plugins

_No response_

### OpenCode version

1.14.40

### Steps to reproduce

_No response_

### Screenshot and/or share link

_No response_

### Operating System

Windows 11

### Terminal

_No response_

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