Repository navigation
Description
What happened?
Two malformed patches are accepted, and both are reported to the model as applied.
An update section with no @@ header. The parser only starts a chunk on a
line beginning @@, and any other line is skipped:
while (i < lines.length && !lines[i].startsWith("***")) {
if (lines[i].startsWith("@@")) { /* …make a chunk… */ } else { i++ }
}So
*** Begin Patch
*** Update File: a.py
- old
+ new
*** End Patch
parses to chunks: []. deriveNewContentsFromChunks then computes
replacements = [], and the "new" content is the file's own bytes. The
hunks.length === 0 guard does not catch it, because the *** Update File:
header already produced one hunk. The tool prints
Success. Updated the following files: M a.py with an empty diff.
A hunk line that lost its prefix. The change-line loop handles " ", "-"
and "+" and has no else, so a line with no leading space or sign — the most
common formatting slip in a model-authored patch — is dropped from both
old_lines and new_lines. That line is usually the only thing distinguishing
one block from another, and seekSequence then tries four progressively looser
passes (rstrip, both-end trim, punctuation folding) to find somewhere to apply
the hunk. What the model asked for in one function can land in another.
A note on scope: a line that is indented is a legitimate context line whose
first space is the prefix, and that is not fixable — no parser can tell
x from a lost-prefix x. That case is left alone deliberately. What is
fixed is the line with no prefix at all, which is unambiguously malformed.
Steps to reproduce
- Give
apply_patchan update section with no@@header (above). It reports
success and the file is unchanged. - Give it a hunk containing a line with no leading space or sign. The line is
dropped, and the hunk is matched with less context than the model supplied.
The regressions in test/tool/apply_patch.test.ts fail on 3e94875c and pass
with the fix.
How did you install OpenScience?
From source (bun dev).
OpenScience version
Source commit 3e94875c.
Provider and model
Not applicable; both defects are in how the patch is interpreted, before any
model call. The consequence lands in the model's next turn, which is why a false
success is the dangerous half here.
Operating system
Not OS-specific; reproduced in the Bun test harness.
Activity
fix(patch): a malformed patch is rejected instead of reported as appl…