Skip to content

fix(tool): do not count a trailing newline as a truncated line - #789

Merged
Ishaan Gangwani (ishaan1124) merged 2 commits into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/truncate-phantom-line-count
Sep 29, 2026
Merged

Ishaan Gangwani (ishaan1124) merged 2 commits into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/truncate-phantom-line-count

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Contributor

What

Truncate.output counted a phantom line for any output ending in a newline, so the "...N lines truncated..." figure it shows the model was one too high and the preview carried a blank entry.

Why it matters

That count is how the model judges how much of an output it is missing, printed right under "The tool call succeeded but the output was truncated." Almost every CLI and log file ends in a newline, so this was the common case, not an edge case.

The byte path is unaffected, and the full output written to disk is byte-identical — only the count and the trailing blank preview line change.

Verification

Fails before, passes after:

Expected to contain: "...90 lines truncated..."
Received:            "line0\n...\nline9\n\n...91 lines truncated..."

The new test is the existing truncates by line count case plus a trailing newline, so the two together pin both shapes:

(pass) truncates by line count [2.74ms]
(pass) counts a trailing newline as no line of its own [7.86ms]
 14 pass
 0 fail

All 13 pre-existing tests in the file still pass, including the byte-limit, tail-direction, and saved-output cases.

The change

     const direction = options.direction ?? "head"
-    const lines = text.split("\n")
+    // A trailing newline makes split yield a phantom final element, which
+    // would be kept as an empty preview line and reported as a removed one.
+    const lines = text.endsWith("\n") ? text.slice(0, -1).split("\n") : text.split("\n")

bun run typecheck clean; touched files are Prettier-clean (checked on LF-normalized copies — this Windows checkout has core.autocrlf=true, which makes Prettier flag every file in the repo).

Fixes #788

@vercel

vercel Bot commented Sep 28, 2026

Copy link
Copy Markdown

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.

split(\n) yields a phantom final element for text that ends in a newline, so the preview kept an empty entry and the count included a line that was never removed. A 100-line file truncated to 10 announced 91 lines removed. Drop the trailing newline before splitting.
@ishaan1124
Ishaan Gangwani (ishaan1124) merged commit 5514c8d into synthetic-sciences:main Sep 29, 2026
8 of 9 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.

Truncate reports one more truncated line than it removed when the output ends in a newline

2 participants