Repository navigation
perf(terminal): skip kitty scans for plain PTY output - #21643
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthrough
Priority: ➖ Normal Severity of issue fixed: Medium 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Out of Scope Changes checkExplanation The changes in
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Fast-path guard in
scanInternal—TerminalKittyKeyboardModeTracker.scanInternal()now returns immediately whenscanTailis empty and the chunk contains neither ESC (\x1b) nor C1 CSI (\x9b), skippingextractScanTailand the kitty-mode regex for plain output. Escape-bearing chunks,scanReplay, and pending split sequences keep the unchanged parser path. - Plain-output state test — asserts that a plain chunk arriving after
\x1b[>1uleaves bothflagsandsnapshotFlagsat1.
The guard is sound: every alternative in kittyModeRe begins with \x1b or \x9b, so no matchable sequence can be skipped, and with an empty scanTail the parser path was already a no-op for plain data. It mirrors the identical pre-filter in src/main/daemon/terminal-shell-lifecycle-scanner.ts:97. The new test pins the invariant rather than the fast path (it would pass without the guard); the benchmark in the PR body is the performance oracle, which is reasonable for a shared-parser fast path with no CI latency gate.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
The new escape-byte fast path dereferences the chunk before the string concatenation that used to coerce a nullish value, so an unchecked caller now throws instead of no-opping. Normalize once at the top. Also type the AgentTerminalPreview connect mock against the real preload signature, which turns the stale bare-string replay fixture that tripped this into a compile error.
3ff9ac8 to
5be3013
Compare
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Nullish-chunk regression fixed —
scanInternal()normalizes a non-stringdatato''before the escape-byte fast path, restoring totality for unchecked main-process callers;scan()andscanReplay()both funnel through it. - Regression test added — a new test drives
scan()andscanReplay()with an absent chunk, asserting neither throws and negotiated flags survive; it fails against the guard as first committed (data.includes(...)). AgentTerminalPreviewconnect mock typed — the mock is now typed againstTerminalPreviewApi['connect'], which turned the stale bare-stringreplayfixture into a compile error; it is corrected to{ data, mode: 'replay' }, matchingTerminalPreviewReplayChunk[]. That invalid fixture was the runtime path that fedundefinedinto the tracker.
The fast-path guard remains sound — every alternative in kittyModeRe starts with \x1b or \x9b, so nothing matchable is skipped — and the fix covers every caller at the shared boundary rather than one @ts-nocheck site. Verified locally: focused tracker/preview suites (53 tests) and pnpm tc:web pass.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
The kitty keyboard tracker is a small referee that watches terminal output for special keyboard messages. Before this change, it reopened its rulebook for every ordinary shell-output chunk, even when the chunk contained no escape marker. The tracker now checks for those markers first and skips the expensive parser when there is nothing to inspect. Special messages and split messages still use the existing parser.
What Changed
Every PTY output chunk still reaches
TerminalKittyKeyboardModeTracker.scan(), butscanInternal()returns immediately when there is no pending partial sequence and the chunk contains neither ESC (\\x1b) nor C1 CSI (\\x9b). Escape-bearing chunks, replay scans, and pending split sequences follow the unchanged parser path. A focused test records that ordinary output leaves negotiated flags and their snapshot provenance unchanged.The guard replaced a string concatenation (
this.scanTail + data) that used to coerce a nullish chunk to a harmless string, soscanInternal()now normalizes the chunk once at the top and both the guard and the concatenation use it. That keeps the function total: two unchecked main-process call sites reach this tracker —orca-runtime-capture-provider-terminal-buffer.ts(scanReplay(snapshot.data)) andorca-runtime-on-pty-data.ts(.scan(data)on every PTY data event) — and both files are@ts-nocheck, so the declared non-optionaldata: stringis not enforced at either.The
AgentTerminalPreviewconnect mock is now typed against the real preload signature, which turns a stale bare-string replay fixture into a compile error rather than a runtime throw.For users, terminal output with no kitty protocol traffic spends much less renderer CPU in this bookkeeping path. Kitty keyboard negotiation, dense SGR output, ACK accounting, output ordering, snapshots, replay, and remote projection retain their existing behavior.
Why
The output path calls this tracker once per PTY chunk. A warmed Node 24 benchmark on macOS measured 100,000 scans:
The guard is the smallest safe boundary because it does not alter the protocol parser or retain ordinary output. Checking the pending tail is required so a sequence split across PTY chunks is still completed.
Linked Issue
Fixes #21642
Visual Proof
N/A — this is a shared parser fast path with no visual or interaction layout change.
Testing
Automated tests added/updated, or explained why not below
I manually tested these changes locally
pnpm test src/shared/terminal-kitty-keyboard-mode-tracker.test.ts src/shared/terminal-kitty-keyboard-tail-retention.test.ts— 30 tests passed.pnpm test src/renderer/src/components/dashboard-popout/AgentTerminalPreview.test.tsx— 23 tests passed.pnpm tcpassed.pnpm run check:code-quality:changedpassed.Oxlint, Oxfmt, and
git diff --checkpassed.Benchmark compares the current tracker with the exact
origin/mainimplementation using warmed Node 24 calls; dense SGR remains on the parser path.Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
The change is platform-neutral string parsing. It preserves remote/SSH output ordering and snapshot/replay entry points because only the no-marker path returns early.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Full
pnpm lint, the complete test suite, and packaging are left to CI; the focused gates above passed locally.