Repository navigation
perf(process): stop padding rendered terminal lines to full width - #1450
Conversation
Rendered frames padded every visible row with trailing spaces to the terminal width. Blank rows cost a full row each and every frame repeats them, so the padding made up 14-39% of capture Evidence (2 KB of sparse output produced 228 KB). The padding carried no information: columns is recorded and serialized_state keeps the exact terminal state. Lines are now trimmed after normalization, so line.padEnd(columns) restores the previous value. The comparison contract commits rendered_line_format so older padded captures do not compare as the same contract. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
TL;DR: This is a post-merge check. I tested the PR head, and the merged commit has the same patch. I ran real Linux captures on the old and new code. The new captures are smaller, and old vs new captures are refused cleanly. No visible text is lost. But padding a line back to Size (same PTY chunks,
|
| Capture | Cols | Base | Head | Saved |
|---|---|---|---|---|
echo hello |
80 | 2,147 | 232 | 89% |
vim -R file, then :q! |
80 | 6,754 | 1,161 | 83% |
| 60 short lines | 80 | 147,556 | 40,038 | 73% |
colored bash lines |
80 | 5,402 | 1,838 | 64% |
less -R file, space, q |
80 | 8,635 | 3,967 | 54% |
ls --color=always -la /usr/bin | head -200 |
200 | 64,513 | 51,163 | 20% |
same ls |
80 | 54,386 | 52,286 | 4% |
top -b -n 1 |
80 | 510,763 | 507,592 | 1% |
At 80 columns, ls -la wraps, so its rows are already full. Wall time did not change beyond noise. The limits.output_bytes claim holds. With a 20,000 byte budget, the 60-line run kept 10 of 60 frames on base. Head kept 54 of 60.
Does head line + padEnd(columns) equal the base line?
| Case | Equal? |
|---|---|
| Plain, colored, blank and wrapped rows | yes |
| Real trailing spaces the program printed | yes |
| Tab, NBSP, U+3000 at the end | yes (kept, not trimmed) |
| Wide CJK at the right edge | yes |
Row exactly columns wide |
yes |
Red background spaces (\e[41m ) |
yes |
\e[K with blue background, cursor jump past text |
yes |
Combining marks (e + U+0301) |
no |
| Emoji with U+FE0F, ZWJ family | no |
Own pid (echo pid $$) |
no |
Port in localhost:8080 |
no |
A patterns entry that changes length |
no |
Every miss is trailing spaces only. The trimmed text matches. serialized_state matched base byte for byte in every frame. Colored spaces stay in serialized_state.
Here is why it misses. Base pads first, then normalizes. So a 7-digit pid becomes <pid>, and that base row is 38 units at 40 columns. Head pads pid <pid> back to 40. Combining marks go the other way. padEnd counts UTF-16 units, not cells. So that base row is 50 units at 40 columns. Head pads it to 40. top -b -n 1 hits the pid case when its own row is on screen.
A small follow-up could make the docs line say "up to trailing spaces". Your call.
Contract
Old vs new is refused both ways. Both builds name the field: these scenario fields differ: rendered_line_format. Pairs from one build still compare. Terminal shows unchanged. One small nit: the message says to capture both scenarios with the same values. This field is not in the scenario. The fix is to capture the old side again with the new REA.
Tests
| Check | Node 22.23.1 | Node 24.18.0 | Node 26.11.1 |
|---|---|---|---|
| PR test files on head | 5 pass | 5 pass | 5 pass |
| PR test files on base | not run | 2 fail, 3 pass | not run |
tests/boundary/process + src/process on head |
not run | 298 pass, 7 skip | not run |
src/domain/process + toolResult on head |
not run | 32 pass | not run |
On base, the two new checks fail as they should. The test "trims only after normalization sees the full-width row" passes on base too. So it guards the order, not the trim.
Not run
- PR test files on base with Node 22 and 26
- Process suites on Node 22 and 26
localToolContracts,check:changed,typecheck,docs:check- macOS and Windows
htopand other full-screen apps besideslessandvim- The MCP capture ran only for
echoandless
Thanks kaoru0822-kitauji for a tidy PR and a clear contract bump.
How I measured
- Base is the PR parent
33b9b31a. It is notgh's base ref.mainhad already moved on. - Each scenario ran three times per build through
rea capture-process --json. I usedenv -i, a fakeHOMEand a shortTMPDIR. - PTY chunking changes run to run, so frame counts differ between real runs. For a fair size test, I fed the same raw chunks into both builds'
TerminalRenderer. I used the realnormalizeProcessTextand the recovered pid. The table shows the median of six chunk sets. - The equality check used that same replay. It compared every row of every frame.
- For the base test row, I copied the two head test files into the base tree.
- Over stdio MCP,
echostructured content went from 8,101 to 6,234 bytes. The text block carries the same Evidence, so the whole response went from 16,924 to 13,194.
Edge cases
printf 'trail \r\n'
printf 'a\tb\t\r\n'
printf 'nbsp \r\n'
printf 'ideo \r\n'
printf '%*s漢\r\n' 38 'cjk-edge'
printf 'éééééééééé\r\n'
printf '❤️ ❤️ \U0001F468\U0001F469\U0001F467\r\n'
printf 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n'
printf '\e[41m \e[0m\r\n'
printf '\e[44mbg-erase\e[K\e[0m\r\n'
printf 'pid %s\r\n' "$$"
printf 'url localhost:8080\r\n'
printf '\e[14;30Hfar'Base vs head row lengths in UTF-16 units, 40 columns:
| Row | Base | Head + padEnd |
|---|---|---|
éééééééééé |
50 | 40 |
❤️ ❤️ 👨👩👧 |
47 | 40 |
pid <pid> |
38 | 40 |
url localhost:<port> |
42 | 40 |
short → much-longer-replacement |
58 | 40 |
LONGTOKEN y → x y |
32 | 40 |
Test setup
- Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
- CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
- RAM: 32 GB DDR4-3600
- Node: 22.23.1, 24.18.0, 26.11.1
- Head / base:
3b1bee87/33b9b31a - Merged as
2781cad2, same patch as the head - Programs:
lsfrom GNU coreutils 9.10 (GPL-3.0-or-later)- The
toptool from procps-ng 4.0.6 (GPL-2.0-or-later) - GNU bash 5.3.9 (GPL-3.0-or-later)
- less 704 (GPL-3.0-only OR BSD-2-Clause)
- Vim 9.2 (Vim license)
🤖 Generated with Claude Code (Opus 5.5) 🦊
…rluto#1450) Rendered frames padded every visible row with trailing spaces to the terminal width. Blank rows cost a full row each and every frame repeats them, so the padding made up 14-39% of capture Evidence (2 KB of sparse output produced 228 KB). The padding carried no information: columns is recorded and serialized_state keeps the exact terminal state. Lines are now trimmed after normalization, so line.padEnd(columns) restores the previous value. The comparison contract commits rendered_line_format so older padded captures do not compare as the same contract.
Summary
Process capture padded every visible terminal row with trailing spaces to the terminal width (
TerminalRendererusedpadEnd(columns)). Each rendered frame repeats all rows, so blank and short rows cost a full row in every frame. The padding carried no information: each frame recordscolumns, andserialized_statekeeps the exact terminal state.linesare now trimmed of trailing U+0020 after normalization.line.padEnd(frame.columns)restores the previous value exactly, so nothing is lost.rendered_line_format: "trailing-spaces-trimmed-v1". This follows theport_normalization_versionprecedent: comparing a capture with padded lines against a new capture reports an incompatible contract that names this field, instead of reporting terminal changes that are only whitespace.rendered_terminalbyte accounting counts the trimmed lines, solimits.output_bytesretains more frames before truncating.docs/process-capture.mddocuments the line format.No field was removed, and text/structured results are unchanged (#723).
Measurements
Real
capture_process_scenariocalls through stdio MCP on macOS arm64, comparing wholestructuredContentbytes. "Before" means the same capture with its lines padded back to full width.git log --oneline -15echo hellols -la /ApplicationsMCP results carry the Evidence in both text and structured content, so a call saves twice these bytes.
Verification
src/process/capture/TerminalRenderer.test.tscovers trimmed rows, preserved blank rows and inner spacing,padEnd(columns)restoration, byte accounting, and normalization still seeing the full-width row.tests/boundary/process/processCaptureNormalization.test.tspins the committed contract field.npm run test:focused --all oftests/boundary/process/*,src/domain/process/*,src/process/**,tests/boundary/mcp/toolResult.test.ts,src/application/ReconstructionObligationCandidates.test.ts: 52 files, 336 passed, 3 skipped (Linux-only).tests/acceptance/tools/localToolContracts.test.tspassed.npm run check:changed,npm run typecheckandnpm run docs:checkpass.Refs #723, #1065.
🤖 Generated with Claude Code