Repository navigation
fix(native-chat): keep terminal pane chat ownership stable - #22984
Conversation
There was a problem hiding this comment.
Important
The persisted chat owner is not reliably written: terminalLayoutEqual ignores chatLeafId, so setTabLayout bails out and the new persist effect becomes a no-op whenever chat ownership changes without a topology change. Restore-after-restart then depends on an unrelated field (a shutdown/park buffer capture) happening to differ in the same write.
Reviewed changes
- Routing exits chat on pane close —
resolveNativeChatLeafRoutegains a branch after the hydration guard: a setchatLeafIdwhose pane is no longer mounted, with no confirmed agent exit, now returns{chatLeafId: null, exitChat: true}rather than retargeting to the active sibling. The confirmed-agent-exit handoff path is preserved. - Owner persisted on the layout —
chatLeafId?: stringonTerminalLayoutSnapshot, declared optional in the workspace-session schema, written bycaptureTerminalShutdownLayoutand a new layout-persistence effect (only whileeffectiveChatViewModeand the pane is mounted), and seeded back into state by theuseStateinitializer. - Restore and shutdown capture tests — new schema round-trip case plus shutdown-capture and routing assertions.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughTerminal layout snapshots now store and restore the native chat leaf ID. Persistence and shutdown capture record the ID only when chat view is effective and the leaf is mounted. Layout normalization and synchronization preserve or remap the ID. When the chat leaf closes without a confirmed agent exit, routing clears its ID and exits chat instead of moving chat to an active sibling. Priority: ➖ Normal Merge Risk: 🔵 Low · up to Chat ownership can remain stale after a view toggle or reappear on a web client after the host clears it. Both are bounded issues, but they should be fixed or explicitly accepted before merging. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 1 system. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description covers the change, rationale, testing, visual proof, compatibility notes, and checklist. However, it does not provide the required linked issue; it explicitly states that no tracker issue was provided.
✨ 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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 5d02f00d-ec51-4b01-bfda-c5f43fc099ae
📥 Commits
Reviewing files that changed from the base of the PR and between 1c2cf12 and 34c835acda2cbcc86017dd15cd27a8358ba3e2cf.
📒 Files selected for processing (10)
src/renderer/src/components/native-chat/native-chat-leaf-routing.test.tssrc/renderer/src/components/native-chat/native-chat-leaf-routing.tssrc/renderer/src/components/terminal-pane/terminal-shutdown-layout-capture.test.tssrc/renderer/src/components/terminal-pane/terminal-shutdown-layout-capture.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-foundation.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-layout-persistence.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-title-effects.tssrc/shared/terminal-tab-types.tssrc/shared/workspace-session-schema.tssrc/shared/workspace-session-terminal-schema.test.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.
| const [chatLeafId, setChatLeafId] = useState<string | null>( | ||
| () => useAppStore.getState().terminalLayoutsByTabId[tabId]?.chatLeafId ?? null | ||
| ) |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '105,145p' src/renderer/src/components/terminal-pane/use-terminal-pane-foundation.ts
sed -n '40,75p' src/renderer/src/components/terminal-pane/use-terminal-pane-layout-persistence.ts
sed -n '115,145p' src/renderer/src/components/terminal-pane/use-terminal-pane-layout-persistence.ts
sed -n '135,170p' src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.ts
sed -n '180,210p' src/renderer/src/hooks/remote-workspace-snapshot-apply.ts
sed -n '230,270p' src/renderer/src/hooks/remote-workspace-session-merge.ts
sed -n '65,115p' src/renderer/src/store/terminals/terminal-layout-state.tsRepository: stablyai/orca
Length of output: 11327
🏁 Script executed:
#!/bin/bash
set -eu
rg -n -C 5 'setChatLeafId|chatLeafId|applyNativeChatLeafRoute|NativeChatLeafRoute' \
src/renderer/src/components/terminal-pane/use-terminal-pane-foundation.ts \
src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.ts \
src/renderer/src/components/terminal-pane/use-terminal-pane-layout-persistence.ts \
src/renderer/src/store/terminals/terminal-layout-state.ts \
src/renderer/src | head -n 500Repository: stablyai/orca
Length of output: 42079
Restore remote ownership without undoing a local clear.
A mounted foundation can miss a chatLeafId added by late remote hydration. A later persistence write can then replace that layout without the restored owner.
Do not use current ?? savedChatLeafId. Both an uninitialized owner and an explicit local clear use null, so this effect can restore stale ownership after setChatLeafId(null). Synchronize the saved owner only before local state has been explicitly set or cleared.
34c835a to
a55e44a
Compare
There was a problem hiding this comment.
ℹ️ No critical issues — the two prior findings are resolved; one minor coverage suggestion below.
Reviewed changes
Reviewed the single commit since the prior pullfrog review (34c835a → a55e44a), which resolves both prior threads and extends owner persistence across every layout transform.
- Owner survives the store bailout —
terminalLayoutEqualnow compareschatLeafId, so a chatLeafId-onlysetTabLayoutpublishes; the identity-bailout test adds the matching mutation case. - Owner remapped through leaf-ID rewrites —
normalizeTerminalLayoutLeafIds,normalizeTerminalLayoutPtyOwnership, and the main-processnormalizeTerminalLayoutSnapshotForPersistencenow carrychatLeafIdalongside the other leaf-keyed records instead of letting it fall through the spread. - Ownership written from the route effect —
applyNativeChatLeafRoutewrites the owner intoterminalLayoutsByTabIddirectly and returns early while chat view is off, keeping the persist path off an unrelated field. - Owner carried across layout transforms —
detachTerminalLayoutLeaf,cloneTerminalLayoutSnapshot, the mobile tab projection, andchooseRemoteTerminalLayoutpreservechatLeafId(the remote chooser retaining the client's owner when the host publishes none).
ℹ️ Nitpicks
- The new remap/transfer handling for
chatLeafId(normalizeTerminalLayoutLeafIds,normalizeTerminalLayoutPtyOwnership,normalizeTerminalLayoutSnapshotForPersistence,detachTerminalLayoutLeaf,chooseRemoteTerminalLayout) is exercised only indirectly. A fixture that duplicates a leaf ID and asserts the rewritten owner would lock in the invariant the prior review asked to maintain.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: caa49c16-bc51-472a-842e-728ab5339bf6
📥 Commits
Reviewing files that changed from the base of the PR and between 34c835acda2cbcc86017dd15cd27a8358ba3e2cf and a55e44a.
📒 Files selected for processing (11)
src/main/persistence/restoring-sessions/terminal-layout-normalization.tssrc/main/runtime/mobile-session-layout-projection.tssrc/renderer/src/components/terminal-pane/terminal-layout-leaf-detach.tssrc/renderer/src/components/terminal-pane/terminal-layout-leaf-ids.tssrc/renderer/src/components/terminal-pane/terminal-layout-pty-ownership.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.tssrc/renderer/src/components/terminal-pane/use-terminal-pane-layout-persistence.tssrc/renderer/src/lib/terminal-layout-equality.tssrc/renderer/src/runtime/sync-runtime-graph/mobile-session-terminal-tabs.tssrc/renderer/src/runtime/web-session-tabs-sync/terminal-surfaces.tssrc/renderer/src/store/slices/terminal-write-identity-bailouts.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
| if (!isChatViewMode && chatLeafId && route.chatLeafId === null) { | ||
| // Keep the owner through the batched toggle that turns chat mode on. | ||
| return | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- diff ---'
git diff --unified=35 8d21fdbf604f0c459c50ed803893de155b002e83 a55e44aaa250d240773d7b773698fbd5c37b05e2 -- src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.ts
printf '%s\n' '--- outline ---'
ast-grep outline src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.ts
printf '%s\n' '--- targeted symbols ---'
rg -n -C 5 'isChatViewMode|chatLeafId|applyNativeChatLeafRoute|setTabLayout|setChatViewMode' src/renderer/src/components/terminal-pane src/renderer/src -g '*.{ts,tsx}'
printf '%s\n' '--- relevant files ---'
git ls-files | rg 'terminal-pane|chat.*state|route'Repository: stablyai/orca
Length of output: 45664
🤖 get_repo_knowledge executed:
get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions
Length of output: 39089
🏁 Script executed:
#!/bin/bash
set -e
git diff --unified=35 8d21fdbf604f0c459c50ed803893de155b002e83 a55e44aaa250d240773d7b773698fbd5c37b05e2 -- src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.ts
printf '%s\n' '--- symbols ---'
rg -n -C 6 'isChatViewMode|chatLeafId|applyNativeChatLeafRoute|setTabLayout|setChatViewMode' src/renderer/src/components/terminal-pane src/renderer/src -g '*.{ts,tsx}'Repository: stablyai/orca
Length of output: 45664
🏁 Script executed:
#!/bin/bash
set -e
git diff --unified=30 8d21fdbf604f0c459c50ed803893de155b002e83 a55e44aaa250d240773d7b773698fbd5c37b05e2 -- src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.ts
rg -n -C 8 'isChatViewMode|chatLeafId|applyNativeChatLeafRoute|setChatViewMode|toggleChat' src/renderer/src/components/terminal-pane src/renderer/src -g '*.{ts,tsx}'Repository: stablyai/orca
Length of output: 45664
🏁 Script executed:
pwd; git diff --unified=25 8d21fdbf604f0c459c50ed803893de155b002e83 a55e44aaa250d240773d7b773698fbd5c37b05e2 -- src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.ts; rg -n -C 5 'isChatViewMode|applyNativeChatLeafRoute|chatLeafId' src/renderer/src/components/terminal-pane -g '*.{ts,tsx}'Repository: stablyai/orca
Length of output: 42067
🌐 Web query:
"stablyai/orca" "use-terminal-pane-chat-state.ts"
💡 Result:
I couldn’t find `use-terminal-pane-chat-state.ts` in `stablyai/orca` from the search results. Are you looking for the file’s contents, its purpose, or a related issue/commit? [1]
🏁 Script executed:
#!/bin/bash
set -e
file=src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.ts
printf '%s\n' '--- chat state 130-285 ---'
sed -n '130,285p' "$file"
printf '%s\n' '--- chat state 285-380 ---'
sed -n '285,380p' "$file"
printf '%s\n' '--- mode and route call sites ---'
rg -n -C 12 'setTabViewMode|toggleTabViewMode|resolveNativeChatLeafRoute|applyNativeChatLeafRoute|handleToggleNativeChat|toggleNativeChatForLeaf' src/renderer/src/components/terminal-pane -g '*.{ts,tsx}'Repository: stablyai/orca
Length of output: 41803
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- chat state relevant sections ---'
nl -ba src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.ts | sed -n '145,275p'
printf '%s\n' '--- all terminal-pane mode actions ---'
rg -n -C 10 'setTabViewMode\(|toggleTabViewMode\(' src/renderer/src/components/terminal-pane -g '*.{ts,tsx}' | head -n 500
printf '%s\n' '--- route projection references ---'
rg -n -C 14 'resolveNativeChatLeafRoute|applyNativeChatLeafRoute' src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.tsRepository: stablyai/orca
Length of output: 18797
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- relevant chat-state lines ---'
nl -ba src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.ts | sed -n '145,275p'
printf '%s\n' '--- direct mode-action callers in repository ---'
rg -n -C 8 'setTabViewMode\(|toggleTabViewMode\(' src/renderer/src -g '*.{ts,tsx}' | rg -v 'use-terminal-pane-store-actions.ts|use-terminal-pane-chat-state.ts' | head -n 300
printf '%s\n' '--- route projection in chat state ---'
rg -n -C 18 'resolveNativeChatLeafRoute|applyNativeChatLeafRoute' src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.tsRepository: stablyai/orca
Length of output: 24549
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- resolver ---'
nl -ba src/renderer/src/components/native-chat/native-chat-leaf-routing.ts | sed -n '1,240p'
printf '%s\n' '--- tab bar toggle ---'
nl -ba src/renderer/src/components/tab-bar/tab-bar-item-surface.tsx | sed -n '105,145p'
printf '%s\n' '--- keyboard toggle ---'
nl -ba src/renderer/src/components/native-chat/use-native-chat-toggle-shortcut.ts | sed -n '55,110p'Repository: stablyai/orca
Length of output: 10245
🏁 Script executed:
#!/bin/bash
set -e
rg -n -C 12 'toggleTabViewMode|setTabViewMode' src/renderer/src/store/slices/tab-view-mode.ts src/renderer/src/store -g '*.ts' | head -n 240Repository: stablyai/orca
Length of output: 18886
Limit the owner-preservation guard to the pending chat toggle.
The tab bar and keyboard shortcut toggle only the tab view mode. They can switch to terminal mode while chatLeafId remains set. The route resolver then returns chatLeafId: null, and the current guard skips both component and saved-layout cleanup. Apply the exception only during the pending toggle into chat.
| const chatLeafId = | ||
| parentLayout?.chatLeafId && knownLeafIds.has(parentLayout.chatLeafId) | ||
| ? parentLayout.chatLeafId | ||
| : existingLayout?.chatLeafId && knownLeafIds.has(existingLayout.chatLeafId) | ||
| ? existingLayout.chatLeafId | ||
| : undefined |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '175,245p' src/renderer/src/runtime/web-session-tabs-sync/terminal-surfaces.ts
rg -n 'chooseRemoteTerminalLayout|applyNativeChatLeafRoute|chatLeafId' src/renderer/src/runtime/web-session-tabs-sync src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.tsRepository: stablyai/orca
Length of output: 8255
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- terminal-surfaces definitions and callers ---'
sed -n '130,240p' src/renderer/src/runtime/web-session-tabs-sync/terminal-surfaces.ts
sed -n '1,180p' src/renderer/src/runtime/web-session-tabs-sync/terminal-build.ts
printf '%s\n' '--- route application and surrounding state ---'
sed -n '1,290p' src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.ts
printf '%s\n' '--- parentLayout/existingLayout and publication references ---'
rg -n -C 4 'parentLayout|existingLayout|publish.*layout|terminalLayout|chatLeafId' src/renderer/src/runtime/web-session-tabs-sync src/renderer/src/components/terminal-pane --glob '*.{ts,tsx}'
printf '%s\n' '--- changed files against supplied merge base ---'
git diff --stat 8d21fdbf604f0c459c50ed803893de155b002e83 a55e44aaa250d240773d7b773698fbd5c37b05e2 -- src/renderer/src/runtime/web-session-tabs-sync src/renderer/src/components/terminal-paneRepository: stablyai/orca
Length of output: 45659
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- parentLayout declarations and assignments ---'
rg -n -C 3 'parentLayout' src --glob '*.{ts,tsx}' --glob '!**/*.test.*'
printf '%s\n' '--- buildMirroredTerminalTabs callers ---'
rg -n -C 5 'buildMirroredTerminalTabs|existingLayoutsByTabId' src/renderer/src/runtime src/renderer/src --glob '*.{ts,tsx}' --glob '!**/*.test.*'
printf '%s\n' '--- layout publication implementation ---'
cat -n src/renderer/src/components/terminal-pane/remote-pane-layout-push.ts
sed -n '185,275p' src/renderer/src/components/terminal-pane/use-terminal-pane-title-effects.ts
printf '%s\n' '--- host snapshot and route-related symbols ---'
rg -n -C 5 'updateWebRuntimePaneLayout|web.*session.*tabs|parent.*layout|chatLeafId' src/renderer/src/runtime src/shared --glob '*.{ts,tsx}' --glob '!**/*.test.*'
printf '%s\n' '--- PR hunks for implicated files ---'
git diff --unified=35 8d21fdbf604f0c459c50ed803893de155b002e83 a55e44aaa250d240773d7b773698fbd5c37b05e2 -- \
src/renderer/src/runtime/web-session-tabs-sync/terminal-surfaces.ts \
src/renderer/src/runtime/web-session-tabs-sync/terminal-build.ts \
src/renderer/src/components/terminal-pane/use-terminal-pane-chat-state.ts \
src/renderer/src/components/terminal-pane/use-terminal-pane-title-effects.ts \
src/renderer/src/components/terminal-pane/remote-pane-layout-push.tsRepository: stablyai/orca
Length of output: 41575
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- host parent layout construction ---'
cat -n src/renderer/src/runtime/sync-runtime-graph/mobile-session-terminal-tabs.ts | sed -n '1,145p'
printf '%s\n' '--- mobile projection ---'
cat -n src/main/runtime/mobile-session-terminal-projection.ts | sed -n '1,90p'
printf '%s\n' '--- exact mirrored-tab build caller ---'
rg -n -C 12 'buildMirroredTerminalTabs' src/renderer/src --glob '*.{ts,tsx}' --glob '!**/*.test.*'
printf '%s\n' '--- updateWebRuntimePaneLayout bindings and callers ---'
rg -n -C 12 'updateWebRuntimePaneLayout' src/renderer/src --glob '*.{ts,tsx}' --glob '!**/*.test.*'
printf '%s\n' '--- layout push and state persistence ---'
cat -n src/renderer/src/components/terminal-pane/remote-pane-layout-push.ts
rg -n -C 10 'createRemotePaneLayoutPusher|remotePaneLayoutPusher|\.push\(\{.*layout|layoutPusher' src/renderer/src --glob '*.{ts,tsx}' --glob '!**/*.test.*'Repository: stablyai/orca
Length of output: 42220
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- layout persistence construction ---'
cat -n src/renderer/src/components/terminal-pane/use-terminal-pane-layout-persistence.ts | sed -n '35,140p'
printf '%s\n' '--- update action body ---'
cat -n src/renderer/src/runtime/web-runtime-terminal-actions.ts | sed -n '190,255p'
printf '%s\n' '--- snapshot application around layout input ---'
cat -n src/renderer/src/runtime/web-session-tabs-sync/apply-preparation-base.ts | sed -n '110,180p'
printf '%s\n' '--- focused tests and route contract ---'
rg -n -C 8 'chooseRemoteTerminalLayout|chatLeafId|resolveNativeChatLeafRoute|applyNativeChatLeafRoute' src/renderer/src/runtime/web-session-tabs-sync src/renderer/src/components/terminal-pane --glob '*.{test.ts,test.tsx}'
printf '%s\n' '--- route implementation ---'
cat -n src/renderer/src/components/native-chat/native-chat-leaf-routing.ts | sed -n '1,220p'Repository: stablyai/orca
Length of output: 19924
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- snapshot application state write ---'
cat -n src/renderer/src/runtime/web-session-tabs-sync/apply-preparation-base.ts | sed -n '165,260p'
printf '%s\n' '--- chatLeafId consumers and initialization ---'
rg -n -C 8 'chatLeafId|setChatLeafId' src/renderer/src/components/terminal-pane src/renderer/src/runtime/web-session-tabs-sync --glob '*.{ts,tsx}' --glob '!**/*.test.*'
printf '%s\n' '--- terminal surface tests/files ---'
find src/renderer/src/runtime/web-session-tabs-sync -maxdepth 1 -type f -printf '%f\n' | sort
rg -n -C 10 'chooseRemoteTerminalLayout|parentLayout.*chat|chatLeafId' src/renderer/src/runtime/web-session-tabs-sync --glob '*test*'
printf '%s\n' '--- layout setter definition ---'
rg -n -C 10 'setTabLayout' src/renderer/src/store src/renderer/src --glob '*.{ts,tsx}' --glob '!**/*.test.*' | head -n 240Repository: stablyai/orca
Length of output: 41877
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- mirrored terminal tab layout return ---'
cat -n src/renderer/src/runtime/web-session-tabs-sync/terminal-build.ts | sed -n '90,180p'
printf '%s\n' '--- apply mirrored terminal records/layout ---'
rg -n -C 12 'terminalLayoutsByTabId|layout|mirroredTerminalTabs|apply.*terminal' src/renderer/src/runtime/web-session-tabs-sync/apply-terminal-records.ts src/renderer/src/runtime/web-session-tabs-sync/apply-final-patch.ts src/renderer/src/runtime/web-session-tabs-sync/apply-snapshot.tsRepository: stablyai/orca
Length of output: 30352
Do not fall back to existingLayout.chatLeafId when parentLayout is present.
The host publishes a parentLayout without chatLeafId after the owner exits. If the client still has the old owner in existingLayout, this branch restores it because it only checks whether the parent field is valid. Keep the fallback only when parentLayout is absent.
Suggested fix
const chatLeafId =
- parentLayout?.chatLeafId && knownLeafIds.has(parentLayout.chatLeafId)
- ? parentLayout.chatLeafId
- : existingLayout?.chatLeafId && knownLeafIds.has(existingLayout.chatLeafId)
- ? existingLayout.chatLeafId
- : undefined
+ parentLayout
+ ? parentLayout.chatLeafId && knownLeafIds.has(parentLayout.chatLeafId)
+ ? parentLayout.chatLeafId
+ : undefined
+ : existingLayout?.chatLeafId && knownLeafIds.has(existingLayout.chatLeafId)
+ ? existingLayout.chatLeafId
+ : undefined📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const chatLeafId = | |
| parentLayout?.chatLeafId && knownLeafIds.has(parentLayout.chatLeafId) | |
| ? parentLayout.chatLeafId | |
| : existingLayout?.chatLeafId && knownLeafIds.has(existingLayout.chatLeafId) | |
| ? existingLayout.chatLeafId | |
| : undefined | |
| const chatLeafId = | |
| parentLayout | |
| ? parentLayout.chatLeafId && knownLeafIds.has(parentLayout.chatLeafId) | |
| ? parentLayout.chatLeafId | |
| : undefined | |
| : existingLayout?.chatLeafId && knownLeafIds.has(existingLayout.chatLeafId) | |
| ? existingLayout.chatLeafId | |
| : undefined |

ELI5
Closing the chat side of a split terminal used to make the remaining terminal inherit chat. Restarting then had no stable record of which split owned chat, so the panes could come back reversed and a later close could target the wrong terminal.
What Changed
Why
The old close path treated a missing chat pane and an agent process exit as the same event. They have different user intent: a close ends the chat surface, while an agent exit can hand off to another eligible agent. Persisting the stable owner avoids guessing from mount order after restart.
Linked Issue
No tracker issue was provided; this PR addresses the reported terminal/chat pane close and restart behavior.
Visual Proof
N/A — the fix changes pane ownership and persistence state; the rendered controls and styling are unchanged.
Testing
pnpm tc:webpnpm test src/renderer/src/components/native-chat/native-chat-leaf-routing.test.ts src/renderer/src/components/terminal-pane/layout-serialization.test.ts src/renderer/src/components/terminal-pane/terminal-pane-surface-ownership.test.ts src/renderer/src/components/terminal-pane/TerminalPaneHeaderOverlay.test.tsx src/renderer/src/components/terminal-pane/terminal-shutdown-layout-capture.test.ts src/shared/workspace-session-terminal-schema.test.tspnpm run check:code-quality:changedmacOS renderer tests; SSH and mobile wire behavior is unchanged and the added layout field is optional.
Automated tests added/updated
Review
Agent skill upstream boundary
Notes
The new layout field is optional for older sessions and additive for remote payloads.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (targeted checks pass; CI will run the full suite)