You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
patch: case-only rename deletes the file on case-insensitive filesystems #63126
On a case-insensitive filesystem (the macOS and Windows defaults), a patch that only changes the case of a file name deletes the file.
packages/core/src/tool/plugin/patch.ts:185 treats the hunk as a move because same.txt and Same.txt are different strings. That check comes from #59197, which fixed moves onto the exact same path (./same.txt), but it doesn't catch a case change. The apply step then writes Same.txt, which overwrites same.txt in place, and removes same.txt, which is the same file (patch.ts:233-239). The tool then fails with:
Failed to read <dir>/Same.txt: file does not exist. Completed before failure: Same.txt
On a case-sensitive filesystem the same patch renames the file correctly.
The v1 branch has the same write-then-remove in apply_patch.ts and no guard even for the exact same path (#45310 was closed, but its fix #45316 was not merged).
On a case-insensitive filesystem, create same.txt containing before.
Run the patch tool with:
*** Begin Patch
*** Update File: same.txt
*** Move to: Same.txt
@@
-before
+after
*** End Patch
The directory is now empty and the tool returns the error above. Expected: Same.txt containing after.
I reproduced it with a test added to packages/core/test/tool-patch.test.ts (using withTempTool and executeTool), run with TMPDIR on a vfat mount. The same test passes on ext4.
Screenshot
No response
Operating System
macOS and Windows (any case-insensitive volume); reproduced on Linux with a vfat mount
Thanks for the detailed report. I reproduced this on 2.2.7, and it still happens on the latest dev (8f0bf22d6).
Setup: a case-insensitive vfat mount on Linux with same.txt containing before. A simulated model calls the patch tool with *** Update File: same.txt / *** Move to: Same.txt and changes -before to +after. The tool fails with Failed to read .../Same.txt: file does not exist. Completed before failure: .../Same.txt, and the directory is left empty. As you describe, the move is detected by a plain string comparison of the paths, so writing Same.txt and then removing same.txt deletes the only file.
The recording and screenshot below show it on 2.2.7 and on dev, and the script below reproduces it (it needs a case-insensitive mount at /mnt/fat).
Related: #59197 (the earlier fix for moves onto the exact same path) and #45310 (the same-path problem on v1).
recording.mp4
Reproduction script (drive.ts)
// Reproduces anomalyco/opencode#63126: a case-only rename via the patch tool// deletes the file on a case-insensitive filesystem.//// Prerequisite (as root): a vfat (case-insensitive) mount at /mnt/fat:// truncate -s 64M /tmp/fat.img && mkfs.vfat /tmp/fat.img// mkdir -p /mnt/fat && mount -o loop /tmp/fat.img /mnt/fat// Run: OPENCODE_DRIVE_MEDIA_DIR=/workspace/media opencode-drive run drive.ts// (set OC_DEV=/path/to/opencode-checkout to run from source)import{Effect,Stream}from"effect"import{mkdirSync,readdirSync,rmSync,writeFileSync,readFileSync}from"node:fs"import{Llm,OpenCodeDriver}from"opencode-drive"constdir="/mnt/fat/case-repro"exportdefaultOpenCodeDriver.use({
...(process.env.OC_DEV ? {opencode: {dev: process.env.OC_DEV}} : {}),config: {permission: "allow"},tui: {recording: true},},({ ui, llm })=>Effect.gen(function*(){rmSync(dir,{recursive: true,force: true})mkdirSync(dir,{recursive: true})writeFileSync(`${dir}/same.txt`,"before\n")console.log("BEFORE:",readdirSync(dir))constpatchText=["*** Begin Patch",`*** Update File: ${dir}/same.txt`,`*** Move to: ${dir}/Same.txt`,"@@","-before","+after","*** End Patch",].join("\n")// Title requests go to the same simulated model; answer them separately.letmain=0yield*llm.serve((request)=>{if(JSON.stringify(request).includes("You name conversations"))returnStream.make(Llm.text("Case rename"))main++if(main===1)returnStream.make(Llm.toolCall({index: 0,id: "call_patch",name: "patch",input: { patchText }}),Llm.finish("tool-calls"),)returnStream.make(Llm.text("Patch step finished."))})yield*ui.submit(`Rename ${dir}/same.txt to Same.txt and change before to after`)yield*ui.waitFor("Patch step finished.",{timeout: 25000})yield*Effect.sleep(1500)yield*ui.screenshot("after-patch")constfiles=readdirSync(dir)console.log("AFTER:",files)for(constfoffiles)console.log(`${f}:`,JSON.stringify(readFileSync(`${dir}/${f}`,"utf8")))console.log(files.length===0 ? "BUG REPRODUCED: file was deleted" : "file survived")}),)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
I'd like to work on this. My plan is to treat a move whose new path differs from the old one only in letter case as a rename: rename the file first, then write the updated content, instead of writing the new name and removing the old one. I'll add a regression test to tool-patch.test.ts that fails on a case-insensitive filesystem without the fix. Could you assign it to me?
Activity
opencodejr commentedon Nov 10, 2026
Thanks for the detailed report. I reproduced this on 2.2.7, and it still happens on the latest
dev(8f0bf22d6).Setup: a case-insensitive vfat mount on Linux with
same.txtcontainingbefore. A simulated model calls thepatchtool with*** Update File: same.txt/*** Move to: Same.txtand changes-beforeto+after. The tool fails withFailed to read .../Same.txt: file does not exist. Completed before failure: .../Same.txt, and the directory is left empty. As you describe, the move is detected by a plain string comparison of the paths, so writingSame.txtand then removingsame.txtdeletes the only file.The recording and screenshot below show it on 2.2.7 and on
dev, and the script below reproduces it (it needs a case-insensitive mount at/mnt/fat).Related: #59197 (the earlier fix for moves onto the exact same path) and #45310 (the same-path problem on v1).
recording.mp4
Reproduction script (drive.ts)
Run it with opencode-drive:
opencode-drive run ./drive.ts. It drivesopencodefrom yourPATH; setOC_DEVto the path of an OpenCode checkout to run that from source instead.KrBeTect2025 commentedon Nov 10, 2026
I'd like to work on this. My plan is to treat a move whose new path differs from the old one only in letter case as a rename: rename the file first, then write the updated content, instead of writing the new name and removing the old one. I'll add a regression test to tool-patch.test.ts that fails on a case-insensitive filesystem without the fix. Could you assign it to me?