Skip to content

Sessions disappear after renaming project folder - directory matching is case-sensitive with inconsistently normalized stored paths #44538

Description

@jvirkel

Description

Environment

  • OpenCode desktop app 1.18.18
  • Windows 10 22H2 (build 19045)

Steps to reproduce

  1. Create sessions in a project folder (e.g. D:\Documents\Default Project)
  2. Rename that folder to something else (e.g. D:\Documents\OpenCode)
  3. Open the app on the renamed folder -> session list is empty
  4. Rename the folder back -> sessions still do not appear reliably

Expected behavior

Renaming a project folder should not orphan its sessions. Windows paths are
case-insensitive, so d: and D: must be treated as identical.

Actual behavior / root cause

Session listing filters by exact string comparison:

listByProject() in packages/opencode/src/session/session.ts does
eq(SessionTable.directory, input.directory) — case-sensitive SQLite match.

Meanwhile, stored session.directory values are normalized inconsistently.
Found in the same database, created by opencode itself:

  • D:/Documents/Default Project
  • d:/Documents/Default Project <-- lowercase drive letter

The desktop app also stores the registered project as d:\\Documents\\OpenCode
(lowercase) in its state file, while other components use uppercase. So even
after manually updating all DB paths to the "correct" casing shown by Explorer,
/api/session?directory=D:\Documents\OpenCode returned 6 sessions but the UI
requested d:\Documents\OpenCode and got 0.

The event-sourced payloads (event table, type session.created/updated)
also embed the old directory path inside their JSON, which kept stale paths
alive after fixing the session table.

Data loss appearance

Nothing was actually lost (messages live in the global opencode.db), but from
the user's perspective ALL sessions vanish after a folder rename, which looks
catastrophic.

Suggested fix

Resolve both sides to a canonical real path (e.g. via realpath) before storing
and before comparing, or compare case-insensitively on Windows.

Workaround used

Directly updated opencode.db: session.directory, session.path and every
JSON directory field inside the event table, matching the exact casing the
app sends (d:\Documents\OpenCode). Sessions reappeared after app restart.

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

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