Skip to content

fix(session): anchor non-git session paths to the directory drive - #41568

Open
wxj006007 wants to merge 1 commit into
anomalyco:devfrom
wxj006007:session-path-stability
Open

fix(session): anchor non-git session paths to the directory drive#41568
wxj006007 wants to merge 1 commit into
anomalyco:devfrom
wxj006007:session-path-stability

Conversation

@wxj006007

Copy link
Copy Markdown

Issue for this PR

Closes #41567

Type of change

  • Bug fix

What does this PR do?

On Windows, non-git projects get a synthetic worktree of "/" (project.ts). path.relative(path.resolve("/"), cwd) then anchors the relative path to the drive root of the process working directory, so the same directory stores different session.path values depending on which drive opencode was launched from (Users/... vs Dev/..., or absolute-style C:/Users/... when crossing drives). Path-based directory filtering in /sessions then hides sessions depending on the launch drive.

The fix anchors a synthetic "/" worktree to the directory's own drive root (path.parse(dir).root) when computing sessionPath(), making stored paths deterministic and independent of the launch drive. On POSIX the root is always "/" so behavior is unchanged. cli/import.ts had a second copy of the same path logic and now reuses sessionPath() to avoid drift.

Note: same-directory visibility from /sessions is scoped by directory in #38532; this PR makes the underlying stored paths stable on Windows.

How did you verify your code works?

  • Added unit tests for sessionPath() covering the git worktree, non-git "/" worktree, and cross-drive absolute results.
  • Added server tests for project-wide (scope: "project") listing and for listing non-git sessions stored relative to the directory root.
  • Ran the session and server test suites, plus bun run typecheck in packages/opencode and the TUI tests.
  • Manually recreated the scenario from [BUG] Windows: session.path for non-git projects is drive-dependent, hiding sessions from /sessions based on launch drive #41567: sessions created from C: remain listed under a path anchored to C:, and no longer produce drive-dependent relative paths.

Screenshots / recordings

N/A (not a UI change)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Non-git projects synthesize a worktree of "/" (project.ts). On Windows
path.resolve("/") anchors to the launch drive root, so the same directory
could store sessions under different relative paths ("Users/..." vs
"Dev/...") depending on which drive opencode was started from, which
made session.path unstable and hid sessions from path-based filters.

- sessionPath(): anchor a synthetic "/" worktree to the directory own
  drive root so stored paths are deterministic (no-op on POSIX where the
  root is always "/"); also reused by cli import to avoid drift.
- tests: unit coverage for sessionPath and server coverage for
  project-wide (scope project) listing of non-git sessions.
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found a related PR that may be addressing similar Windows session path issues:

Related PR:

The current PR (#41568) appears to be a more targeted fix that ensures stored session paths are deterministic across different drive launches on Windows, while #40503 may have addressed an earlier aspect of the same problem. You may want to check if #40503 is still open/merged and whether it fully resolves the underlying issue or if this PR provides a complementary fix.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Windows: session.path for non-git projects is drive-dependent, hiding sessions from /sessions based on launch drive

1 participant