Skip to content

fix(worktree-palette): guard undefined review title in matcher (crash c5d87873) - #10024

Merged
nwparker merged 1 commit into
mainfrom
nwparker/fix-worktree-palette-tolowercase
Jul 23, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/fix-worktree-palette-tolowercase

Conversation

@nwparker

@nwparker nwparker commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes a renderer crash in the Worktree Jump Palette (Cmd/Ctrl+J). Typing any non-numeric text into the palette could throw:

TypeError: Cannot read properties of undefined (reading 'toLowerCase')
    at matchWorktreePaletteReview
    at searchWorktrees
    at WorktreeJumpPalette (useMemo)

matchWorktreePaletteReview called review.title.toLowerCase() with no guard. Although HostedReviewInfo.title / PRInfo.title are typed as required string, the review objects come from on-disk rehydrated caches (hostedReviewCache / prCache) that can contain partial/legacy entries with no title. At runtime title was undefined, so the whole renderer crashed into the modal.worktree-palette error boundary.

Crash report: c5d87873-e664-405e-858e-c41a720d50b5 (macOS, Orca 1.4.147). Same unguarded path exists on current main.

CLEAR, UNDENIABLE fix evidence

A regression test reproduces the exact production error against the unmodified code, then passes after the one-line null-safety guard.

Before the fix (git stash the source change, keep the test):

 ❯ worktree-palette-review-match.test.ts (4 tests | 2 failed)
   × returns null instead of throwing when a cached review has no title
     AssertionError: expected [Function] to not throw an error but
     'TypeError: Cannot read properties of undefined (reading 'toLowerCase')' was thrown
   × does not throw when the checks-review cache entry has no title   (via searchWorktrees)
     AssertionError: ... 'TypeError: Cannot read properties of undefined (reading 'toLowerCase')' was thrown

The thrown message is byte-for-byte the production crash, reproduced both through the matcher directly and through the real searchWorktrees → WorktreeJumpPalette useMemo path from the stack trace.

After the fix:

 Test Files  2 passed (2)
      Tests  22 passed (22)     # 4 new regression tests + 18 existing search tests

tsc web typecheck: exit 0. oxlint on the changed file: clean.

ELI5

The little "jump to worktree" search box tries to match what you type against each worktree's pull-request title. Some saved PR records (loaded from disk) had no title at all — an empty slot. The code assumed a title was always there and called "make this text lowercase" on the empty slot, which is like trying to read a page from a book that isn't there — so the whole window crashed. The fix: if there's no title, treat it as an empty string. An empty title just can't match your search (which is correct — there's nothing to match), and nothing crashes.

Trade-offs / regressions

  • None user-facing. With a missing title the matcher now returns null (no supporting-text highlight for that review) instead of throwing — the desired behavior; the palette simply doesn't highlight a title that never existed. Number matching, GitHub/GitLab sigil scoping, and match-range math are untouched.
  • The SearchableReview type was narrowed to title?: string (honest about runtime reality); all call sites still compile.
  • Deferred (out of scope): the underlying schema HostedReviewInfo.title: string is still "optimistic" — any other consumer that reads a rehydrated title directly could hit the same class of bug. This PR guards the crashing palette path only. A follow-up could make title optional at the type source or sanitize on cache rehydration.

Adversarial review

  • 1 loop to clean. A fresh skeptic sub-agent tried to refute the fix and confirmed it is correct and complete for the reported crash (query is guaranteed non-empty, so a missing title deterministically yields null; the type widening is sound; no title-present behavior change; no secondary .title crash remains in the useMemo path). Only nice-to-have/nit suggestions remained (the deferred schema note above; a non-string-title defensive coercion with no evidence of occurring) — none are must-fix.
  • Perf review (/perf skill, sub-agent): clean. Pure null-safety guard; if anything it reduces two property reads to one. No allocation, polling, effect, render, or subscription vectors touched.

Made with Orca 🐋

… c5d87873)

matchWorktreePaletteReview called review.title.toLowerCase() with no guard.
Rehydrated review/PR caches can hold entries with an undefined title, so any
text query in the Cmd/Ctrl+J worktree palette crashed the renderer with
'TypeError: Cannot read properties of undefined (reading toLowerCase)'.
Coalesce the title to '' and widen the type to reflect runtime reality.

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Updated SearchableReview to allow missing titles and made matchWorktreePaletteReview use an empty fallback for title matching and returned text. Added Vitest regression coverage for titleless reviews, title and PR-number matching, and the searchWorktrees path involving cached reviews without titles.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the fix and testing, but it doesn't follow the required template sections for Screenshots, AI Review Report, Security Audit, or Notes. Restructure the PR description to match the template and add the missing Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes sections.
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 clearly states the main fix: guarding undefined review titles in the worktree palette matcher.
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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 46f849d7-dfb7-4f81-be82-0233a99ef000

📥 Commits

Reviewing files that changed from the base of the PR and between c8381f3 and 14969fa.

📒 Files selected for processing (2)
  • src/renderer/src/lib/worktree-palette-review-match.test.ts
  • src/renderer/src/lib/worktree-palette-review-match.ts

Comment on lines +39 to +47
// Null-safe: a cached review may have no title, so fall back to '' (query is non-empty, so it won't match).
const title = review.title ?? ''
const titleIndex = title.toLowerCase().indexOf(query)
if (titleIndex === -1) {
return null
}
return {
labelKind: isMergeRequest ? 'mr' : 'pr',
text: review.title,
text: title,

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Return no match explicitly when the title is missing.

With query === '', the empty fallback produces titleIndex === 0, so a titleless review returns a match with empty text instead of null. Guard the missing-title case directly and add an empty-query regression test.

Suggested fix
-  // Null-safe: a cached review may have no title, so fall back to '' (query is non-empty, so it won't match).
-  const title = review.title ?? ''
+  if (review.title == null) {
+    return null
+  }
+  const title = review.title
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Null-safe: a cached review may have no title, so fall back to '' (query is non-empty, so it won't match).
const title = review.title ?? ''
const titleIndex = title.toLowerCase().indexOf(query)
if (titleIndex === -1) {
return null
}
return {
labelKind: isMergeRequest ? 'mr' : 'pr',
text: review.title,
text: title,
if (review.title == null) {
return null
}
const title = review.title
const titleIndex = title.toLowerCase().indexOf(query)
if (titleIndex === -1) {
return null
}
return {
labelKind: isMergeRequest ? 'mr' : 'pr',
text: title,

@nwparker
nwparker merged commit bc301de into main Jul 23, 2026
1 of 2 checks passed
@nwparker
nwparker deleted the nwparker/fix-worktree-palette-tolowercase branch July 23, 2026 00:43
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