Skip to content

Studio tool output: strip ANSI in plain runs and find the tail without splitting the whole text - #16998

Merged
danielhanchen merged 3 commits into
mainfrom
perf/r29-tool-output-strip
Nov 8, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
perf/r29-tool-output-strip

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

While a Python or terminal tool runs, every tool_output SSE event appends to the live output and ToolLiveOutputPane recomputes tailToolOutput(stripAnsi(output)) over the whole accumulated text (up to the 400k character backend cap). stripAnsi appended one character at a time, and tailToolOutput split the whole text on newlines to keep the last 2,000 lines. So every event cost O(total output) on the main thread, and a chatty tool (pip installs, training logs, progress bars) made the chat UI janky.

Change

  • stripAnsi: same scanner and the same control paths; only the plain-character branch now copies the whole run of plain characters with one slice. Short runs are found with a hand scan, and runs longer than 32 characters fall through to a regex over the bytes the scanner acts on (CAN, SUB, ESC and the C1 range). A regex call at every loop step made escape-dense output about 2.8x slower than main, so the regex is only used where it pays.
  • tailToolOutput: finds the 2,000th newline from the end with lastIndexOf instead of split("\n") plus join, and counts the hidden lines the same way. The 200k character cap is unchanged.

Results

tailToolOutput(stripAnsi(text)) on 400k characters, ms per event, median of 12 interleaved rounds, with a second copy of main as an A/A noise control:

Engine Input main main (A/A) this branch
Chromium plain log lines 7.55 6.60 0.54
Chromium colour on every line 5.95 6.40 2.96
Chromium colour per word 3.34 3.33 3.04
Chromium colour per character 3.09 3.13 3.31
Firefox plain log lines 19.80 19.10 0.80
Firefox colour on every line 12.80 12.90 5.40
Firefox colour per word 7.20 7.00 6.60
Firefox colour per character 5.10 4.90 5.50
WebKit plain log lines 9.00 9.10 0.70
WebKit colour on every line 6.40 6.00 1.90
WebKit colour per word 2.80 2.80 2.20
WebKit colour per character 1.50 1.50 1.60

stripAnsi alone on a 400k tqdm progress bar (node 24): 10.65 ms to 0.32 ms. The only shape that does not gain is one plain character between escape codes, which stays within about 7% of main.

Parity

Differential fuzz against main's functions, run in node, Chromium, Firefox and WebKit: 362,168 inputs per engine (every UTF-16 code unit alone, inside plain text, after ESC and after C1 CSI; random mixes of ESC / CSI / OSC / DCS / C1 / CAN / SUB / BEL / \^E / surrogate pairs / newlines / runs of 31 and 33 plain characters; 0, 1, 1,999 to 2,001 and 4,000 lines with leading and trailing newlines), plus a separate 300,167-case node run. stripAnsi and both tailToolOutput fields are identical in every case and every engine.

Tests

  • New tests/strip-ansi-runs.test.ts: fuzz (20,000 inputs) and the line-boundary cases against the previous implementation kept in the test as an oracle.
  • tests/strip-ansi.test.ts passes; full frontend suite 15,116 passed, 0 failed.

danielhanchen added a commit that referenced this pull request Nov 7, 2026
…se (#17012)

## Summary

After #16978 lowered the long-chat gate's Glass ceilings to 7x for most
areas and 12-15x for scrolling Settings, the "Browser gate for long-chat
typing cost" step started failing on PRs that do not change what it
measures. For example, on #16998 (one TS file):

```
FAIL: appearance mode blurred makes area api_monitor cost 539 ms CPU against 75 in the default appearance at 40 turns = 7.2x (limit 7.0x ...)
FAIL: appearance mode liquid-3d makes area reasoning_toggle cost 576 ms CPU against 74 in the default appearance at 40 turns = 7.8x (limit 7.0x ...)
```

The same commit passed on rerun. #17003 has since put the ceilings back
to 10x and 18x, which fixes the red runs. This PR adds the guard, so the
ceilings cannot be tightened back into runner noise, or loosened until
they stop catching anything, without a test saying so.

The numbers come from the gate's own ratio table, which I parsed from 25
runs today on GitHub runners (ubuntu-24.04 and ubuntu-26.04):

| | spread on identical code (same PR, repeated runs) | highest reading
|
|---|---|---|
| Glass modes, other areas | 6.2x to 8.3x | 8.3x |
| Glass modes, Settings scrolling | 9.3x to 13.8x | 14.0x |

## Change

`tests/studio/test_area_matrix.py`:
`test_shipped_ceilings_clear_runner_noise_but_not_a_real_regression`
takes the highest runner reading for blurred thread scrolling (8.3x),
liquid-3d reasoning toggle (7.8x), blurred Settings scrolling (14.0x)
and frosted Settings scrolling (13.5x). It feeds each one through
`judge()` with the shipped `KNOWN_DEFAULT`. Each reading must pass, and
1.5x each reading must fail. No product or gate code changes.

## Testing

| `_area_matrix.py` ceilings | new test |
|---|---|
| main (10x / 18x, from #17003) | 4 passed |
| #16978's (7x / 12-15x) | 3 failed: 8.3x, 7.8x and frosted 13.5x read
as regressions |
| pre-#16978 Settings value, 28x | 2 failed: 1.5x the worst Settings
reading, about 21x, passes |

`test_area_matrix.py` in full: 32 passed.
@danielhanchen danielhanchen self-assigned this Nov 8, 2026
Running the regex at every loop step made escape-dense output (colour per
character) about 2.8x slower than main. Keep main's control flow, widen
only the plain-char branch into a run copy: a short hand scan, the regex
only for runs past 32 chars.

[skip ci]
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-08T16:10:38.059181Z
We couldn’t complete this review. Comment @codex review to try again.
951076b Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 32f7ef4d53

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 951076bda3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen marked this pull request as ready for review November 8, 2026 16:10
@danielhanchen
danielhanchen merged commit 297a50c into main Nov 8, 2026
@danielhanchen
danielhanchen deleted the perf/r29-tool-output-strip branch November 8, 2026 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant