Repository navigation
perf(renderer): gate the jump palette's status-map subscriptions while closed - #7558
Conversation
…e closed Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughThis PR adds a new module exporting Sequence Diagram(s)Included in the hidden review stack artifact above. Related PRs: None identified. Suggested labels: refactor, renderer Suggested reviewers: None identified. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 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.
🧹 Nitpick comments (4)
src/renderer/src/components/worktree-jump-palette-status-inputs.ts (2)
14-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTrim the "why" comments to the guideline's one/two-line limit.
Both blocks (10 lines each) explain valuable context, but the repo guideline caps design-rationale comments at one or two lines.
✏️ Suggested trim
-// Why: shared frozen bundle returned whenever the Cmd+J jump palette isn't -// active. The two hottest maps here — agentStatusByPaneKey and -// runtimePaneTitlesByTabId — get a new top-level identity on every agent-status -// transition and every terminal pane-title write app-wide. The palette is always -// mounted (App.tsx renders <CommandDialog open={visible}>) and stays mounted for -// the whole session once opened, so subscribing to them while it's closed -// re-rendered the whole palette — and recomputed its per-worktree live/working-dot -// sort over every worktree — on unrelated terminal chatter. A useShallow -// subscription keeps this same reference across that churn, so the closed palette -// stops reacting. Frozen so the shared singleton can't be mutated. +// Why: shared, frozen no-op bundle used while the always-mounted palette is +// closed, so useShallow stays referentially stable across unrelated status churn.Based on coding guidelines,
**/*.{ts,tsx,js,jsx}requires "Keep comments short — one or two lines, capturing only the non-obvious reason."Also applies to: 32-41
Source: Coding guidelines
24-30: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winType the frozen singleton as
Readonly<PaletteStatusInputs>.
Object.freezegives runtime immutability, but the explicitPaletteStatusInputsannotation discards that guarantee at compile time — nothing stops a future edit likeEMPTY_PALETTE_STATUS_INPUTS.tabsByWorktree = {...}from type-checking, even though it will silently no-op at runtime.🛡️ Proposed fix
-export const EMPTY_PALETTE_STATUS_INPUTS: PaletteStatusInputs = Object.freeze({ +export const EMPTY_PALETTE_STATUS_INPUTS: Readonly<PaletteStatusInputs> = Object.freeze({ agentStatusByPaneKey: {}, runtimePaneTitlesByTabId: {}, ptyIdsByTabId: {}, terminalLayoutsByTabId: {}, tabsByWorktree: {} })src/renderer/src/components/WorktreeJumpPalette.tsx (2)
346-350: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTrim the "why" comments to one or two lines.
Both blocks (5 and 12 lines) restate rationale already captured in
worktree-jump-palette-status-inputs.ts; consider linking to that module's doc comment instead of duplicating the full explanation here.
Based on coding guidelines,**/*.{ts,tsx,js,jsx}requires "Keep comments short — one or two lines, capturing only the non-obvious reason."Also applies to: 363-374
Source: Coding guidelines
346-362: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winAdd a fake-timers test for the close-linger gate. Cover the 300ms delay and the reopen-before-timeout path so
statusInputsLingeringdoesn’t regress.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a98b16e5-0dd6-4755-906e-6fb3617d09e0
📒 Files selected for processing (3)
src/renderer/src/components/WorktreeJumpPalette.tsxsrc/renderer/src/components/worktree-jump-palette-status-inputs.test.tssrc/renderer/src/components/worktree-jump-palette-status-inputs.ts
Brings in 9 commits: deferred remote catalogs at startup (#7087), owner-aware pane title decision gating the Gemini GPU fallback (#7458), incremental transcript parsing for JSONL agents (#7593), gh rate-limit and git-status spawn-churn fixes (#7595), WSL Codex session bridging (#7477), jump-palette subscription gating (#7558), and the IDE font dropdown fix. Conflict resolutions (our structure, main's semantics): - pty-connection.ts onTitleChange: kept this branch's third parameter and stale-derived-title guard (staleWorkingTitleClear must never feed completion tracking), grafted main's resolvePaneTitleDecision so the display label, GPU policy, and observeTitle all ride the owner-aware decision (#7428/#7447). - App.tsx startup: kept this branch's publishTerminalViewAttributesAtAppStart (hidden-at-launch OSC 10/11 replies) ahead of main's restructured local-first startup; dropped this branch's early ui.get() overlap — main's #7087 now awaits ui.get at effectively the same point, making it redundant. Gates: typecheck clean; 4298 tests across src/main/ipc, src/main/daemon, terminal-pane, pane-manager. The delivery path (ipc/pty.ts, dispatcher, scheduler, snapshots) had no conflicts and no incoming changes. Co-authored-by: Orca <[email protected]>
…e closed (stablyai#7558) Co-authored-by: Orca <[email protected]>
Follow-up scan for more #7545-class wins — always-mounted renderer components that subscribe to hot store maps they only need under a narrow condition. Independently surfaced by two finders and adversarially verified (churn confirmed, always-mounted confirmed, gate sound); this was the highest-value survivor.
1. Description
WorktreeJumpPalette(Cmd+J) is always mounted —App.tsxrenders<CommandDialog open={visible}>, and once opened it stays mounted for the rest of the session. It opened five whole-map Zustand subscriptions:Those five feed only the palette's row derivations —
sortWorktreesSmartover every worktree,isInactiveWorkspacefiltering,buildSearchableWorkspaceTabs, and thegetWorktreeStatusdots — all consumed only inside the open dialog. But two of them,runtimePaneTitlesByTabIdandagentStatusByPaneKey, get their top-level reference replaced on every terminal pane-title escape sequence and every agent-status transition — the two hottest maps in the app. So while the palette was closed (virtually always), every such write re-rendered the whole palette and recomputed its per-worktree status sort over the full worktree list.Fix (same shape as #7545): collapse the five subscriptions into one
useShallowselector (selectPaletteStatusInputs, extracted toworktree-jump-palette-status-inputs.ts) that returns a shared frozen constant while the palette isn't active. Idle palettes then stay referentially equal across the title/status churn and stop re-rendering; the live maps flow through the instant it opens (same render —visiblederives from the same store snapshot, so there's no stale first frame).Close-animation safety:
visibleflips false synchronously on close, but theCommandDialogcontent stays mounted while it fades/zooms out. A naive gate would flash the rows empty/reordered mid-animation, so a smallstatusInputsLingeringlatch keeps the maps live for 300ms past close (comfortably beyond the ~150–200ms animation), after which the gate drops the subscription.2. Undeniable evidence + measurable improvement
worktree-jump-palette-status-inputs.test.ts, red→green — the honest, non-flaky evidence): the selector returns the sameEMPTY_PALETTE_STATUS_INPUTSreference even afterruntimePaneTitlesByTabId/agentStatusByPaneKeychurn while inactive (→useShallowskips the render); exposes the live maps the instant it becomes active; keeps them live during the close linger; and shallow-changes only when a subscribed map ref actually changes while active (so the open palette re-derives exactly as before).WorktreeJumpPalettetests pass unchanged; typecheck + oxlint + react-doctor clean.3. ELI5
The Cmd+J switcher was quietly listening to every terminal in the app renaming its tab or flipping agent status — and redrawing its whole list each time — even while it was closed and invisible. Now it ignores all that chatter until you actually open it (and keeps listening just long enough to fade out cleanly).
4. Trade-offs that regress the end experience
None material. The five maps drive only the palette's own rows, which are shown only while it's open; the linger removes the one theoretical close-animation flash.
migrationUnsupportedByPtyId(identity-preserving on the status path) and every non-status subscription are left exactly as they were.Made with Orca 🐋