anomalyco / anomalyco/opencode

apply_patch: `*** End of File` anchor is dead code and never anchors to the end

Open
#43,331 0 comments 0 reactions 1 assignee View on GitHub

@kitlangton is already working on this.

Since Aug 19, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Bug description

The *** End of File anchor in apply_patch updates is parsed but never takes effect: packages/opencode/src/patch/index.ts parseUpdateFileChunks guards the change-line loop with !lines[i].startsWith("***"), so the *** End of File line can never enter the loop body and is_end_of_file stays undefined forever. The tryMatch EOF branch (match from end of file first) therefore never runs, and EOF-anchored patches silently fall back to plain forward matching, editing the first occurrence of the pattern instead of the last.

The reference parser in packages/core/src/patch.ts implements the same marker correctly (loop only excludes @@; the EOF marker is checked inside the body, and other *** lines break the loop).

Reproduction

File eof_anchor.txt containing marker\nend\nmiddle\nmarker\nend (no trailing newline), patch:

*** Begin Patch
*** Update File: eof_anchor.txt
@@
-marker
-end
+marker-changed
+end
*** End of File
*** End Patch

Expected: last marker occurrence edited (marker\nend\nmiddle\nmarker-changed\nend). Actual: first occurrence edited.

Environment
  • OS: Windows
  • opencode version: dev branch

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.