Skip to content

Fix quit blocked when a remote host session has no terminal tabs - #25925

Closed
silee9019 wants to merge 1 commit into
stablyai:mainfrom
silee9019:fix/remote-host-stage-missing-tabs
Closed

silee9019 wants to merge 1 commit into
stablyai:mainfrom
silee9019:fix/remote-host-stage-missing-tabs

Conversation

@silee9019

Copy link
Copy Markdown
Contributor

ELI5

When you quit Orca, it saves a snapshot of every host's tabs first. If one of your paired remote runtimes has no terminal tabs open, saving that runtime's snapshot crashed. The crash cancelled the quit, so Cmd+Q, closing the window, and "Restart to update" all failed on the first try. This PR makes the save treat "no tabs listed" as "no tabs", so quitting works on the first try again.

What Changed

Before (user-visible): On the first Cmd+Q, window close, or update restart, Orca shows Renderer shutdown checkpoint was not completed: Failed to stage renderer state before unload. and stays open. A second attempt quits only because it skips saving the session.

After: The first attempt saves the session and quits.

Mechanism: The renderer splits the session by owning host before the quit stage (splitWorkspaceSessionByHost). A remote host's slice gets tabsByWorktree only when some worktree routes to that host, so a paired runtime with no terminal tabs sends a slice without that key. In the main process, setHostWorkspaceSession → sanitizeWorkspaceSessionTerminalRetirements → rebaseWorkspaceSessionTerminalMembership runs whenever the prior partition has terminalTopologyRevisionByRepoId (an empty {} counts). It then called Object.keys(incoming.tabsByWorktree) and threw TypeError: Cannot convert undefined or null to object. rebaseWorkspaceSessionTerminalMembership now reads incoming.tabsByWorktree ?? {} and prior.tabsByWorktree ?? {} at every access, and the prior partition's tabs are kept.

Why

The main process already accepts partial renderer payloads on this path. The debounced patch path sends partial slices too, and setHostWorkspaceSession exists to rebase them onto the stored partition. rebaseWorkspaceSessionTerminalMembership is the one function every host-partition writer goes through, so a guard there also covers future senders that omit the key. I considered making the renderer always add an empty tabsByWorktree to every remote slice. That would fix only this one sender and leave the main-process invariant unenforced.

Linked Issue

Fixes #25924

Visual Proof

N/A for screenshots: nothing on screen changes, only whether the app quits. Below is the main-process log for the same quit on the same profile. The profile is a copy of a real one with two paired runtimes, one of them with no terminal tabs. Remote endpoints were pointed at an unreachable address so that no live runtime was touched. Each build was quit once, by sending a quit request and clicking "Close" in the "remote host unreachable" confirmation.

Before (main at 7faa9f7cd3, pnpm dev):

[app] Failed to stage renderer state before unload: TypeError: Cannot convert undefined or null to object
    at Object.keys (<anonymous>)
    at wKe (out/main/index.js:224:52618)
    at AKe (out/main/index.js:224:57710)
    at GKe (out/main/index.js:224:62511)
    at NZe.stageWorkspaceSessionBeforeUnload (out/main/index.js:224:66419)
→ app still running after the quit request

After (this branch, pnpm dev; also a packaged arm64 build of v1.4.221 with only this commit cherry-picked):

(no "Failed to stage renderer state" line)
→ app exited after the first quit request

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

New test src/main/persistence/loading-store/store-host-partition-partial-stage.test.ts drives the real Store. It seeds a runtime: host partition that has a tab and terminalTopologyRevisionByRepoId, then stages a slice without tabsByWorktree through stageWorkspaceSessionBeforeUnload. It asserts that the call does not throw and that the prior tab is kept.

Check Command Result
New test without the fix (origin/main cad8ea4fa7 source) pnpm test src/main/persistence/loading-store/store-host-partition-partial-stage.test.ts exit 1, TypeError: Cannot convert undefined or null to object
New test + related suites with the fix pnpm test <new test> workspace-session-membership-scaling.test.ts mobile-session-terminal-persistence-retirement.test.ts store-runtime-authored-session-writes.test.ts renderer-shutdown-checkpoint.test.ts exit 0, 5 files / 26 tests passed
Typecheck pnpm tc:node exit 0
Changed-code gates pnpm run check:code-quality:changed, oxlint, oxfmt --check on the changed files exit 0

Platforms: macOS (arm64) only. The change is platform-independent main-process code. I did not run full pnpm lint, pnpm build, or the full pnpm test locally, and I am relying on CI for those.

AI Disclosure

The investigation and the fix were done with Claude Opus 5.5 (claude-opus-5-5). The test and fix were drafted by Claude Sonnet 5.5. I reviewed the change and ran the verification above.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

The persisted format and the IPC payloads are unchanged. The guard only changes behavior when tabsByWorktree is missing, which is exactly the case that used to throw.

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)

@coderabbitai

coderabbitai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 5093cd7a-df2a-4498-9ba3-61bfd377e246
📥 Commits

Reviewing files that changed from the base of the PR and between cad8ea4 and 828000d.

📒 Files selected for processing (2)
  • src/main/persistence/loading-store/store-host-partition-partial-stage.test.ts
  • src/main/runtime/workspace-session-terminal-membership-authority.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

The rebasing logic now treats missing tabsByWorktree maps on either session as empty maps during worktree collection and tab reconciliation. A store test stages a renderer slice without tabsByWorktree and checks that staging does not throw and the host tab remains.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 82800

Missing terminal-tab maps no longer prevent host-session staging from completing. The focused test covers the reported case, and no concrete merge-blocking risk remains.

🚥 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 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the primary fix: quitting is no longer blocked when a remote host session has no terminal tabs.
Description check ✅ Passed The description covers the required sections with clear user impact, technical cause and fix, linked issue, visual-proof rationale, testing results, platform scope, and checklist. It notes that full l…
Linked Issues check ✅ Passed Issue #25924 requires host-session staging to tolerate a remote slice without tabsByWorktree and preserve prior tabs. rebaseWorkspaceSessionTerminalMembership now defaults both incoming and prior …
Out of Scope Changes check ✅ Passed The PR changes only the host-session rebasing logic and adds a regression test for the #25924 failure. Both changes directly support the linked issue. No unrelated changes appear in the whole-PR diff.
  • Fix all pre-merge checks with AI
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

nwparker added a commit that referenced this pull request Oct 9, 2026
Records the retained adapted contribution from #25925 in replacement PR #26848.

Co-authored-by: Sangin <[email protected]>
@OrcaWin

OrcaWin commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Thank you @silee9019 for tracking this down and for the clear write-up and repro. The same quit-time crash (#25924) was fixed by #26848, which landed first: it fills in the missing tab maps at the start of the shared host-session save (setHostWorkspaceSession), so both the incoming slice and any older saved copy are covered before the terminal-membership rebase reads them. Your diagnosis matched it exactly. Since main already has the fix, I'm closing this one as superseded. We really appreciate the contribution.

@OrcaWin OrcaWin closed this Oct 11, 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.

[Bug]: Quit and update restart are cancelled with "Failed to stage renderer state before unload" when a paired runtime has no terminal tabs

2 participants