Skip to content

[Windows] Non-git projects get an absolute session.path, hiding those sessions from the TUI session list #48762

Description

@xiaobright

Description

session.path is supposed to be the session directory relative to the project worktree, but for non-git projects on Windows it is written as an absolute path. The TUI session picker filters on the relative value, so those sessions are never listed — even though they are intact in opencode.db and opencode export <id> still works.

Root cause is in packages/core/src/session.ts (dev @ 95daf906):

const project = yield* projects.resolve(input.location.directory)
...
path: path.relative(project.directory, input.location.directory).replaceAll("\\", "/"),

For a non-git directory the resolved project directory is "/" (the global project row in project has worktree = '/'). On Windows / is resolved against the current process drive, so path.relative("/", "E:/Desktop/x") is a cross-drive relative and Node returns the absolute path unchanged. The row therefore gets path === directory.

The same happens to a C: directory if the process was started from another drive. In my DB the bad rows just happen to be the E: ones — it is the process drive that decides, not the directory.

The picker's filter (packages/opencode/src/session/session.ts, listByProject) is:

eq(SessionTable.path, input.path)
like(SessionTable.path, `${input.path}/%`)
and(isNull(SessionTable.path), eq(SessionTable.directory, input.directory))

An absolute path matches none of the three.

Plugins

None.

OpenCode version

session.version on the 26 affected rows: local 17, 1.18.19 5, 1.18.25 3, 1.18.15 1. The root cause is still present in dev at 95daf906.

Steps to reproduce

  1. On Windows, open a non-git directory on a drive other than the one the process runs from (e.g. E:\work while the app lives on C:).
  2. Create a session there.
  3. Open the TUI in the same directory and look at the session list. The session is missing; it appears if the query is re-run with the absolute value.

Screenshot and/or share link

No screenshot — there is no visual difference beyond the missing list entries. The DB evidence is below.

Operating System

Windows 11 (10.0.26200)

Terminal

No response

Evidence from my DB (271 sessions, shared by the v1 CLI and the v2 desktop / dev builds)

  • 245 rows: path relative
  • 26 rows: path absolute, and all 26 are byte-identical to directory
  • all 26 are on E:, none on C:

So it only shows up on a non-system drive, which makes it look intermittent. Replaying the picker's query against my DB: the relative form matches 53 sessions for that directory, the absolute form matches 9 — the absolute ones are exactly the missing ones.

Expected behavior

path stays relative to the worktree, or the picker tolerates both forms.

Related

Workaround for other users

With OpenCode closed, normalize the column so the relative form matches:

UPDATE session SET path = substr(path, 4) WHERE path GLOB '[A-Za-z]:/*';

Also patch the "path" value inside the matching session.created.1 / session.updated.1 rows in event, otherwise a projection rebuild restores the absolute value.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions