Repository navigation
fix(terminal): re-run deferred tab admission when a plan installs mid-activation - #20176
Conversation
…-activation planColdActivationTabDeferral can install an empty allowed set, deferring every tab so the pane filter renders none. The drain that undoes that, useActivationDeferredTabAdmission, depends only on backgroundMountRevision and renderedActiveWorktreeId while reading the deferred set from a mutable ref, and the install bumps neither: the only revision producers are the drain itself and the background-mount event path, which the activation plan never reaches. So this pass strands the workspace with zero panes: the worktree is already rendered-active while the startup gate is closed, which resets lastActivationWorktreeIdRef, then the gate opens on the same worktree and installs a plan. Nothing re-runs the drain until the user switches workspaces and back. The hook's own comment anticipates this launch shape and relies on re-reading on growth, but that re-read only happens on a dep change. applyTerminalColdActivation now returns activationDeferralPlanRevision, backed by a ref in the parking foundation and incremented only when the plan actually installs, which the admission effect takes as a dep. A ref rather than state because the pass runs during render, where a setState would be a render-phase update. The 4-tab admission cap is deliberately untouched: it reproduces the warm set an eager activation used to mount, so steady-state pane and WebGL-context population is unchanged. Ablated: with the change reverted the new suite's drain case fails on the deferred set surviving the timers; the precondition and the away-and-back control pass either way.
|
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 (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughThe change adds a render-safe cold-activation plan revision ref to the terminal parking foundation. Cold activation increments the revision when it installs a deferral plan and returns the current revision. Deferred tab admission now re-runs when the revision changes. New tests cover reopening the startup gate with the same active worktree and the existing worktree-switch path. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The startup-gate reopening path is covered without introducing an actionable merge risk. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description clearly explains the problem, implementation, rationale, testing, and platform scope. However, it does not provide the required linked issue, does not use the required Resolution Add a linked issue after
✨ Finishing Touches 💡 1📝 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
This PR closes a stranding gap where a cold-activation deferral plan installs on the gate-open pass for an already-active worktree by mutating only refs, so the admission drain's effect deps never changed and the tabs stayed unmounted until the user switched workspaces and back.
- Revision channel —
applyTerminalColdActivationnow capturesplanColdActivationTabDeferral's return, bumps a newactivationDeferralPlanRevisionRefonly on an actual install, and returns the count. - Drain dependency —
useActivationDeferredTabAdmissionaddsactivationDeferralPlanRevisionas a third effect dep (with awhycomment), so the drain re-runs on the install render. - Foundation ref — new
activationDeferralPlanRevisionRefcreated and exported fromuseTerminalParkingFoundation; ref rather than state because the cold-activation pass runs during render. - Tests — new
cold-activation-deferral-stranding.test.tsexercises the real modules and store (gate-closed pass → gate-open install → drain without anyrenderedActiveWorktreeIdchange, plus a bounce-away control), and the hand-built controller literal interminal-workspace-surface-ids.test.tsxgains the new ref.
Verified this run: the new test passes 3/3 and an independent ablation (dropping the new dep) fails exactly the gate-open drain case (expected true to be false) while the precondition and control still pass, so the test can actually fail. Five related suites pass 45/45, pnpm tc:web exits 0, and check:code-quality:changed reports 0 findings across the five changed files.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
Electron/CDP UI check (PR #20176)Launched this worktree’s dev app hidden ( App identity (verified): Scenario attemptedThe defect is a startup-gate ordering: the worktree is already rendered-active while the gate is closed (which resets That exact ordering could not be forced through the real UI on this quiet isolated launch. First paint of the isolated profile had no workspaces/tabs ( What I could drive:
Visible evidenceIsolated launch (empty profile, this branch’s app): Two tabs + drawn pane after activating the fixture workspace: After switching away and back: After renderer reload, both tabs and the pane still drawn (no second workspace switch): Console / app errors
Gaps (do not treat this as proof of the mid-activation drain)
No production code or tests were modified. |
Review status: PASS — land\n\n- Independent same-model senior review completed clean; no production fixes were warranted and no scope expansion was made.\n- Readiness checklist passed at start and end with no proven P0/P1/P2 findings. No counsel packet was needed.\n- Full terminal suite: 488 files / 4,622 tests passed.\n- Focused regression suites: 3 files / 16 tests passed.\n- Web typecheck and changed-file oxlint passed; passed.\n- Review covered activation gating, worktree bounce, deferral-disabled paths, >4-tab admission cap, pruning/cleanup, cross-platform/remote boundaries, and performance. The change adds only a scalar revision/ref and the intended one-per-idle-tab drain; no new scans, IPC, retries, or resource lifetimes.\n- Electron/CDP evidence with full-window screenshots is in the UI validation comment. It verifies the intended worktree identity, terminal tabs rendering after activation, survival across workspace switching, and rendering after reload with 0 console errors. The exact startup-gate-open-on-an-already-active-worktree race was not reproducible in the isolated profile, so the new regression test remains the direct proof for that path.\n- No SSH/mobile/windows validation was needed: the diff is renderer-only and does not change RPC, relay, filesystem, or platform-specific contracts.\n\nFinal tree is clean and the PR head remains unchanged. |





ELI5
A workspace can come up with its tab bar populated but no terminals drawn at all, and stay that way until you switch to another workspace and back. The tabs were deferred on purpose to keep the switch fast — but nothing ever came back to actually mount them.
What Changed
planColdActivationTabDeferralcan install an empty allowed set, deferring every tab, so the pane filter renders none. The drain that undoes that —useActivationDeferredTabAdmission— depends only onbackgroundMountRevisionandrenderedActiveWorktreeId, while reading the deferred set out of a mutable ref. The install bumps neither dep: the only two revision producers in the repo are the drain itself and the background-mount event path, which fires only for explicit wake/resume requests and which the activation plan never reaches.The stranding pass is specific: the worktree is already rendered-active while the startup gate is closed, so the
elsebranch resetslastActivationWorktreeIdRefto null; then the gate opens on the same worktree, the plan installs, and no dep changed. Nothing re-runs the drain untilrenderedActiveWorktreeIdchanges — i.e. until the user switches workspaces and back.applyTerminalColdActivationnow returnsactivationDeferralPlanRevision, backed by a ref in the parking foundation and incremented only when the plan actually installs (planColdActivationTabDeferralalready returnstrueexactly when it sets the restriction,falseon the threshold-miss path after deleting it). The admission effect takes that as a dep.A ref rather than state because the cold-activation pass runs during render, where a
setStatewould be a render-phase update. The returned number differs on the install render, so the effect re-runs after that render commits.Why
The hook's own comment already anticipates this launch shape and relies on "re-reading on growth" — but the re-read only happens on a dep change, and the gate-open pass produces none. This closes that gap at the point where the state actually changes, rather than adding a poll or a timer.
The 4-tab admission cap (
ACTIVATION_DEFERRED_ADMISSION_LIMIT) is deliberately untouched. It reproduces the warm set an eager activation used to mount, so steady-state pane, WebGL-context and heap population stay unchanged; above it, tabs still mount when revealed.Linked Issue
No filed issue — found while diagnosing a report of a newly created workspace showing no terminal and no tabs. Note this is a second, independent defect with the same "switch away and back fixes it" signature; it is not the cause of that report, since it renders zero panes and therefore spawns no PTYs, whereas the reported occurrence did spawn them.
Visual Proof
Not captured. This needs the startup gate to open on an already-active worktree, which I could not drive through the real UI on a quiet machine. Evidence is the ablated unit test below, which exercises the real modules and the real store rather than mocks.
Happy to add a recording if a reviewer can suggest a way to force the gate ordering interactively.
Testing
New
src/renderer/src/components/terminal/cold-activation-deferral-stranding.test.ts— real modules, real zustand store, no mocks of anything under test:canWatcherCoverParkedTerminalTabwith panes captured and authoritative snapshots primedrenderedActiveWorktreeIdever changingAblation (measured, both arms):
drains a plan installed by the gate-open pass without the active worktree changing(expected true to be false— deferred set survived the timers)Other gates:
cold-activation|background-terminal-worktree-mount|activation-deferred: 82/82 passedpnpm tc:web: exit 0pnpm run check:code-quality:changed: 0 findings across code quality, type-aware and React DoctorOne test-only edit:
terminal-workspace-surface-ids.test.tsxbuilds a controller literal by hand and needed the new ref, or it throws at runtime.Platform: macOS only. Renderer-only change with no platform-conditional code.