fix(opencode): skip end bounds check on empty backing file#752
Merged
backnotprop merged 1 commit intoMay 19, 2026
Merged
Conversation
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
Owner
|
thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #742.
validateEditsrejectsend > lineCounton first call when the backing file is empty (lineCount = 0). The plan-agent path in OpenCode includesendin the payload even when the agent omits it, so the firstsubmit_plancall fails withError: end (1) exceeds file length (0).applyEditsalready handles this correctly (splice clamps on an empty array), so the fix just skips the bounds check whenlineCount === 0. On an empty file every edit is a pure insert andendis meaningless.This is the clean fix for the #730 revert in 0.19.19.