Skip to content

fix(patch): handle Windows drive-letter colons in patch header path parsing#13582

Open
machinekoder wants to merge 2 commits intoanomalyco:devfrom
machinekoder:fix/windows-patch-path-parsing
Open

fix(patch): handle Windows drive-letter colons in patch header path parsing#13582
machinekoder wants to merge 2 commits intoanomalyco:devfrom
machinekoder:fix/windows-patch-path-parsing

Conversation

@machinekoder
Copy link
Copy Markdown

Summary

  • parsePatchHeader used line.split(':', 2) to extract file paths from headers like *** Update File: D:\path\file.ts. On Windows, the colon in the drive letter (e.g. D:) caused split to truncate the path to just the drive letter, producing invalid resolved paths like <project_dir>\D.
  • Replaced split(':') with slice() after the known prefix length so the full path including drive letter is preserved.
  • Added regression test covering all 4 header types (Add File, Delete File, Update File, Move to) with Windows drive-letter paths.

Reproduction

When a model generates a patch with an absolute Windows path:

*** Update File: D:\repos\project\src\file.ts

The parser splits on : and gets ["*** Update File", " D"], truncating the path to D. This is then resolved as path.resolve(projectDir, "D") producing e.g. D:\repos\project\D, which fails with:

Error: apply_patch verification failed: Failed to read file to update: D:\repos\project\D

Fixes #10360. Related to #11687.

Note: Similar fix to #10808 — arrived at independently. This PR uses a simpler inline approach while #10808 extracts a helper function. Either approach resolves the issue.

…arsing

parsePatchHeader used line.split(':', 2) to extract file paths from
headers like '*** Update File: D:\path\file.ts'. On Windows, the colon
in the drive letter (D:) caused split to truncate the path to just the
drive letter, producing invalid paths like 'D:\project\D'.

Replace split(':') with slice() after the known prefix length so the
full path including drive letter is preserved.
Copilot AI review requested due to automatic review settings February 14, 2026 11:17
@github-actions
Copy link
Copy Markdown
Contributor

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

Potential Related PR Found:

Note: The PR description acknowledges #10808 as a similar fix arrived at independently, so this is a known related PR rather than a true duplicate.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Windows-specific path truncation in Patch.parsePatchHeader by avoiding ':' splitting in patch headers (e.g., *** Update File: D:\...) and adds a regression test to cover all supported header types with drive-letter paths.

Changes:

  • Update patch header parsing to slice the path substring after the known header prefix rather than splitting on :.
  • Add a regression test ensuring Windows drive-letter paths are parsed correctly for Add File, Delete File, Update File, and Move to.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/opencode/src/patch/index.ts Fixes header path extraction to preserve Windows drive-letter colons.
packages/opencode/test/patch/patch.test.ts Adds a regression test covering colon-containing (drive-letter) paths across header types.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@machinekoder
Copy link
Copy Markdown
Author

Copilot approves as well, the fix is minimal and should solve most of the problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows apply_patch fails

2 participants