Skip to content

fix: normalize filepath in FileTime to prevent Windows path mismatch#20367

Open
JosXa wants to merge 1 commit intoanomalyco:devfrom
JosXa:fix-filetime-path-normalization
Open

fix: normalize filepath in FileTime to prevent Windows path mismatch#20367
JosXa wants to merge 1 commit intoanomalyco:devfrom
JosXa:fix-filetime-path-normalization

Conversation

@JosXa
Copy link
Copy Markdown
Contributor

@JosXa JosXa commented Mar 31, 2026

Issue for this PR

Closes #20354

Type of change

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

What does this PR do?

On Windows, the Read tool normalizes file paths (forward slashes to backslashes, canonical casing via realpathSync.native) before calling FileTime.read(), which stores the normalized path as a Map key. But Write and Edit tools pass the raw path (often with forward slashes from LLM output) to FileTime.assert(), which looks up the un-normalized key and fails with a false "must read file before editing/writing" error.

The fix adds Filesystem.normalizePath() at the entry of all four FileTime Effect functions (read, get, assert, getLock). This is the single choke point where all file-time operations converge, so normalizing here guarantees consistent Map keys regardless of how callers format the path. On non-Windows platforms, normalizePath is a no-op, so there's no behavioral change.

How did you verify your code works?

  1. Typecheck passes
  2. All 19 FileTime tests pass (15 existing + 4 new path normalization tests covering forward/backslash combinations for read, get, assert, and withLock)
  3. Ran the patched build via bun dev run with the exact repro steps from the issue (Read with forward slashes then Edit/Write with same forward-slash path) - both succeeded without error

Screenshots / recordings

N/A - no UI change

Checklist

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

@github-actions github-actions bot added contributor needs:compliance This means the issue will auto-close after 2 hours. labels Mar 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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

Based on my search results, I found two related PRs about Windows path normalization that might be relevant:

These PRs appear to address similar Windows path normalization issues, though they focus on session queries rather than FileTime specifically. However, they're addressing the same underlying problem of path format inconsistencies on Windows. You may want to verify if there's any overlap in scope or if these should be coordinated.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

Windows: FileTime read-gate path normalization mismatch causes false 'must read first' errors

1 participant