Skip to content

fix/windows path normalization(#21441)#21852

Open
chenyy9527 wants to merge 3 commits intoanomalyco:devfrom
chenyy9527:fix/windows-path-normalization-21441
Open

fix/windows path normalization(#21441)#21852
chenyy9527 wants to merge 3 commits intoanomalyco:devfrom
chenyy9527:fix/windows-path-normalization-21441

Conversation

@chenyy9527
Copy link
Copy Markdown

Closes #21441

Summary

  • Server: extract Filesystem.posixPath() and apply to all API responses and session read/write paths for consistent POSIX-style output
  • Server: fix contains() and overlaps() to return false for cross-drive paths on Windows
  • Client: use workspaceKey() for all internal map keys to prevent duplicate caches from mixed path formats (D:/foo vs D:\foo)
  • Client: replace duplicated normalizeDirectory in Session with Filesystem.posixPath
  • Test: add unit tests for posixPath, contains, overlaps; update existing tests for path format consistency

Issue for this PR

Closes #21441

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

On Windows, the same directory can have different path formats (D:/foo vs D:\foo), causing:

  1. Path traversal bypasspath.relative() returns the target as-is for cross-drive paths, so contains() incorrectly returned true for arbitrary paths like /etc/passwd.
  2. Cache key mismatches — Internal maps (booting, sdkCache, sessionMeta, etc.) used raw directory as keys, creating duplicate entries and causing session data loss on store eviction.
  3. API format inconsistency — Server responses mixed backslash and forward-slash paths.

Fix: Add isAbsolute guard to contains()/overlaps() for cross-drive detection. Extract posixPath() as single normalization function. Apply it consistently at server API boundaries and client cache keys.

How did you verify your code works?

  • bun typecheck passes (13/13 packages)
  • Path-traversal tests pass (15/15), including cross-drive checks on Windows
  • App tests: 301/301 pass. Opencode tests: 585/589 pass (3 pre-existing failures unrelated)
  • Verified posixPath() edge cases: drive roots, trailing slashes, mixed separators
  • Traced the full data flow: page refresh → two loadSessions call paths → API requests → store writes → render, confirming the normalization unifies all paths.

Checklist

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

chenyiy@133.cn added 3 commits April 10, 2026 15:44
…omalyco#21441)

On Windows, directory paths used backslashes which caused cache key
mismatches in Maps (booting, sdkCache, sessionMeta, queue, prefetch,
seen). Extract Filesystem.posixPath() on the server and consistently
use workspaceKey() on the client so all lookups use normalized paths.
… compatibility (anomalyco#21441)

- Update project.test.ts to use Filesystem.posixPath for sandbox comparisons
- Update global-session-list.test.ts to use Filesystem.posixPath for worktree comparisons
- Add unit tests for posixPath, contains, and overlaps
…-normalization

# Conflicts:
#	packages/app/src/context/sync.tsx
#	packages/opencode/src/server/instance.ts
@github-actions
Copy link
Copy Markdown
Contributor

Hey! Your PR title fix/windows path normalization(#21441) doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

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

Based on my search, I found several potentially related PRs addressing Windows path handling issues:

Related/Potentially Duplicate PRs:

  1. PR fix: normalize directory paths for session list queries on Windows #17067 - "fix: normalize directory paths for session list queries on Windows"

  2. PR fix(windows): keep project paths stable across aliases #18709 - "fix(windows): keep project paths stable across aliases"

  3. PR fix(patch): parse Windows drive-letter paths #10808 - "fix(patch): parse Windows drive-letter paths"

Note: The primary results all return PR #21852 (the current PR being checked), so these are the only distinct related PRs found in the search results.

@github-actions github-actions bot mentioned this pull request Apr 10, 2026
6 tasks
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.

SortableWorkspace session list empty due to store.path.directory not bootstrapped

1 participant