Repository navigation
fix: truncate LLM-facing command output head+tail instead of head-only - #777
Conversation
execute-bash.tsx and custom-tools/handler.ts both truncated long output by keeping the first TRUNCATION_OUTPUT_LIMIT characters and discarding the rest. Compiler and test-runner output puts the actionable part at the end (tsc's error list, AVA's failure summary, most tools' exit digest), so head-only truncation throws away exactly what the model needs and forces an extra round-trip with a narrower command to recover it. Added a shared truncateHeadAndTail() helper (source/utils/truncate-output.ts) that keeps both ends within the same byte budget, tail-weighted (40/60 head/tail split) since that's where the actionable content usually is, with an elision marker showing how much was cut. Used it in both call sites. Left bash-progress.tsx's head-only estimate alone, since that one only feeds a display-only token-count stat, not the model. Fixes Nano-Collective#764
luisangelrod
left a comment
There was a problem hiding this comment.
Nice extraction and the tail-weighted split matches the failure-output use case well. One contract detail is worth clarifying before this helper is reused by the global-cap work in #769: limit currently limits only the retained source characters, not the returned string. For a 10,000-character input with limit = 2_000, the result is 2,052 characters after adding the marker.
That is consistent with the two old call sites (they also appended a marker beyond TRUNCATION_OUTPUT_LIMIT), so I do not see it as a blocker for this PR. But the generic helper name/signature makes a hard output ceiling easy to assume. I would either document that limit is the retained-content budget, or make the marker count toward the limit and add a result.length <= limit test. The latter would make this helper safe to reuse for #769 without quietly exceeding the configured cap.
I also traced both call sites and verified the 40/60 calculation directly. I could not complete the repository test command locally because the current checkout's frozen install reports a pre-existing patchedDependencies/lockfile configuration mismatch, so this feedback is based on the diff plus a direct execution of the helper logic rather than claiming a full suite run.
|
Nice work @MsfPablo :) |
Summary
Fixes #764.
execute-bash.tsxandcustom-tools/handler.tsboth truncated long output for the model by keeping only the firstTRUNCATION_OUTPUT_LIMIT(2000) characters. Compiler and test-runner output puts the actionable part at the end —tscprints its error list then the count, AVA prints passing output then the failure summary, most build tools print the exit digest last — so head-only truncation throws away exactly what the model needs from apnpm run test:typesorpnpm run test:avarun. It then has to re-run with a narrower command to recover information already in hand.Added a shared helper,
source/utils/truncate-output.ts, that keeps both the head and the tail within the same byte budget (40/60 split, tail-weighted since that's where the actionable content usually is), with a marker showing how many characters were elided in between. Used it at both LLM-facing call sites:formatBashResultForLLMinexecute-bash.tsxtruncate()incustom-tools/handler.tsLeft
bash-progress.tsx's head-only truncation alone — per the issue, that one only feeds a display-only token-count estimate for the live progress UI, not something the model sees.Test plan
pnpm run test:format,test:lint,test:types— all cleansource/utils/truncate-output.spec.ts— 5 tests covering the under/at/over-limit cases, that both head and tail are kept, and the 40/60 splitpnpm run test:ava source/tools/execute-bash.spec.tsx source/custom-tools/handler.spec.ts— 67 tests pass unmodified, including the existing truncation-length and truncation-marker assertions