Skip to content

Normalize invalid terminal line height before xterm - #8050

Merged
nwparker merged 1 commit into
mainfrom
nwparker/crashes-4
Jul 10, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/crashes-4

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Description

Fixes crash reports ebfaa501-de3f-4dea-a118-53939a4b531a and e5f85f81-1bc4-4003-85e7-f9016ce1459b.

Both reports contain the same xterm exception: lineHeight cannot be less than 1, value: 0.85. The Settings control already clamps new input to [1, 3], but legacy/user-edited persisted state and renderer IPC updates bypassed that clamp. A stored 0.85 therefore reached both the terminal workbench and Settings preview and escaped through their React error boundaries.

This PR adds one shared line-height normalizer, repairs invalid persisted values on load, normalizes renderer IPC updates before persistence, and defensively normalizes both xterm construction/mutation paths.

Clear, undeniable fix evidence

Before (exact live reproduction)

Using an isolated Orca dev profile on current main:

  1. Persist terminalLineHeight=0.85.
  2. Open Settings → Appearance.
  3. Observe two console errors from TerminalSettingsPreview:
    Error: lineHeight cannot be less than 1, value: 0.85.

The regression test was then added before the fix and failed:

expected 0.85 to be 1
- Expected: 1
+ Received: 0.85
TerminalSettingsPreview.lifecycle.test.tsx:231

After (same corrupted value)

With the renderer store deliberately left at terminalLineHeight=0.85:

  • Settings → Appearance: xtermSurfaces=1, Appearance heading visible, 0 console errors.
  • Terminal workbench: xtermSurfaces=1, terminal surface visible, 0 console errors.
  • Persistence reload rewrites 0.85 to 1.
  • settings:set({ terminalLineHeight: 0.85 }) persists 1.

Automated evidence:

  • pnpm exec vitest run --config config/vitest.config.ts src/shared/terminal-line-height-settings.test.ts src/main/ipc/settings.test.ts src/main/persistence.test.ts src/renderer/src/components/settings/TerminalSettingsPreview.lifecycle.test.tsx — 391 passed
  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/terminal-appearance.test.ts src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.test.ts — 39 passed
  • Existing xterm-addon.boundary-containment reliability command — 41 passed
  • pnpm typecheck — passed
  • changed-file oxlint, git diff --check, and pnpm check:max-lines-ratchet — passed

ELI5

Orca's settings screen only lets users choose safe terminal line spacing, but an older settings file could still contain an unsafe number. Orca handed that number directly to the terminal library, and the library threw an error that removed the terminal/settings surface. Orca now checks the number whenever it loads, saves, or applies it, so old bad values become the nearest safe value before the terminal sees them.

Trade-offs

  • Values below 1 now become 1; values above 3 become 3; non-finite values become 1.
  • This intentionally changes behavior for manually edited/legacy unsupported values: Orca no longer preserves spacing outside the Settings UI's documented 1–3 range.
  • No supported value changes, and no polling, scans, PTY calls, provider calls, or render loops are added.

Reliability proof

  • Reliability class / gate: xterm-addon.boundary-containment (existing experimental, partial gate; unchanged).
  • Invariant: persisted, renderer-supplied, local, or remote settings cannot pass an out-of-contract line height into xterm construction or live option mutation.
  • Product change type: runtime hardening plus regression coverage.
  • Performance risk: constant-time numeric normalization in settings load/update and terminal option application. Typing, focus, switching, resize, output, startup awaits, provider listing, hidden output, and git/worktree scans are unchanged.
  • Provider/platform coverage: shared option path covers local, daemon, SSH, WSL, remote-runtime, and mobile/relay consumers. Automated tests are platform-neutral; live Electron evidence is macOS only.
  • Residual gaps: no live Linux/Windows Electron run in this PR; Windows crash payloads are being handled separately on a Windows machine.
  • Promotion status: gate remains experimental/partial because this fix does not add cross-platform runtime history.
  • Rollback/demotion rule: revert or follow up if any supported value in [1,3] changes, if xterm surfaces diverge from the persisted normalized value, or if cross-platform Electron validation exposes a provider-specific settings path.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds shared terminal line-height normalization with bounds of 1 through 3. Applies normalization to settings IPC updates, persisted settings loading and repair, terminal preview initialization and updates, terminal appearance application, and terminal lifecycle options. Adds tests covering normalization cases, IPC persistence, persisted-state repair, and preview behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description doesn't use the required template and omits or renames key sections like Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes. Rewrite the PR description to match the repository template, including all required headings, a screenshots note, testing checklist, AI review report, security audit, and notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 accurately summarizes the main change: normalizing invalid terminal line height before xterm sees it.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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/shared/terminal-line-height-settings.test.ts (1)

9-17: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider adding edge cases for Infinity and non-number types.

The current cases cover the primary paths well. Adding Infinity (returns MIN via !Number.isFinite) and a non-number type like '1.35' or null (returns MIN via the typeof guard) would strengthen confidence in the two distinct rejection branches.

♻️ Suggested additional test cases
   it.each([
     [undefined, MIN_TERMINAL_LINE_HEIGHT],
     [Number.NaN, MIN_TERMINAL_LINE_HEIGHT],
+    [Number.POSITIVE_INFINITY, MIN_TERMINAL_LINE_HEIGHT],
+    [Number.NEGATIVE_INFINITY, MIN_TERMINAL_LINE_HEIGHT],
+    [0, MIN_TERMINAL_LINE_HEIGHT],
+    [-5, MIN_TERMINAL_LINE_HEIGHT],
+    ['1.35', MIN_TERMINAL_LINE_HEIGHT],
+    [null, MIN_TERMINAL_LINE_HEIGHT],
     [0.85, MIN_TERMINAL_LINE_HEIGHT],
     [1, 1],
     [1.35, 1.35],
     [3, 3],
     [4, MAX_TERMINAL_LINE_HEIGHT]
   ])('normalizes %s to %s', (input, expected) => {

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4f2d2050-3a72-4a0c-ab91-11522587140d

📥 Commits

Reviewing files that changed from the base of the PR and between b7e84ae and 64a8221.

📒 Files selected for processing (10)
  • src/main/ipc/settings.test.ts
  • src/main/ipc/settings.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/renderer/src/components/settings/TerminalSettingsPreview.lifecycle.test.tsx
  • src/renderer/src/components/settings/TerminalSettingsPreview.tsx
  • src/renderer/src/components/terminal-pane/terminal-appearance.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts
  • src/shared/terminal-line-height-settings.test.ts
  • src/shared/terminal-line-height-settings.ts

@nwparker
nwparker merged commit e4c7aab into main Jul 10, 2026
3 checks passed
@nwparker
nwparker deleted the nwparker/crashes-4 branch July 10, 2026 08:28
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