Skip to content

fix/windows path normalization#21902

Closed
chenyy9527 wants to merge 5 commits intoanomalyco:devfrom
chenyy9527:fix/windows-path-normalization
Closed

fix/windows path normalization#21902
chenyy9527 wants to merge 5 commits intoanomalyco:devfrom
chenyy9527:fix/windows-path-normalization

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 5 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
- Resolve 8.3 short paths in Global.Path via Filesystem.resolve() to ensure
  consistent canonical paths for data/cache/config/state directories
- Normalize path.cwd and path.root with posixPath() in session prompt messages
  for cross-platform consistency
- Fix session project_id update query to use posixPath() on worktree comparison
@github-actions
Copy link
Copy Markdown
Contributor

Hey! Your PR title fix/windows path normalization 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:

Potential Duplicate Found

PR #21852: fix/windows path normalization(#21441)

@chenyy9527 chenyy9527 closed this Apr 10, 2026
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