Skip to content

fix(terminal): stop parking pass queueing no-op renders that trip React #185 during worktree removal - #23636

Merged
OrcaWin merged 3 commits into
mainfrom
fix/scan29-react-185-active-worktree-remove
Oct 2, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
fix/scan29-react-185-active-worktree-remove

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​102 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​102
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​27 $\color{#cf222e}{\Huge{\mathbf{−}}}$​12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​15

Description

Removing the worktree you are looking at could crash the terminal area with "Minified React error #185" (Maximum update depth exceeded). The whole terminal workbench then showed its error fallback. One user hit this on 1.4.215 while deleting an active worktree that had 8–9 terminal panes and a running Claude session.

Mechanism. When a worktree is removed, the main process stops every terminal (PTY) in it. The renderer then closes those panes one at a time, and each close is its own synchronous React commit. After each commit, the terminal workbench's useTerminalParkingPass effect runs again and calls three state setters: setParkedTerminalWorktreeIds, setForceParkedTerminalWorktreeIds and setEvictionExemptTerminalTabIds. Their updaters return the same Set when nothing changed. React still queues a render for them anyway, because it skips its "same state, do nothing" shortcut while the component already has other work pending. So every commit in the burst leaves one more update behind. React counts these chained updates and never resets the count during the burst. It grows by about 1.7 per closed pane. Past about 30 panes it goes over React's limit of 50 and throws #185, right at setParkedTerminalWorktreeIds. That is the exact statement in the user's crash frame (Terminal-M0kI6An6.js:2:103140 in 1.4.215).

Change (src/renderer/src/components/use-terminal-parking-pass.ts). The hook now keeps a ref of the last three sets it dispatched. This effect is the only code that writes those three states. It calls a setter only when the new set actually differs (haveSameIdSet). An unchanged pass now dispatches nothing, so it queues no render and leaves nothing pending.

Before / after for the user: before, deleting an active worktree with many terminal panes could crash the terminal area. After, deletion completes normally. Parking decisions (which hidden worktrees get parked) are unchanged.

Why this approach. It removes the source of the chained updates with a small, local change. The alternative was to batch the whole pty-exit teardown while a worktree is being deleted. That touches the pane manager and the tab-close paths, so it is riskier. It is noted below as possible follow-up.

Fix evidence

Unit regression test: src/renderer/src/components/use-terminal-parking-pass.test.tsx. A host hook owns the three parking states plus a revision state. It bumps the revision 5 times on the same component, which reproduces the case where React skips its same-state shortcut. The test asserts exactly 5 renders and checks that the parked set is still dispatched.

pnpm test src/renderer/src/components/use-terminal-parking-pass.test.tsx
  • Before, with the original hook restored: FAIL AssertionError: expected 10 to be 5. Every bump caused one extra no-op render.
  • After: PASS Tests 1 passed (1).

Real Electron app, end to end. The app was built with npx electron-vite build --mode e2e and run hidden with ORCA_BACKGROUND_LAUNCH=1. The React bundle was patched with one read-only line that records the peak of React's own nested-update counter, the counter that throws #185 above 50. A local, uncommitted Playwright probe did the following:

  1. Created 2 hidden background worktrees with split terminals.
  2. Created a target worktree with N split terminal tabs, one of them running a busy streaming "agent" loop.
  3. Removed the target while it was the active worktree.
ORCA_BACKGROUND_LAUNCH=1 SKIP_BUILD=1 R185_TABS=14 R185_SPLIT_EVERY=1 \
  npx playwright test tests/e2e/react-185-active-worktree-remove.repro.spec.ts \
  --config tests/playwright.config.ts --project electron-headless --workers=1
Build Panes Peak nested-update counter Result
origin/main (before) 4 6 ok
origin/main (before) 9–10 9–17 ok
origin/main (before) 18 34 ok
origin/main (before) 20 37 ok
origin/main (before) 30 51 Minified React error #185 ... at Terminal-g_NrAwx8.js:2:104389 (setParkedTerminalWorktreeIds), [terminal.workbench] render crash contained by boundary, test failed
this branch (after) 20 0 / 0 ok
this branch (after) 30 0 / 0 no #185, no boundary fallback, 1 passed
this branch (after) 50 (stress) 0 no #185. The only failure was WebAssembly.instantiate(): Out of memory, which is the separate too-many-terminals issue tracked in #23499

The crash in the "before" build matches the user's report:

  • Same statement: d(e=>bo(e,n.nextParkedTerminalWorktreeIds)?e:...) here, and mo(...) in the 1.4.215 chunk extracted from the shipped app.
  • Same React frame chain (_i/mi/zs/Rs/Kc/kl/Ol) and the same terminal.workbench boundary.
  • Same timing: the crash lands about 2–3 s into a roughly 4.5 s removal, which is what the user's log shows.

Other checks:

  • pnpm test on the new test plus src/renderer/src/components/terminal-pane/: 4729 passed.
  • Parking e2e specs on the fixed build: terminal-hidden-view-parking, terminal-parked-close-retirement, terminal-parked-memory and terminal-parked-cli-split, 9 passed.
  • pnpm tc:web: OK.
  • oxlint: OK.

ELI5 of the fix

Every time a terminal closed, a helper said "update the parking list!" even when the list had not changed. React took each of those as real work. When you deleted a worktree with lots of terminals, dozens of "nothing changed" updates arrived in a row. React decided it was stuck in an infinite loop and crashed the terminal area. Now the helper remembers what it last said and stays quiet when the list is the same.

Trade-offs

  • No user-facing behaviour change. Parking results are the same. A pass that produces the same sets just no longer queues a render.
  • The ref could drift in the future. The ref assumes this effect is the only writer of the three states, which is true today (checked with grep). A future second writer would also have to update the ref. A code comment says this.
  • The pane-close burst is still there. Removing a worktree still does one commit per closed pane: about 58 commits for 30 panes. That burst just no longer chains into fix: improve scrollbar and file explorer scroll behavior #185. Two other effects that queue no-op updates showed up in the trace, one in quick-open and one other. They are not enough to reach fix: improve scrollbar and file explorer scroll behavior #185 today. Batching the pty-exit teardown during worktree deletion would remove the burst entirely, but it is left as follow-up.
  • Telemetry still misses this. The existing react_commit_cascade telemetry still cannot see this kind of chain, because it reads pending work before the passive effects run. That is unchanged here.

Adversarial review

1 loop until clean.

  • Loop 1: clean, no issues.
    • The "only writer" claim was checked by grep. The three states and the ref live in the same component.
    • The ref and the state start the same (both empty Sets) and stay in step on remount and under StrictMode.
    • Stored sets are never changed after they go into the ref.
    • Nothing is specific to SSH, folder workspaces or any OS.
    • The new test fails with the original source ("expected 10 to be 5") and passes with the fix.
    • oxlint and pnpm tc:web pass. The single type assertion in the test has a SAFETY comment.

Linked crash reports

Visual Proof

N/A. This fixes a crash with no visual change. The evidence is the test and the e2e counter results above.

Testing

  • I manually tested these changes locally (macOS, real Electron app run in the background; see Fix evidence)
  • Automated tests added/updated

Agent skill upstream boundary

  • Not applicable

Notes

  • Security: not affected.
  • Platforms: the change is platform-independent React state logic.
  • SSH: not affected; no remote or PTY protocol change.
  • Mobile: not affected.
  • Backwards compatibility: not affected.
  • Performance: slightly better, since there are fewer renders.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Additional merge-risk verification (2026-10-02)

Integrated current main. Initialized the parking-set mirror lazily so repeated renders do not allocate three unused Sets. Added changed-set and Strict Mode regression coverage; 81 tests passed across five parking/retention suites, renderer typecheck passed, and the changed-code quality gate passed for the two PR files. Existing unrelated untracked reproduction artifacts were excluded from that gate. The recorded 30-pane Electron reproduction establishes this crash class; the exact 8–9-pane field incident is still unconfirmed.

…lose bursts

Removing an active worktree with many terminal panes closed each pane in its
own commit. Every commit re-ran the parking pass, whose functional setters
queued a render even when the sets were unchanged, so each commit left work
pending and React's nested-update counter climbed past 50 (#185), taking down
the terminal workbench boundary. Dispatch only when a set actually changes.

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

  • Parking pass no longer queues no-op renders — use-terminal-parking-pass.ts now mirrors the three dispatched id sets in a ref and calls the value setter only when haveSameIdSet reports a real difference, replacing functional updaters that returned current (which React still treats as a queued update during a pending-work burst).
  • Regression test added — use-terminal-parking-pass.test.tsx drives a host hook through 5 revision bumps and asserts exactly 5 renders plus the parked set still dispatching.

I verified the sole-writer assumption behind the ref (only the foundation declares these setters and only this pass consumes them), and independently reproduced the test's before/after: with the old functional-updater form it fails expected 10 to be 5; with the fix it passes. Parking semantics are unchanged because same-content sets were already skipped.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 29341d4e-05ad-4b3e-a30c-513d428e0f37

📥 Commits

Reviewing files that changed from the base of the PR and between 6afc0a0 and cfc769f.

📒 Files selected for processing (2)
  • src/renderer/src/components/use-terminal-parking-pass.test.tsx
  • src/renderer/src/components/use-terminal-parking-pass.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.


📝 Walkthrough

Walkthrough

useTerminalParkingPass now tracks the last dispatched parked, force-parked, and eviction-exempt ID sets. It calls each state setter only when the corresponding computed set differs. New tests cover unchanged parking sets, changed candidate IDs, render counts, and transitions under StrictMode.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to cfc76

The change suppresses redundant parking updates while preserving identified parking transitions. No actionable merge-blocking risk remains after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the terminal parking fix, the no-op render problem, React error #185, and the worktree-removal context.
Description check ✅ Passed The description is comprehensive and covers the problem, mechanism, rationale, user impact, testing, compatibility considerations, visual proof, and checklist. The required Fixes # issue field is blan…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@OrcaWin
OrcaWin merged commit a050afb into main Oct 2, 2026
20 of 22 checks passed
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