Skip to content

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

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

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.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

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