Description
apply_patch writes files sequentially. When a patch touches multiple files and a later file fails (disk full, stale content, permission denied), earlier files stay modified on disk with no rollback. The workspace is left in an inconsistent state.
The tool description itself acknowledges the gap: "if a later operation fails, earlier operations remain applied." Both V1 (packages/opencode/src/tool/apply_patch.ts) and V2 (packages/core/src/tool/apply-patch.ts) have this behavior. A TODO in file-mutation.ts confirms it needs fixing.
Plugins
None
OpenCode version
dev branch (58ba99e)
Steps to reproduce
- Have two files in a workspace: first.txt and second.txt (second.txt has stale content)
- Ask OpenCode to apply a patch that deletes first.txt and updates second.txt with outdated expected content
- The delete succeeds, the update fails with StaleContentError
- first.txt is permanently deleted with no recovery
Operating System
Windows 11
Terminal
Windows Terminal
Description
apply_patch writes files sequentially. When a patch touches multiple files and a later file fails (disk full, stale content, permission denied), earlier files stay modified on disk with no rollback. The workspace is left in an inconsistent state.
The tool description itself acknowledges the gap: "if a later operation fails, earlier operations remain applied." Both V1 (packages/opencode/src/tool/apply_patch.ts) and V2 (packages/core/src/tool/apply-patch.ts) have this behavior. A TODO in file-mutation.ts confirms it needs fixing.
Plugins
None
OpenCode version
dev branch (58ba99e)
Steps to reproduce
Operating System
Windows 11
Terminal
Windows Terminal