Repository navigation
fix(tool): stop read from appending a phantom last line - #765
Merged
Ishaan Gangwani (ishaan1124) merged 1 commit intoSep 28, 2026
Conversation
ANIRUDDHA ADAK (aniruddhaadak80)
requested review from
Aayam Bansal (aayambansal) and
Ishaan Gangwani (ishaan1124)
as code owners
September 27, 2026 20:47
|
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. |
`finishLine` handles a partial final line, so a file ending in a newline had an empty one appended: every line number shifted, the total reported to the model was one too high, and the offset hint pointed one line past the end.
Ishaan Gangwani (ishaan1124)
force-pushed
the
fix/read-trailing-line-total
branch
from
September 28, 2026 05:11
d1cc2e4 to
f3bbca2
Compare
3 of 8 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?
readfinished the last line unconditionally at end of file:finishLineis the handler for a partial final line — one with no trailingnewline. When a file ends in a newline,
consumehas already flushed every lineand left
state.lineempty, sofinishLinestill runs: it increments the linecounter and pushes an empty string.
A two-line file is therefore reported as three lines. On
3e94875c:Three things the model sees, all wrong:
(End of file - total N lines)is one too high.00003|empty line is printed.lastReadLine = offset + raw.lengthfeeds the "Use 'offset' parameter to readbeyond line N" hint, so paging is off by one as well: a three-line file read
with
offset: 2returns00003| threeand a phantom00004|.Almost every source file ends in a newline, so this fires on essentially every
read. A file with no trailing newline is unaffected, which is why the existing
cases never caught it.
The fix only finishes a line when one is actually pending:
state.lineWideis included so a line that was cut atMAX_LINE_LENGTHstillgets its
...marker andlineNumberbump.Linked issue
Fixes #764
How did you verify it?
Two regressions added to
backend/cli/test/tool/read.test.ts, both driventhrough the real
ReadTool:a newline-terminated file reports the lines it has and no phantom last onecovers
"a\nb\n"(2 lines, no00003|),"only\n"(1 line, no00002|) and"a\nb"— the unterminated case still keeps its partial last line, so the fixis not "drop the last line".
offset paging agrees with the reported totalpins the interaction withpaging:
limit: 2thenoffset: 2ends at the real last line, andoffset: 3on a three-line file returns nothing while still reporting
total 3 lines.On unmodified
3e94875cboth fail:Commands run:
bun test --timeout 30000 ./test/tool/read.test.ts→ 36 pass, 1 failasks for external_directory permission when an internal symlink resolves outside the project, which I reproduced on unmodifiedmainwith my change stashed, so it is not from this diff.
bun run --cwd backend/cli typecheck→ exit 0The whole suite matters here rather than just the new cases: this change touches
line accounting for every read, and the existing truncation, offset, limit and
long-line cases all still pass.
Pre-existing reds on this Windows checkout, not from this diff:
bun run format:checkcannot pass here: git materializes the LF blobs as CRLF,so Prettier flags hundreds of untouched files, including
tsconfig.jsonandturbo.json. I verified all three changed files are formatted per the repoconfig with line endings normalized.
bun run typecheck: backend is clean;@synsci/workspacefails becausefrontend/workspace/src/custom-elements.d.tsis a symlink (mode120000) thatWindows checked out as a text file containing
../../ui/src/custom-elements.d.ts,which TypeScript then parses as source →
TS1128.Checklist
bun run checkis green (format, typecheck, backend + frontend/ui + SDK tests) — blocked on this Windows checkout by the CRLF and symlink artifacts described above; backend typecheck is clean and the full read suite is green apart from the pre-existing symlink case abovebun 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: theoffsetparameter is already documented as a line number, and this makes the reported numbers match itpackage.jsonversions and tags are written by the release workflow)installandfrontend/landing/public/installare still byte-identical if I touched either — not touched