Repository navigation
fix(patch): insert an added-only hunk where its header says - #779
Merged
Ishaan Gangwani (ishaan1124) merged 1 commit intoSep 29, 2026
Conversation
ANIRUDDHA ADAK (aniruddhaadak80)
requested review from
Aayam Bansal (aayambansal) and
Ishaan Gangwani (ishaan1124)
as code owners
September 28, 2026 07:53
|
ANIRUDDHA ADAK (@aniruddhaadak80) is attempting to deploy a commit to the InkVell Team on Vercel. A member of the Team first needs to authorize it. |
Ishaan Gangwani (ishaan1124)
force-pushed
the
fix/patch-insert-hunk-anchor
branch
from
September 29, 2026 01:24
05a5ee0 to
07ec6bc
Compare
3 of 8 tasks
computeReplacements resolved the @@ header into a line index and then ignored it for a hunk with no old lines, so the line was appended after the last line of the file rather than after the block the model named. Use the resolved index, and keep end-of-file for a hunk with no header.
Ishaan Gangwani (ishaan1124)
force-pushed
the
fix/patch-insert-hunk-anchor
branch
from
September 29, 2026 01:31
07ec6bc to
7786860
Compare
6 of 7 tasks
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.
What does this PR do, and why?
computeReplacementsresolves the@@header into a line index and then throwsit away for a hunk that only adds lines:
So
@@ def main():followed by only+lines puts the line at end of file, notafter the function it named.
The failure mode is quiet rather than loud, which is what makes it worth fixing.
In Python, YAML or LaTeX a misplaced statement is usually not a syntax error:
a line relocates from inside a function to module scope, or a YAML key lands
under the wrong parent, and the file keeps working while doing something else.
The tool reports
Success. Updated the following files: M m.py.The fix uses the position the header already resolved, keeping end-of-file as the
fallback for a hunk with no header:
Linked issue
Addresses the same class as #775 (a patch that is not what it appears to be),
filed there. This hunk header is resolved — it is just ignored on this one path,
so there is no separate report to link.
How did you verify it?
Two cases in
backend/cli/test/tool/apply_patch.test.ts:an insert-only hunk lands after the context it names, not at end of file—drives the real tool on a file with
main()andcleanup(); on3e94875ctheline lands after the top-level
main()callan insert-only hunk with no context still appends— the fallback is unchanged,so this is the guard that the fix is not "always insert at the anchor"
On unmodified
3e94875cthe first fails with the line in the wrong place; thesecond passes on both.
Commands run:
bun test --timeout 180000 ./test/tool/apply_patch.test.ts→ 40 pass, 0 failbun run --cwd backend/cli typecheck→ exit 0Two notes on how I ran that suite, because the numbers are worth trusting:
full run used the default 30 s per-test timeout and reported 3 failures — all
three at exactly 30 s. Re-run individually they pass in 14 s, 25 s and 16 s,
and the whole file is green at a realistic timeout, so those were load-induced
timeouts, not failures. I am reporting this rather than quietly quoting a green
number, because a reader running the default timeout will see reds.
inserts lines with insert-only hunkcase carries contextlines, so
old_lines.length > 0and it never reached the branch I changed. Thatis exactly why the bug survived, and it is why the new test omits context lines.
Relationship to #776
Disjoint hunks in the same file. #776 changes the change-line parser (rejecting an
unprefixed line) and adds a guard in
apply_patch.ts; this changes only thepure-addition branch in
computeReplacements. Neither conflicts with the other,and both are in the same test file at different locations.
Checklist
bun run checkis green (format, typecheck, backend + frontend/ui + SDK tests) — blocked on this Windows checkout by the CRLF and symlink artifacts in my other pull requests; backend typecheck is clean and the full apply_patch suite is green at a realistic timeoutbun run --cwd frontend/workspace buildsucceeds if I touchedfrontend/workspaceorfrontend/ui— not touched./tooling/repo/generate.tswas run and thetooling/sdkoutput committed if I changedbackend/cli/src/server— not touchedfrontend/docs/src/content/openscience/is updated if behavior changed — no doc change needed: the@@header is already documented as naming the change contextpackage.jsonversions and tags are written by the release workflow)installandfrontend/landing/public/installare still byte-identical if I touched either — not touched