Skip to content

fix: keep terminal search from crashing the surface on narrow viewports - #6852

Merged
nwparker merged 1 commit into
mainfrom
nwparker/fix-terminal-search-decoration-crash
Jun 30, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/fix-terminal-search-decoration-crash

Conversation

@nwparker

@nwparker nwparker commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Crash channel report (Orca 1.4.104, macOS): react-error-boundary on the terminal surface.

  • boundary_id: terminal.workbench, surface: terminal-workbench
  • error: This API only accepts positive integers
  • deminified stack: _verifyPositiveIntegers ← registerDecoration ← _createResultDecorations ← createHighlightDecorations ← _highlightAllMatches ← SearchAddon.findNext ← TerminalSearch useEffect

Root cause

@xterm/addon-search builds each match-highlight decoration with a per-row width of:

amountThisRow = Math.min(terminal.cols - matchCol, remainingSize)

When the live viewport is narrower than the buffer column where a match starts — content laid out at a wider width before the pane reflowed, or a collapsed / 0-column viewport — cols - matchCol is negative, so the width is negative. xterm's registerDecoration → _verifyPositiveIntegers then throws synchronously inside findNext. Because TerminalSearch calls findNext from a React effect/handler, the throw trips RecoverableRenderErrorBoundary and kills the whole terminal surface.

There's no patch-package in this repo, so the fix is app-side.

Fix

Wrap the addon findNext/findPrevious calls in a small safeFind() helper that swallows only this specific decoration error (/only accepts positive integers/i). Match navigation happens before decoration creation inside the addon, so search stays fully functional — we just drop the highlight on that one pathological frame; the next find (after a reflow/fit widens the viewport) highlights normally. Any unrelated error still propagates.

Evidence of fix

terminal-search-safe-find.test.ts exercises the real safeFind helper (not ported logic):

✓ swallows the xterm "positive integers" decoration error instead of letting it crash the surface
✓ returns the addon result and forwards options on the normal path
✓ re-throws unrelated errors so genuine bugs are not hidden
 Test Files  1 passed (1)   Tests  3 passed (3)

Before the fix, a findNext that throws This API only accepts positive integers propagated out of TerminalSearch's effect into the boundary (the exact reported crash). After the fix it is contained and reported as "no match this frame".

ELI5

The terminal's "find" feature draws a colored box around each match. To draw the box it does box width = screen width − match position. If the window is skinnier than where the match sits, that subtraction goes negative, and the drawing library refuses negative sizes by throwing an error so loud it takes down the whole terminal. We now catch that one specific complaint: search still jumps to the match, we just skip painting the box on that frame instead of blowing up the terminal.

Trade-offs

  • On the rare frame where the viewport is too narrow to place a match's highlight, the highlight box is skipped for that frame. The match is still found/navigated, and highlighting resumes on the next find once the pane has reflowed. This is strictly better than crashing the terminal.
  • We match the error by message substring (only accepts positive integers) because xterm throws a plain Error with no code. If xterm reworded that message, the guard would stop catching it — acceptable for a defensive guard, and the unit test pins the current wording so a dependency bump that changes it is visible.

Scope / platforms

Renderer-only; platform-agnostic (applies to local, SSH, and remote terminals — all use the same xterm search addon).

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@brennanb2025, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 10 seconds

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 52d5d512-c7c6-4caf-b482-1735c0d7cfda

📥 Commits

Reviewing files that changed from the base of the PR and between e9b958a and f30b3e1.

📒 Files selected for processing (3)
  • src/renderer/src/components/TerminalSearch.tsx
  • src/renderer/src/components/terminal-search-safe-find.test.ts
  • src/renderer/src/components/terminal-search-safe-find.ts
📝 Walkthrough

Walkthrough

A new terminal-search-safe-find.ts module introduces a safeFind helper that wraps xterm SearchAddon find calls in a try/catch. When the caught error message matches /only accepts positive integers/i (a known xterm registerDecoration crash triggered by a negative decoration width), safeFind suppresses the error and returns false; all other errors are rethrown. TerminalSearch.tsx is updated to import and use safeFind in findNext, findPrevious, and the incremental-search useEffect. A Vitest suite in terminal-search-safe-find.test.ts covers the three behavioral paths.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is detailed but does not follow the required template and omits several required sections. Rewrite the description using the repo template and add the missing Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes sections.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: preventing terminal search crashes on narrow viewports.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/renderer/src/components/TerminalSearch.tsx (1)

53-67: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a short why-comment where safeFind is introduced in this component.

The crash-guard behavior is non-obvious at these call sites, and this file now depends on that rationale. A brief note near the first safeFind(...) use is enough.

As per coding guidelines, "When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does."

Suggested tweak
   const findNext = useCallback(() => {
     if (searchAddon && requestQuery) {
+      // Why: xterm can throw while creating search decorations on collapsed or
+      // narrow viewports; safeFind preserves navigation instead of crashing.
       safeFind(
         (term, options) => searchAddon.findNext(term, options),
         requestQuery,
         searchOptions()
       )

Also applies to: 89-93

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 50156696-e697-4c97-a882-0c7323622d4d

📥 Commits

Reviewing files that changed from the base of the PR and between 8e06ee1 and e9b958a.

📒 Files selected for processing (3)
  • src/renderer/src/components/TerminalSearch.tsx
  • src/renderer/src/components/terminal-search-safe-find.test.ts
  • src/renderer/src/components/terminal-search-safe-find.ts

@xterm/addon-search builds match-highlight decorations whose per-row width is
Math.min(terminal.cols - matchCol, remainingSize). When the live viewport is
narrower than the buffer column where a match begins — content laid out at a
wider width before the pane reflowed, or a collapsed/0-col viewport — that width
is negative, and xterm's registerDecoration -> _verifyPositiveIntegers throws
'This API only accepts positive integers' synchronously inside findNext. Thrown
from TerminalSearch's effect/handlers, it trips RecoverableRenderErrorBoundary
and kills the whole terminal surface (crash report 0b9ab636, Orca 1.4.104).

Wrap the addon find calls in safeFind(), which swallows that specific decoration
error. Match navigation runs before decoration creation, so search stays
functional and only the highlight on the pathological frame is dropped; the next
find after a reflow/fit highlights normally. Unrelated errors still propagate.

Adds terminal-search-safe-find.test.ts exercising the real helper.

Co-authored-by: Orca <[email protected]>
@brennanb2025
brennanb2025 force-pushed the nwparker/fix-terminal-search-decoration-crash branch from e9b958a to f30b3e1 Compare June 30, 2026 07:28
@nwparker
nwparker merged commit 1a7dae7 into main Jun 30, 2026
1 check passed
@nwparker
nwparker deleted the nwparker/fix-terminal-search-decoration-crash branch June 30, 2026 08:14
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 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