GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Windows: FileTime read-gate path normalization mismatch causes false 'must read first' errors · Issue #20354 · anomalyco/opencode

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

New issue
Copy link
New issue
Copy link
Closed
#20367
Closed
Windows: FileTime read-gate path normalization mismatch causes false 'must read first' errors#20354
#20367
Copy link
Assignees
Hona
Labels
coreAnything pertaining to core functionality of the application (opencode server stuff)windows

Description

@JosXa
JosXa
opened on Mar 31, 2026
Issue body actions

Summary

On Windows, the FileTime read-gate (the "You must read file X before overwriting it" safety check) uses exact string equality on a Map<string, Stamp> to verify that a file was read before allowing writes/edits. However, the read tool normalizes the filepath before storing it, while the write and edit tools do not normalize before looking it up. This causes false-positive "must read first" errors on Windows when forward and backslashes are mixed, even when the file was just successfully read.

Image

Root Cause

packages/opencode/src/file/time.ts:85-90 — The FileTime.assert() function does a raw Map.get(filepath) with no normalization:

const time = reads.get(sessionID)?.get(filepath)
if (!time) throw new Error(`You must read file ${filepath} before overwriting it. Use the Read tool first`)

The three tools handle paths differently before interacting with this map:

Tool File Normalization before map operation
Read read.ts:36-38 Filesystem.normalizePath(filepath) on win32 — converts / to \, resolves canonical casing via realpathSync.native
Write write.ts:27 None — raw params.filePath passed to FileTime.assert()
Edit edit.ts:54 None — raw params.filePath passed to FileTime.assert()

What happens

  1. LLM calls Read with C:/Users/foo/bar.ts (forward slashes)
  2. read.ts normalizes to C:\Users\Foo\bar.ts and stores that in the Map
  3. LLM calls Edit with C:/Users/foo/bar.ts (same string it used for Read)
  4. edit.ts passes C:/Users/foo/bar.ts directly to FileTime.assert()
  5. Map.get("C:/Users/foo/bar.ts") returns undefined (stored key is C:\Users\Foo\bar.ts)
  6. Error thrown: "You must read file C:/Users/foo/bar.ts before overwriting it"

Display masking

The TUI normalizes displayed paths to backslashes for ALL tools, so the user sees identical paths in both the Read and Edit tool calls. The mismatch is completely invisible in the UI.

Edge Cases

Beyond forward/backslash differences, this also affects:

  • Case sensitivity: realpathSync.native in normalizePath resolves to the filesystem's true casing. A path like c:\users\... would be stored as C:\Users\... after read, but asserted as c:\users\... by edit.
  • Relative path resolution: read.ts uses path.resolve() while write.ts uses path.join(). These differ for paths containing .. segments.

Proposed Fix

Apply Filesystem.normalizePath() in write.ts and edit.ts the same way read.ts already does, before calling FileTime.assert() and FileTime.read().

In write.ts (~line 27):

let filepath = path.isAbsolute(params.filePath)
  ? params.filePath
  : path.join(Instance.directory, params.filePath)
if (process.platform === "win32") {
  filepath = Filesystem.normalizePath(filepath)
}

Same pattern in edit.ts (~line 54).

Alternatively, normalize inside FileTime.assert() and FileTime.read() themselves so all callers get consistent behavior automatically.

Workaround

Set OPENCODE_DISABLE_FILETIME_CHECK=true to bypass the check entirely.

Environment

  • OS: Windows 11
  • OpenCode: latest (from npm)
  • Shell: PowerShell / NuShell
  • LLM paths use forward slashes (standard Claude/GPT behavior)

Activity

  1. github-actions
    assigned
    Hona
    on Mar 31, 2026
  2. github-actions
    added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    windows
    on Mar 31, 2026
  3. github-actions commented on Mar 31, 2026

    @github-actions
    github-actionsBot
    on Mar 31, 2026 – with GitHub Actions
    Contributor
    More actions

    This issue might be a duplicate of existing issues. Please check:

    • Write tool overwrite guard compares raw path strings without canonicalization (Windows) #18028: Same Windows path canonicalization bug — Write tool overwrite guard compares raw path strings without normalization, causing false 'must read file first' errors when Read and Write use different path representations (relative vs absolute, forward vs backslashes, drive-letter casing)
    • Error: You must read file before overwriting it. Use the Read tool first #12402: Same 'You must read file before overwriting it' error (broader scope, not Windows-specific)
  4. JosXa commented on Mar 31, 2026

    @JosXa
    JosXa
    on Mar 31, 2026
    ContributorAuthor
    More actions

    This issue might be a duplicate of existing issues. Please check:

    • Write tool overwrite guard compares raw path strings without canonicalization (Windows) #18028: Same Windows path canonicalization bug — Write tool overwrite guard compares raw path strings without normalization, causing false 'must read file first' errors when Read and Write use different path representations (relative vs absolute, forward vs backslashes, drive-letter casing)
    • Error: You must read file before overwriting it. Use the Read tool first #12402: Same 'You must read file before overwriting it' error (broader scope, not Windows-specific)

    Probably a duplicate, yes, but with more precise exploration and findings around what actually causes it

  5. JosXa commented on Mar 31, 2026

    @JosXa
    JosXa
    on Mar 31, 2026
    ContributorAuthor
    More actions

    Reproduction

    Requires: Windows, OpenCode installed.

    Setup

    echo "hello world" > C:\tmp\opencode-repro.txt

    Test 1: Read then Edit

    opencode run "There is a bug where the Read tool normalizes Windows paths (forward slashes to backslashes) before storing in the FileTime map, but Edit does not normalize before lookup. To reproduce: 1) Read the file using forward slashes: C:/tmp/opencode-repro.txt 2) Edit it using the SAME forward-slash path to replace 'hello' with 'goodbye'. IMPORTANT: You MUST use forward slashes C:/tmp/opencode-repro.txt for BOTH calls. Do NOT retry or switch to backslashes. If the Edit fails with 'must read first', output exactly: REPRODUCED. If it succeeds, output exactly: NOT REPRODUCED."

    Test 2: Read then Write

    echo "hello world" > C:\tmp\opencode-repro.txt
    opencode run "There is a bug where the Read tool normalizes Windows paths (forward slashes to backslashes) before storing in the FileTime map, but Write does not normalize before lookup. To reproduce: 1) Read the file using forward slashes: C:/tmp/opencode-repro.txt 2) Write to it using the SAME forward-slash path with content 'goodbye world'. IMPORTANT: You MUST use forward slashes C:/tmp/opencode-repro.txt for BOTH calls. Do NOT retry or switch to backslashes. If the Write fails with 'must read first', output exactly: REPRODUCED. If it succeeds, output exactly: NOT REPRODUCED."

    Both output REPRODUCED.

  6. JosXa
    added a commit that references this issue on Mar 31, 2026

    fix: normalize filepath in FileTime to prevent Windows path mismatch (a…

    69af636
  7. Hona
    closed this as completedin #20367on Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @Hona
    Hona

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)windows

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.