Skip to content

fix(native-chat): keep terminal pane chat ownership stable - #22984

Merged
OrcaWin merged 1 commit into
mainfrom
OrcaWin/np-buggy-panes
Sep 26, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
OrcaWin/np-buggy-panes

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​29 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25
Prod 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​85 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​79

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

  • A user-closed chat pane now exits chat instead of moving chat to the active sibling.
  • The chat-owning stable pane ID is saved with the terminal layout and restored before native chat chooses a pane.
  • Shutdown capture and session parsing preserve that owner across restart.

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:web

  • pnpm 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.ts

  • pnpm run check:code-quality:changed

  • macOS 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

  • Not applicable

Notes

The new layout field is optional for older sessions and additive for remote payloads.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • 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 (targeted checks pass; CI will run the full suite)

@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 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 — resolveNativeChatLeafRoute gains a branch after the hydration guard: a set chatLeafId whose 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?: string on TerminalLayoutSnapshot, declared optional in the workspace-session schema, written by captureTerminalShutdownLayout and a new layout-persistence effect (only while effectiveChatViewMode and the pane is mounted), and seeded back into state by the useState initializer.
  • Restore and shutdown capture tests — new schema round-trip case plus shutdown-capture and routing assertions.

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

Comment thread src/shared/terminal-tab-types.ts Resolved
@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

Terminal 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 a55e4

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 Summary

Architecture risk: 🔵 Low · up to a55e4

The change affects 1 system.

Changed systems: src

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (ui) was modified; 20 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in src/renderer/src/components/native-chat/native-chat-leaf-routing.test.ts: Renames the test case from moving chat to an eligible sibling after the chat leaf closes to exiting chat when the user closes its pane.
  • observed — Modified behavior in src/renderer/src/components/native-chat/native-chat-leaf-routing.test.ts: Changes the expected route after the chat leaf closes from attaching chat to the eligible sibling to clearing leaf ownership and exiting chat.
  • observed — Modified behavior in src/renderer/src/components/native-chat/native-chat-leaf-routing.ts: When the chat leaf is unmounted without a confirmed agent exit, the route now clears chatLeafId and exits chat instead of allowing the active sibling to receive the chat surface.
  • observed — Modified behavior in src/renderer/src/components/terminal-pane/terminal-shutdown-layout-capture.test.ts: The capture input now includes chatLeafId set to the test leaf ID.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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 is… Add the issue reference after "Fixes #". If no issue exists, create or link the required tracking issue before merging.
Docstring Coverage ⚠️ Warning Docstring coverage is 7.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 20 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preserving terminal pane chat ownership.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

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

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.ts
  • src/renderer/src/components/native-chat/native-chat-leaf-routing.ts
  • src/renderer/src/components/terminal-pane/terminal-shutdown-layout-capture.test.ts
  • src/renderer/src/components/terminal-pane/terminal-shutdown-layout-capture.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-foundation.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-layout-persistence.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-title-effects.ts
  • src/shared/terminal-tab-types.ts
  • src/shared/workspace-session-schema.ts
  • src/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.

Comment on lines +126 to +128
const [chatLeafId, setChatLeafId] = useState<string | null>(
() => useAppStore.getState().terminalLayoutsByTabId[tabId]?.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.

🗄️ 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.ts

Repository: 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 500

Repository: 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.

@OrcaWin
OrcaWin force-pushed the OrcaWin/np-buggy-panes branch from 34c835a to a55e44a Compare September 26, 2026 02:17

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

ℹ️ 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 — terminalLayoutEqual now compares chatLeafId, so a chatLeafId-only setTabLayout publishes; the identity-bailout test adds the matching mutation case.
  • Owner remapped through leaf-ID rewrites — normalizeTerminalLayoutLeafIds, normalizeTerminalLayoutPtyOwnership, and the main-process normalizeTerminalLayoutSnapshotForPersistence now carry chatLeafId alongside the other leaf-keyed records instead of letting it fall through the spread.
  • Ownership written from the route effect — applyNativeChatLeafRoute writes the owner into terminalLayoutsByTabId directly 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, and chooseRemoteTerminalLayout preserve chatLeafId (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.

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

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

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.ts
  • src/main/runtime/mobile-session-layout-projection.ts
  • src/renderer/src/components/terminal-pane/terminal-layout-leaf-detach.ts
  • src/renderer/src/components/terminal-pane/terminal-layout-leaf-ids.ts
  • src/renderer/src/components/terminal-pane/terminal-layout-pty-ownership.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/lib/terminal-layout-equality.ts
  • src/renderer/src/runtime/sync-runtime-graph/mobile-session-terminal-tabs.ts
  • src/renderer/src/runtime/web-session-tabs-sync/terminal-surfaces.ts
  • src/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.

Comment on lines +152 to +155
if (!isChatViewMode && chatLeafId && route.chatLeafId === null) {
// Keep the owner through the batched toggle that turns chat mode on.
return
}

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.

🎯 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.ts

Repository: 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.ts

Repository: 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 240

Repository: 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.

Comment on lines +203 to +208
const chatLeafId =
parentLayout?.chatLeafId && knownLeafIds.has(parentLayout.chatLeafId)
? parentLayout.chatLeafId
: existingLayout?.chatLeafId && knownLeafIds.has(existingLayout.chatLeafId)
? existingLayout.chatLeafId
: undefined

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.

🎯 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.ts

Repository: 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-pane

Repository: 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.ts

Repository: 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 240

Repository: 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.ts

Repository: 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.

Suggested change
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

@OrcaWin
OrcaWin merged commit ff74506 into main Sep 26, 2026
68 of 70 checks passed
@OrcaWin
OrcaWin deleted the OrcaWin/np-buggy-panes branch September 26, 2026 02:40
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