Skip to content

perf(sandbox): collapse long runs of same-shaped output blocks - #477

Merged
mrnasil merged 1 commit into
mainfrom
perf/collapse-similar-blocks
Nov 25, 2026
Merged

mrnasil merged 1 commit into
mainfrom
perf/collapse-similar-blocks

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 25, 2026

Copy link
Copy Markdown
Member

What

clean_terminal_output gains a block pass after the per-line collapse (#461). Output is split into blank-line separated blocks; each block's shape is its layout with words and numbers erased (letter/digit/_ runs → x, whitespace → one space, a repeated mark → one mark, so ^^^^ under a name of any length matches). A run of 8 or more same-shaped blocks keeps:

  • the first block whole,
  • a note [N more blocks shaped like the one above; first 2 lines of each],
  • the first 2 lines of every other block — a rustc diagnostic's message and --> file:line, a failed test's name and where it panicked.

A block that breaks the shape (the error[E0308] after the warnings) ends the run and is kept whole. Blocks of ≤ 2 lines never collapse (nothing to drop). No word lists: shape only.

Why

The dev token workload's failed build prints 120 unused variable warnings, 5 lines each. The line-level collapse cannot see that repetition, so the whole 28.5 KB log (7,035 tokens) rode in every one of the next 6 requests.

Measured (scripts/bench_tokens.py --workload dev, o200k, release builds)

before after
build log tool result 7,035 2,914
session total input 245,364 212,548 (−13%)
uncached input 35,234 28,729 (−18%)

The "before" run predates #476 (glob grouping), so the totals include its ~3k as well; the build log row is this PR alone.

Trade-off

In a run of 8+ same-shaped blocks, lines after the second of each later block are dropped (for many failing tests with identical assertion layouts, the left/right values of all but the first). Every block's identity and location stays; the model can rerun one test for detail.

Tests

  • long_runs_of_same_shaped_blocks_keep_the_first_and_each_head: varying name lengths and line numbers still match; heads kept, bodies dropped; the breaking error block and the end of the output intact.
  • short_runs_and_short_blocks_are_not_collapsed: 7 blocks, and 2-line blocks, pass through unchanged.
  • sandbox clean.rs at 100% line coverage locally; fmt, clippy, budgets.

🤖 Generated with Claude Code

A build with many warnings prints the same multi-line diagnostic layout
around a different name each time; the per-line collapse cannot see
it. Command output is now also split into blank-line separated blocks,
each reduced to its layout (words and numbers erased, whitespace and
repeated marks folded). A run of 8 or more same-shaped blocks keeps the
first block whole and the first two lines of the others: a
diagnostic's message and `--> file:line`, a failed test's name and
where it panicked. A block that breaks the shape ends the run.

Dev token workload: the 120-warning build log goes from 7,035 to 2,914
o200k tokens with the final error intact.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mrnasil
mrnasil merged commit 9b42205 into main Nov 25, 2026
7 checks passed
@mrnasil
mrnasil deleted the perf/collapse-similar-blocks branch November 25, 2026 12:11
@mrnasil mrnasil mentioned this pull request Nov 26, 2026
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.

1 participant