Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(shared): command output failure scan rejects clean output in one pass #26935

Mergedhieu-lee(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/26935/headmerged by juliusmarminge View on GitHub

Problem

toolOutputIndicatesFailure ran six case-insensitive regex scans over every command output (up to 32 KB). It runs for each command item the server projects for the wire (thread open, replay, live events) and again in the client work-log presentation.

Fix

packages/shared/src/toolOutput.ts: one hint regex that is a superset of every failure needle gates the original checks, so outputs with no failure wording are scanned once. The <exited with exit code N> regex is dropped because the following exit(ed)? with exit code check already matches that text. Results are unchanged.

Measurements

2,004 real command outputs (14.5 MB) from a copy of a real database, median of 5 interleaved rounds, base origin/main vs this branch:

BaseNewRatio
toolOutputIndicatesFailure over all outputs60.4 ms25.9 ms2.33x
Heap growth632 KB68 KB-89%

For scale, on 4 real thread windows (1,305 items) the whole server wire projection goes ~8.2 ms to ~4.5 ms (1.8x); a full server-side thread open improves ~1.15x, so this is a targeted win rather than a thread-open win. What limits the new number: a single /i alternation costs about 1.2 ns/char against about 0.35 ns/char for one literal, which puts a floor near 1.8 ms on those 1.49 MB; six other gate shapes (single-pass tokenizer, lowercase + includes) were not faster.

Scope and approval

No triaged issue or maintainer-approved discussion exists for this; it is a focused, behaviour-preserving performance fix of one measured hot path (one problem, one PR, output identical to main as shown under Validation, no new setting, wire change or UI). Dedupe: I searched all open, merged and closed PRs by file and symbol and found none covering this function.

Validation

  • Old vs new compared on 4,928 real output strings (252 positives) plus 400k fuzzed strings with random casing and ſ, K, İ: 0 differences.
  • toolOutput.test.ts rows extended with hint-only negatives and a mixed-case positive.
  • vp run check:changed: format, lint, knip, typecheck, tests pass.
  • Related PRs touch other functions: #23351 (skips the scan when exitCode is set), merged #21146 (client reasoning rows). Searched all PR states by file and symbol; nothing else changes toolOutputIndicatesFailure.

Authored with Claude Sonnet 5.5 via the Claude Code harness in T3 Code.

🤖 Generated with Claude Code

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Approved at 1e5d6f4

      Macroscope's review found this PR approvable — Optimizes command-output failure detection by screening clean output in one pass while retaining the existing detailed checks. Its reach is limited to failure classification and presentation, with reported real-output and fuzz comparisons showing unchanged results.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      The tool output failure detector now checks for failure hints before applying specific patterns. The nonzero-exit pattern no longer requires a closing angle bracket. Tests cover mixed-case exit text and phrases that should not indicate failure.

      Changes: Tool output failure detection

      Layer / File(s)Summary
      Failure hint matching and tests
      packages/shared/src/toolOutput.ts, packages/shared/src/toolOutput.test.ts
      The detector checks for failure hints before applying specific patterns and relaxes the nonzero-exit pattern. Tests cover mixed-case exit text and incomplete phrases.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Refactor

      Suggested reviewers: maria-rcks, t3dotgg

      Merge Risk: Minimal · up to 4f630

      This is a targeted performance optimization of the tool output failure detector, with reported unchanged behavior and added tests. No actionable merge-blocking risk remains.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the main change: a performance fix that makes the command output failure scan run in one pass for clean output. It is a conventional commit title and matches the changed function toolO…
      Description checkPassedThe description follows the repository template. It has Problem, Change (Fix), Scope, and Verification content. The Problem section states the hot path and its cost. The Fix section explains the super…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Title check

      Explanation

      The title names the main change: a performance fix that makes the command output failure scan run in one pass for clean output. It is a conventional commit title and matches the changed function toolOutputIndicatesFailure. The title is short and specific, and it does not describe anything outside the changeset.

      Full details: Description check

      Explanation

      The description follows the repository template. It has Problem, Change (Fix), Scope, and Verification content. The Problem section states the hot path and its cost. The Fix section explains the superset hint regex and the dropped exit-code regex. Scope explains why no issue is linked and states the dedupe search. Verification lists equivalence checks, measurements, and the check command. It does not include UI screenshots, which the template requires only for UI changes. The description also states that the tracker issue is linked in the PR objectives, but the author text itself does not link an issue. This gap is minor because the author gives a reason for the missing issue. The PR also names the model and harness used, as the template asks.

      Finishing Touches

      Generate unit tests (beta)

      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 1e5d6f49e628a348b8fca69e580b58bcbd9881e7 and 4f6309ec266946bb6e42fa1d25f35319aac7a58b.

      Files selected for processing: 2

      • packages/shared/src/toolOutput.test.ts
      • packages/shared/src/toolOutput.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

    4. @maria-rcks ready for review. toolOutputIndicatesFailure ran six regex scans per command output; one superset hint now gates them. On 2,004 real outputs (14.5 MB) it is 2.33x faster with 89% less heap, and old and new agree on 4,928 real plus 400k fuzzed strings. End to end the server wire projection is about 1.8x and a whole thread open about 1.15x, so this is a targeted win. Related tracker: #9661. The CI workflows on this fork PR show action_required, so they are waiting on a maintainer to approve the run. CodeRabbit and Macroscope are done with no open findings (Macroscope approved).

    5. maria-rckscommented

      Note

      Written by gpt-6.1-sol on behalf of Maria

      Verified in a real dev environment

      Verified as-is at 1e5d6f49e628a348b8fca69e580b58bcbd9881e7, after reproducing the extra scanning on github/main (5ef56853ef). No code changes or pushes.

      Ran separate installs and background dev servers, one at a time, on Linux. Used repo Playwright with /usr/bin/google-chrome, a project/thread created through the app pointing at a real git worktree, and real Codex gpt-6.1-sol turns through the local proxy. No mocks, fixtures, or replay provider.

      Temporary runtime counting, forwarding regex calls unchanged, observed six scans on main and one on this head for the same 32,020-character clean command output during live server event projection. Removed instrumentation afterward. This verifies scan count, not an elapsed-time speedup.

      Both revisions produced the same results through server projection and client rows:

      • Large clean output, exit 0: clean.
      • file not found, exit 0: failure.
      • clean exit first, then ExIt CoDe: 3, exit 0: failure.
      • exit, not found, the path cannot be found, exit 0: clean.
      • Empty output, exit 7: failure.

      Expanded real command-output streams, then reloaded/reopened the thread. Outputs and failure flags remained correct. Fresh turns on this head also passed.

      Blacksmith passed 44 focused tests across shared output parsing, wire projection, and client presentation. vp run check:changed passed format, lint, both knip passes, typechecks for 31 packages, and its selected tests. Existing head CI: 30 successful, 0 pending, 0 failing.

      Command transcript

      main: real codex command output classifications

      pr: matching commands, expanded outputs and unchanged failure indicators

      pr: expand clean and failed command outputs through the real client

      Not verified

      Native desktop/iOS/Android, other providers, remote/relay/tunnel transports, and real Windows PowerShell execution were not exercised on this Linux VM. The existing 32,768-character boundary was not separately exercised. The PR's elapsed-time and heap ratios remain independently unverified; this pass proves the live scan reduction and preserved behavior.

    6. @juliusmarminge could you review this when you have a moment?

      Written by Claude Sonnet 5.5 via Claude Code in T3 Code.

    7. Evidence

      Steps on both commits: create fresh synthetic replay histories containing 24 clean 32 KB command outputs without exit codes, 14 failure-pattern samples, six near misses, explicit exit-code controls, and three other-tool outputs. Reopen each thread, expand its work log, load output, and scroll long groups.

      Environment: real isolated servers and Chromium 156 web clients, Linux, 1280×800, light theme. Stills were retained after identical PNGs 500 ms apart.

      Observed: matching rendering and command classifications. Clean outputs and near misses stay clean; all 14 failure samples stay failed; explicit exit codes retain precedence. No behavior difference was observed.

      ViewBefore — 7bc36845f6After — 4f6309ec26
      Clean command historyBefore: clean commandsAfter: clean commands
      Failure patterns, first rowsBefore: failure patternsAfter: failure patterns
      Remaining failure patternsBefore: remaining failuresAfter: remaining failures
      Near missesBefore: near missesAfter: near misses
      Explicit exit-code precedenceBefore: explicit exit codesAfter: explicit exit codes
      Other-tool outputBefore: other-tool outputAfter: other-tool output
      Scripted interactionBefore recordingAfter recording

      Scenario and synthetic replay seed.

      This is evidence of behavior preservation on the covered paths. CPU scan counts and timing were not measured.

      Not shown:

      • Server CPU profiles, browser CPU profiles, scan counts, and repeated timing measurements were not captured; no performance magnitude is claimed.
      • Native mobile clients and the Electron shell were not run; evidence covers the real server and web client paths through the shared helper.
    8. juliusmarminge merged thisbb9658d

    9. juliusmarminge closed this

Sign in to join this conversation.