Repository navigation
fix(terminal): restore live background terminal projections - #11819
lightofjeju wants to merge 3 commits into
Conversation
📝 WalkthroughWalkthroughThe change adds terminal-tab projection invariants, canonical projection repair, and live PTY probing with bounded concurrency, timeouts, deadlines, and abort handling. Startup and terminal adoption invoke repair with diagnostic logging. Main-process tests cover fresh PTY binding persistence. Session persistence now supports asynchronous writes, retains suppressed fields, serializes writes, retries failures, and preserves pending state during cleanup. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/renderer/src/store/slices/tabs.ts (1)
634-648: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winAvoid a no-op store notification when the projection patch is empty.
ensureTerminalTabProjectionreturnsoutcome.patch, which is{}for theunchangedandskippedoutcomes. Zustand still builds a new state object for a partial update and notifies every subscriber. Startup repair calls this once per candidate tab, andonCreateTerminalcalls it on every terminal adoption, so each miss re-runs full-state selectors. The rest of this slice already guards against that pattern (see the "no-op alloc that re-runs full-state selectors" comments).Return the current
statereference when the patch is empty so Zustand skips the notification.♻️ Proposed fix
ensureTerminalTabProjection: (worktreeId, tabId, targetGroupId) => { let result!: EnsureTerminalTabProjectionResult set((state) => { const outcome = buildTerminalTabProjectionPatch( state, worktreeId, tabId, targetGroupId, createBrowserUuid ) result = outcome.result - return outcome.patch + // Why: an empty patch must keep the state reference so subscribers and selectors don't re-run. + return Object.keys(outcome.patch).length === 0 ? state : outcome.patch }) return result },
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8e731685-4bd9-44c9-85cb-de3deda89855
📒 Files selected for processing (16)
src/main/persistence.test.tssrc/main/persistence.tssrc/renderer/src/App.tsxsrc/renderer/src/app-startup-routing.test.tssrc/renderer/src/hooks/ipc-events-test-harness.tssrc/renderer/src/hooks/useIpcEvents.test.tssrc/renderer/src/hooks/useIpcEvents.tssrc/renderer/src/lib/session-write-subscriber.test.tssrc/renderer/src/lib/session-write-subscriber.tssrc/renderer/src/lib/terminal-tab-projection-repair.test.tssrc/renderer/src/lib/terminal-tab-projection-repair.tssrc/renderer/src/store/slices/tabs.test.tssrc/renderer/src/store/slices/tabs.tssrc/renderer/src/store/slices/terminal-tab-projection-invariant.tssrc/renderer/src/store/slices/terminal-tab-projection.test.tssrc/renderer/src/store/slices/terminal-tab-projection.ts
Greptile SummaryThis PR restores live terminal sessions that became invisible when a background/non-focus CLI terminal was created before the renderer session writer ran. The fix adds an idempotent projection repair step owned by the renderer that runs after startup reconnect, and also invokes repair synchronously on each IPC terminal adoption.
Confidence Score: 5/5Safe to merge. The change restores missing terminal tab projections without altering PTY lifecycle, backing rows, layouts, or focus state. The repair is idempotent, fail-closed, and deterministic. Session subscriber hardening is covered by a thorough test suite. The single finding is a cosmetic diagnostic string with no runtime impact. Files Needing Attention: No files require special attention. The diagnostic issue in src/renderer/src/App.tsx is cosmetic.
|
| Filename | Overview |
|---|---|
| src/renderer/src/lib/terminal-tab-projection-repair.ts | New orchestrator: collects candidates, runs bounded concurrent PTY liveness probes, applies mutations in deterministic candidate order. Handles abort, deadline, timeout, false, null, and rejection cleanly. |
| src/renderer/src/store/slices/terminal-tab-projection.ts | New pure function computing an exact-one projection patch with alias deduplication, group topology validation, and layout fixup. Patch is empty on unchanged or skipped paths. |
| src/renderer/src/store/slices/terminal-tab-projection-invariant.ts | New helper checking the exact-one projection invariant: one backing tab, one unified projection, correct group membership, layout coverage, single tab-order occurrence. |
| src/renderer/src/lib/session-write-subscriber.ts | Hardened: persist is async-aware, failed batches are restored and retried, suppression handled via self-scheduled polling, disposal prevents post-cleanup retries. |
| src/renderer/src/store/slices/tabs.ts | Adds ensureTerminalTabProjection store action calling set() only when the patch has keys, preventing no-op Zustand notifications. |
| src/renderer/src/App.tsx | Adds startup projection repair step after reconnect; fixes discarded localWrite promise so IPC write failures can be retried. |
| src/renderer/src/hooks/useIpcEvents.ts | Calls ensureTerminalTabProjection after IPC terminal adoption with structured error logging; errors are non-fatal so projection issues cannot block a successful PTY spawn reply. |
| src/main/persistence.ts | Minor comment clarification: main process documented as backing/binding/layout-only; renderer owns projection. No logic change. |
Reviews (3): Last reviewed commit: "fix(session): serialize durable projecti..." | Re-trigger Greptile
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 67f5e583-b481-4f19-a7fb-785a4bdd65af
📒 Files selected for processing (5)
src/renderer/src/App.tsxsrc/renderer/src/lib/session-write-subscriber.test.tssrc/renderer/src/lib/session-write-subscriber.tssrc/renderer/src/store/slices/tabs.test.tssrc/renderer/src/store/slices/tabs.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/renderer/src/App.tsx
- src/renderer/src/store/slices/tabs.test.ts
- src/renderer/src/store/slices/tabs.ts
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5041c01e-0bf2-495b-b121-d733e91a7520
📒 Files selected for processing (2)
src/renderer/src/lib/session-write-subscriber.test.tssrc/renderer/src/lib/session-write-subscriber.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/lib/session-write-subscriber.ts
|
Closing this submitted branch and routing the disappearing live-terminal projection behavior to canonical issue #15710. That issue owns the current unifiedTabs/tabGroups reconciliation work; we will carry the fix on current main. Full contributor credit is preserved for @lightofjeju. No action is requested from you. Thank you. |
Summary
Fixes a renderer state-synchronization race that could make existing live terminal sessions disappear from Orca after a background/non-focus CLI terminal was created.
The main process can durably create the terminal backing row and PTY binding before the renderer session writer runs. When the renderer subsequently adopted that row, it could skip tab creation and leave the renderer-owned
unifiedTabs/ tab-group projection missing. The PTY remained alive, but the UI no longer had a renderable projection.This change:
Screenshots
No visual styling change. This restores terminal tabs that should already be visible. Native Electron automation verifies exact-one projection recovery, unchanged foreground state, PTY survival, and buffered output replay on first visible mount.
Testing
pnpm lint— not run;pnpm check:code-quality:changedpassed with 0 new findings across all 16 changed filespnpm typecheckpnpm test— final branch used the focused suite below rather than the entire repository suitepnpm build— not invoked directly; the Electron Playwright run completed its application and bundled CLI build successfullyFocused verification on current
origin/main:pnpm check:code-quality:changedpassedpnpm check:max-lines-ratchetpassedgit diff --check origin/main...HEADpassedAI Review Report
The review covered architecture, product behavior, and code quality against the approved repair contract. It checked renderer/main ownership, exact-one projection invariants, focus preservation, startup ordering, IPC reply semantics, liveness failure handling, stale-binding races, destructive reconciliation, writer suppression, and native Electron behavior.
An independent red-team pass found a real deterministic-order blocker in the first implementation: sorted candidates were being applied in PTY probe completion order. The implementation was changed to collect bounded concurrent probe results first and then apply projection mutations synchronously in deterministic candidate order. A three-candidate/concurrency-two reversed-completion regression now pins both the pool boundary and final tab order. Final architecture review returned CLEAR/APPROVE and final red-team QA passed with no blockers.
GitHub automated review then identified three additional gaps: empty projection patches still notified Zustand subscribers, suppression recovery still depended on a later store mutation, and rejected local session writes could lose their captured field batch. The follow-up commit skips no-op
set()calls, self-schedules retained work until suppression lifts, returns and handles the local persistence Promise, restores and retries both synchronous and asynchronous failures, reports the first failure without log spam, and adds regressions for cleanup and concurrent in-flight changes.A second automated pass found that a retained batch could still be cleared if the hydration gate closed while its timer fired, and that multiple asynchronous local patches could overlap. The final follow-up keeps batches across gate closure and serializes Promise-backed writes; dedicated regressions cover gate-only reopen and deferred first-write completion.
Cross-platform compatibility was explicitly reviewed for macOS, Linux, and Windows. The change adds no shortcuts, labels, platform paths, shell commands, or OS-specific branches. It uses existing Electron IPC/store APIs and platform-neutral Promise/timer behavior; no platform-specific follow-up is required.
Security Audit
pty.hasPtycontracttrueliveness results can create UI projection state;false,null, rejection, timeout, deadline exhaustion, and abort all fail closedNo security blocker or follow-up was identified.
Notes
The affected sessions were not terminated; they became invisible because their renderer projection was absent. This PR repairs that projection while retaining the existing PTY lifecycle and main/renderer ownership boundary.