Repository navigation
Studio tool output: strip ANSI in plain runs and find the tail without splitting the whole text - #16998
Conversation
…t splitting the whole text
…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.
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]
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
While a Python or terminal tool runs, every
tool_outputSSE event appends to the live output andToolLiveOutputPanerecomputestailToolOutput(stripAnsi(output))over the whole accumulated text (up to the 400k character backend cap).stripAnsiappended one character at a time, andtailToolOutputsplit 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 oneslice. 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 withlastIndexOfinstead ofsplit("\n")plusjoin, 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:stripAnsialone 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.stripAnsiand bothtailToolOutputfields are identical in every case and every engine.Tests
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.tspasses; full frontend suite 15,116 passed, 0 failed.