Skip to content

fix(native-chat): preserve current pane ownership through toggles and restore - #23049

Merged
OrcaWin merged 2 commits into
mainfrom
fix/native-chat-pane-ownership-followup
Sep 26, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
fix/native-chat-pane-ownership-followup

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​363 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​359
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​36 $\color{#cf222e}{\Huge{\mathbf{−}}}$​20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16

ELI5

After #22984, changing which split showed chat could still leave the old pane recorded as its owner. Turning chat off from the tab bar also retained that old owner, and remote servers never received the owner field. This follow-up keeps later layout saves and remote restores tied to the pane currently showing chat.

What Changed

  • Pane-manager callbacks now read the latest committed chat owner instead of the owner captured when the terminal first mounted. Resize and detach can no longer save the previous owner or resurrect one after chat is turned off.

  • The toggle guard now checks the current tab mode. It still protects an in-progress switch into chat, but lets an explicit tab-bar switch out of chat clear ownership.

  • Ownership changes trigger layout persistence. Remote layout updates carry an optional owner field through validation, host persistence, and the published snapshot. Omission preserves ownership for older clients; null explicitly clears it.

  • Layout saves and shutdown capture use the tab's configured mode, so a client with native chat disabled cannot erase the saved owner locally or on a remote host.

Why

Recreating the persistence callback was insufficient because the pane manager retains its mount-time callback. A stable callback reading committed state fixes those existing event paths without rebuilding terminals. Extending the existing remote layout update keeps ownership alongside the layout rather than introducing another synchronization channel.

Linked Issue

Follow-up to #22984 and the original report: closing right-hand chat moved chat onto the left terminal; restarting swapped the surfaces; closing the misplaced chat then targeted the wrong terminal.

Visual Proof

No Electron screenshots or manual rendered-app verification: the required $electron skill is unavailable in this environment. Automated reproductions below cover the ownership transitions; rendered Electron validation remains outstanding.

Testing

  • Reproduced three failing React lifecycle cases on the merged implementation: tab-bar mode changes, ownership transfer followed by a retained detach callback, and chat-off followed by a retained layout callback. All pass with the fix.

  • Reproduced the remote owner being lost across schema parsing and host persistence; verified save, older-client omission, cold rehydration, and explicit clear after the fix.

  • Added session round-trip coverage with the left pane active, chat on the right, and different numeric pane IDs after remount; closing chat leaves the left terminal in terminal mode.

  • Added a portal test verifying the close action targets the chat pane when its sibling is active.

  • 137 tests passed across 13 targeted suites. After strengthening the lifecycle tests with real Zustand subscriptions and adding disabled-client and batched-toggle coverage, the final focused run passed 53 tests across six suites.

  • Node, renderer, and CLI typechecks; changed-code quality gate; RPC parameter catalog verification.

  • Tests ran on macOS with ORCA_BACKGROUND_LAUNCH=1. No live SSH, Windows, Linux, or visible-window validation. Full suite and build deferred to CI.

  • I manually tested these changes locally

  • Automated tests added/updated

Review

Reviewed ownership from mode selection through pane-manager callbacks, shutdown capture, session parsing, portal close routing, and remote layout persistence.

Agent skill upstream boundary

  • Not applicable

Notes

The remote field is additive and optional. Old clients preserve the host's owner when updating geometry; old hosts continue to accept updates while ignoring the new field. No changes to process termination, filesystem paths, keyboard handling, or workspace identity.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots or videos attached (Electron skill unavailable; see Visual Proof)
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • Full lint, test suite, and build pass (targeted gates passed; remaining coverage is for CI)

@OrcaWin
OrcaWin merged commit 2ed6505 into main Sep 26, 2026
2 of 3 checks passed

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

Important

The local/renderer path looks correct and well covered, but the new remote owner field does not converge across clients: a client that never held the owner can clear it, and a client that already holds it never clears. Details below.

Reviewed changes

This is the follow-up to #22984 that keeps the native-chat owner (chatLeafId) tied to the pane currently showing chat across lifecycle events and the remote host.

  • Stable renderer persistence callback — use-terminal-pane-layout-persistence.ts reads the owner from a chatOwnerRef updated by useLayoutEffect, so the PaneManager's mount-retained persistLayoutSnapshot no longer saves the owner captured at mount, and a new effect persists on ownership changes.
  • Current-mode toggle guard — use-terminal-pane-chat-state.ts applyNativeChatLeafRoute now requires the store's current mode in addition to the render value, so an explicit tab-bar switch out of chat clears ownership.
  • Raw isChatViewMode for layout saves — both persistLayoutSnapshot and the shutdown capture in use-terminal-pane-title-effects.ts gate on the tab's configured mode, so a disabled-native-chat client preserves the owner.
  • Remote owner plumbing — UpdatePaneLayout gains optional nullable chatLeafId; the pusher sends layout.chatLeafId ?? null; the RPC handler, host persistHeadlessTerminalPaneLayout / applyHeadlessTerminalPaneLayoutToSnapshot, and updateMobileSessionPaneLayout forward it (undefined preserves, null clears).
  • Tests — new renderer lifecycle suite, remote-push owner cases, portal close-target routing, and a host RPC/persistence round-trip.

⚠️ A host-side owner clear never reaches a client that already holds the owner

The host collapses an explicit clear to an absent key, and a client that already knows an owner treats absence as "preserve," so cleared ownership can survive on other clients and be pushed back. The accompanying viewMode flip does not rescue this because a client with a prior tab never adopts the host's viewMode.

Technical details
# Explicit owner clear cannot round-trip through the published snapshot

## Affected sites
- `src/main/runtime/orca-runtime-persist-headless-session-tab-props.ts:135` and `:174` — a `null` clear is persisted/published as `undefined` (`args.chatLeafId ?? undefined`), so the wire carries no distinct clear marker.
- `src/main/runtime/mobile-session-layout-projection.ts:67` — `cloneTerminalLayoutSnapshot` only copies a truthy `chatLeafId`, so any later host rebuild drops it too.
- `src/renderer/src/runtime/web-session-tabs-sync/terminal-surfaces.ts:203-208` — `chooseRemoteTerminalLayout` treats an absent `parentLayout.chatLeafId` as a fallback to `existingLayout.chatLeafId`, i.e. "keep my stale owner."
- `src/renderer/src/runtime/web-session-tabs-sync/terminal-build.ts:162` — `viewMode = existing ? existing.viewMode : hostViewModeSurface?.viewMode`: a client with a prior tab never adopts the host's `viewMode`, so it stays in chat and keeps re-emitting the stale owner.

## Reachable sequence
1. Client B holds `terminalLayoutsByTabId[id].chatLeafId = X` (set locally or from an earlier snapshot) and `viewMode` stays `'chat'` because of the sticky rule above.
2. Client A turns chat off; the pusher sends `chatLeafId: null`; the host persists/publishes the clear as an absent field.
3. B receives the snapshot, falls back to its stored `X`, and `terminalLayoutEqual` sees no change — B silently keeps chat on `X`.
4. Once B's layout changes for any reason, its push sends `chatLeafId: X` back, re-establishing the cleared owner host-wide.

## Required outcome
- A host-side clear must be distinguishable on the wire from "host never had an owner / older host omitted it," so a client that already holds an owner can honor the clear instead of retaining it.
- Existing clients that genuinely predate the field must still preserve the host's owner.

## Suggested approach (optional)
- Keep `null` in the published `parentLayout.chatLeafId` (widen the snapshot type/schema) and have `chooseRemoteTerminalLayout` treat an explicit `null` as a clear while treating key absence as legacy-preserve.

## Open questions for the human (optional)
- Is cross-client owner convergence intended for this follow-up, or is the multi-client case explicitly out of scope?

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

tabId,
root: layout.root,
expandedLeafId: layout.expandedLeafId,
chatLeafId: layout.chatLeafId ?? null,

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.

chatLeafId: layout.chatLeafId ?? null turns every geometry-only persist from a client that has no owner into an explicit host-side clear. This pusher fires on resize/detach/expand, and updateMobileSessionPaneLayout treats null as a clear, so a second client sitting in terminal mode (whose sticky viewMode never adopts the host's chat) wipes an owner another client set. null should mean "I am clearing an owner I held"; when this client simply has no owner, omitting the field is the signal that preserves.

Technical details
# Conflating "no owner" with "clear the owner"

## Affected sites
- `src/renderer/src/components/terminal-pane/remote-pane-layout-push.ts:38` — always emits `layout.chatLeafId ?? null`.
- `src/main/runtime/orca-runtime-persist-headless-session-tab-props.ts:135` — `args.chatLeafId !== undefined` means a `null` clears the persisted owner.
- `src/renderer/src/components/terminal-pane/use-terminal-pane-layout-persistence.ts:60` — `persistLayoutSnapshot` omits `chatLeafId` whenever `isChatViewMode && chatLeafId && mounted` is false, so an ownerless client's layout has no field and the pusher converts that to `null`.

## Required outcome
- A geometry-only update from a client with no owner knowledge must not clear the host owner; only a client actually relinquishing an owner it held may send the clear.

## Suggested approach (optional)
- Omit `chatLeafId` when the local layout has none, and track an explicit "owner cleared" transition separate from "owner absent" to drive the clearing push.

Jinwoo-H added a commit that referenced this pull request Sep 26, 2026
#23049 added a useRef, a useLayoutEffect and a useEffect to the terminal pane's
chat-state, layout-persistence and title-effects hooks and merged with the
parity shard red, so main fails 'preserves the recursively flattened render
hook order' (211 vs 214). Pin 214 hooks, 7 useMemo, and the new order hash.

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
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