Skip to content

fix(opencode): skip end bounds check on empty backing file#752

Merged
backnotprop merged 1 commit into
backnotprop:mainfrom
rcdailey:fix/submit-plan-empty-file-validation
May 19, 2026
Merged

fix(opencode): skip end bounds check on empty backing file#752
backnotprop merged 1 commit into
backnotprop:mainfrom
rcdailey:fix/submit-plan-empty-file-validation

Conversation

@rcdailey
Copy link
Copy Markdown
Contributor

Fixes #742.

validateEdits rejects end > lineCount on first call when the backing file is empty (lineCount = 0). The plan-agent path in OpenCode includes end in the payload even when the agent omits it, so the first submit_plan call fails with Error: end (1) exceeds file length (0).

applyEdits already handles this correctly (splice clamps on an empty array), so the fix just skips the bounds check when lineCount === 0. On an empty file every edit is a pure insert and end is meaningless.

This is the clean fix for the #730 revert in 0.19.19.

When a file has no content (lineCount === 0), any edit is a pure insert
and the end field is semantically irrelevant. The previous check
rejected payloads where end was present on an empty file because end >
lineCount always evaluated true, breaking first-call submit_plan
invocations from agents or frameworks that include end unconditionally.

- Skip end > lineCount validation when lineCount === 0; applyEdits
  handles it via splice clamping
- Add applyEdits test: edit on empty file with start=1, end=1 produces
  correct output
- Add validateEdits test: passes for empty file with start=1 and end=1

Fixes backnotprop#742
@backnotprop
Copy link
Copy Markdown
Owner

thanks!

@backnotprop backnotprop merged commit b3f1deb into backnotprop:main May 19, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

submit_plan fails in plan-agent mode from Opencode after 0.19.18

2 participants