Client or integration
Codex App
Area
Provider adapter
Summary
After #1017 / #1144, Cursor edit_file / multi_edit convert into valid Codex apply_patch payloads. That grammar fix works.
The remaining defect is different: converted patches still fail hard at Codex apply time with:
apply_patch verification failed: Failed to find expected lines in …
Failed to find context '…'
especially when the worktree drifts mid-turn, whitespace does not match exactly, or old_string is non-unique.
Expected: once OpenCodex converts a structured edit into a valid patch, apply either succeeds or fails with actionable recovery diagnostics (nearest match / already-applied / refreshed old_string), instead of opaque exact-match rejection and retry storms.
nativeLocalExec: "on" does not bypass #1017 — writes still go through structured edit → apply_patch. Follow-up to closed #1017.
Reproduction
- Run OpenCodex
2.11.1 with the Cursor provider (nativeLocalExec on or off; both hit the same apply path for writes).
- Use Codex App on the Cursor route with
cursor/grok-4.5.
- In a multi-file agent turn, edit via
edit_file / multi_edit while the target can change between read and apply (dirty tree / previous partial edit / concurrent change).
- Observe OpenCodex emit a valid
*** Begin Patch payload, then Codex reject it locally with Failed to find expected lines / Failed to find context.
Minimal cases of the remaining gap (OpenCodex converter semantics + Codex-style exact matcher):
| Case |
Result |
Note |
| Happy path |
✅ |
converter + apply succeed |
| Stale context after drift |
❌ Failed to find expected lines |
file changed before apply |
| Whitespace mismatch |
❌ |
tabs/spaces must match exactly |
Ambiguous / non-unique old_string |
❌ |
must be unique |
Git-style @@ -n,m +n,m @@ |
❌ Failed to find context |
bare @@ only |
Missing *** Begin Patch |
❌ |
freeform envelope fragility |
multi_edit second depends on first |
❌ against ORIGINAL |
independent/original-file semantics |
| Converter ok, apply fails on drift |
❌ |
remaining gap after #1017 |
| Trailing-newline-only |
converter rejects |
intentional sharp edge |
| Indent-mangled but apply “succeeds” |
⚠️ |
exact match can succeed with wrong result |
Relevant code:
src/adapters/cursor/tool-definitions.ts
src/adapters/cursor/protobuf-events.ts (translateStructuredEditCall / replacementHunk)
src/adapters/cursor/native-exec-fs.ts
src/adapters/cursor/exec-policy.ts
Version
2.11.1
Operating system
NixOS 26.11 (Linux x86_64)
Provider and model
cursor / cursor/grok-4.5
Logs or error output
apply_patch verification failed: Failed to find expected lines in <file>:
editor = "nvim";
apply_patch verification failed: Failed to find context '-3,7 +3,7 @@' in <file>
apply_patch verification failed: invalid patch: The first line of the patch must be '*** Begin Patch'
Checks
Client or integration
Codex App
Area
Provider adapter
Summary
After #1017 / #1144, Cursor
edit_file/multi_editconvert into valid Codexapply_patchpayloads. That grammar fix works.The remaining defect is different: converted patches still fail hard at Codex apply time with:
apply_patch verification failed: Failed to find expected lines in …Failed to find context '…'especially when the worktree drifts mid-turn, whitespace does not match exactly, or
old_stringis non-unique.Expected: once OpenCodex converts a structured edit into a valid patch, apply either succeeds or fails with actionable recovery diagnostics (nearest match / already-applied / refreshed
old_string), instead of opaque exact-match rejection and retry storms.nativeLocalExec: "on"does not bypass #1017 — writes still go through structured edit →apply_patch. Follow-up to closed #1017.Reproduction
2.11.1with the Cursor provider (nativeLocalExecon or off; both hit the same apply path for writes).cursor/grok-4.5.edit_file/multi_editwhile the target can change between read and apply (dirty tree / previous partial edit / concurrent change).*** Begin Patchpayload, then Codex reject it locally withFailed to find expected lines/Failed to find context.Minimal cases of the remaining gap (OpenCodex converter semantics + Codex-style exact matcher):
Failed to find expected linesold_string@@ -n,m +n,m @@Failed to find context@@only*** Begin Patchmulti_editsecond depends on firstRelevant code:
src/adapters/cursor/tool-definitions.tssrc/adapters/cursor/protobuf-events.ts(translateStructuredEditCall/replacementHunk)src/adapters/cursor/native-exec-fs.tssrc/adapters/cursor/exec-policy.tsVersion
2.11.1Operating system
NixOS 26.11 (
Linux x86_64)Provider and model
cursor / cursor/grok-4.5Logs or error output
Checks