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

Open
opened 2026-02-16 18:19:29 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13582

State: open
Merged: No


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.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13582 **State:** open **Merged:** No --- ## 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.
yindo added the pull-request label 2026-02-16 18:19:29 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14722