Repository navigation
fix(terminal): every explicit terminal close commits through one main transaction #22929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
d285a67
7012c3e
fc5cac5
95abe04
bc8bbd7
f860b7d
25e31cb
07496c1
a201c79
0a808ae
28613ff
e17f7a6
6734584
3e78690
b6db605
a0782a7
1c2c599
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { SSH_PROVIDER_UNREGISTERED_REASON } from '../../shared/pty-liveness-verd | |
| import type { RuntimeTerminalClose } from '../../shared/runtime-types' | ||
| import { countTerminalLayoutLeaves } from './headless-terminal-split-layout' | ||
| import type { RuntimePtyTabCloseAuthority } from './runtime-terminal-state-records' | ||
| import { parsePaneKey } from '../../shared/stable-pane-id' | ||
|
|
||
| export class OrcaRuntimeWithStopExplicitlyClosedTabPtys extends OrcaRuntimeWithFocusTerminal { | ||
| protected async stopExplicitlyClosedTabPtys( | ||
|
|
@@ -155,28 +156,32 @@ export class OrcaRuntimeWithStopExplicitlyClosedTabPtys extends OrcaRuntimeWithF | |
| return this.describeTerminalClose(handle, tabId, pty.pty.ptyId, ptyKilled) | ||
| } | ||
| const ptyKilled = await this.stopExplicitlyClosedTabPtys([pty.pty.ptyId], pty.pty.ptyId) | ||
| if (!ptyKilled || siblingCount <= 1) { | ||
| if (surface) { | ||
| // Why: paired viewers keep ended streams mounted until the HUB publishes removal, so explicit close uses the durable host-tab transaction instead of viewer-local exit handling. | ||
| try { | ||
| await this.closeMobileSessionTab(`id:${pty.pty.worktreeId}`, tabId, { | ||
| localPtyTeardownOwnedExternally: true | ||
| }) | ||
| } catch (error) { | ||
| if (!(error instanceof Error) || error.message !== 'workspace_session_unavailable') { | ||
| throw error | ||
| } | ||
| this.notifier?.closeTerminal(tabId) | ||
| if (siblingCount > 1) { | ||
| const leafId = surface?.tab.leafId ?? parsePaneKey(pty.pty.paneKey ?? '')?.leafId | ||
| // Why: the pane's removal is this close's own commit, not a side effect of its exit. An | ||
| // unconfirmed stop is unverifiable, never a reason to close the live siblings with it. | ||
| if (leafId) { | ||
| this.closeTerminalLeaf(pty.pty.worktreeId, tabId, leafId) | ||
| } | ||
| } else if (surface) { | ||
| // Why: paired viewers keep ended streams mounted until the HUB publishes removal, so explicit close uses the durable host-tab transaction instead of viewer-local exit handling. | ||
| try { | ||
| await this.closeMobileSessionTab(`id:${pty.pty.worktreeId}`, tabId, { | ||
| localPtyTeardownOwnedExternally: true | ||
| }) | ||
| } catch (error) { | ||
| if (!(error instanceof Error) || error.message !== 'workspace_session_unavailable') { | ||
| throw error | ||
| } | ||
| } else { | ||
| this.notifier?.closeTerminal(tabId) | ||
| } | ||
| } else { | ||
| this.notifier?.closeTerminal(tabId) | ||
| } | ||
| return this.describeTerminalClose(handle, tabId, pty.pty.ptyId, ptyKilled) | ||
| } | ||
| this.assertGraphReady() | ||
| const { leaf } = this.getLiveLeafForHandle(handle) | ||
| // Why: in a multi-pane tab, killing the PTY is enough (renderer's exit handler closes the pane); an extra IPC close would race it and close the whole tab. | ||
| const siblingCount = this.countLeavesInTab(leaf.tabId) | ||
| const ptyIdsToKill = | ||
| siblingCount <= 1 | ||
|
|
@@ -190,8 +195,10 @@ export class OrcaRuntimeWithStopExplicitlyClosedTabPtys extends OrcaRuntimeWithF | |
| const ptyKilled = leaf.ptyId | ||
| ? await this.stopExplicitlyClosedTabPtys(ptyIdsToKill, leaf.ptyId) | ||
| : false | ||
| if (siblingCount > 1 ? !ptyKilled : !this.notifier?.closeTerminalTab) { | ||
| this.notifier?.closeTerminal(leaf.tabId, leaf.paneRuntimeId) | ||
| if (siblingCount > 1) { | ||
| this.closeTerminalLeaf(leaf.worktreeId, leaf.tabId, leaf.leafId) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift Do not retire a split pane while its PTY stop is unverified. If |
||
| } else if (!this.notifier?.closeTerminalTab) { | ||
| this.notifier?.closeTerminal(leaf.tabId) | ||
| } | ||
| return this.describeTerminalClose(handle, leaf.tabId, leaf.ptyId ?? null, ptyKilled) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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:
Repository: stablyai/orca
Length of output: 45665
🏁 Script executed:
Repository: stablyai/orca
Length of output: 34912
🏁 Script executed:
Repository: stablyai/orca
Length of output: 41450
🏁 Script executed:
Repository: stablyai/orca
Length of output: 45659
🏁 Script executed:
Repository: stablyai/orca
Length of output: 1824
🏁 Script executed:
Repository: stablyai/orca
Length of output: 5598
🏁 Script executed:
Repository: stablyai/orca
Length of output: 42310
🏁 Script executed:
Repository: stablyai/orca
Length of output: 10097
🏁 Script executed:
Repository: stablyai/orca
Length of output: 28146
🏁 Script executed:
Repository: stablyai/orca
Length of output: 37166
🏁 Script executed:
Repository: stablyai/orca
Length of output: 10569
🏁 Script executed:
Repository: stablyai/orca
Length of output: 3026
Publish the leaf removal after a successful PTY kill.
This branch persists the workspace session removal but does not update or notify the mobile snapshot. A later listing is not sufficient in all cases. Without a PTY exit event, subscribed mobile clients can retain the closed leaf.
Suggested fix
import { rendererPublicationThrottle } from '../window/renderer-publication-throttle' +import { retireTerminalSurfacesFromSnapshot } from './mobile-session-terminal-retirement' export class OrcaRuntimeWithCloseMobileSessionTab extends OrcaRuntimeWithRefuseUnattributedMobileSessionTabClose { ... // Why: the pane's removal is this close's own commit, not a side effect of its exit. this.closeTerminalLeaf(worktreeId, tab.parentTabId, tab.leafId) + const retired = retireTerminalSurfacesFromSnapshot({ + snapshot, + ptyId: pty.ptyId, + exactSurfaces: [{ parentTabId: tab.parentTabId, leafId: tab.leafId }], + exactOnly: true + }) + if (retired) { + this.storeMobileSessionSnapshot(worktreeId, retired.snapshot) + this.notifyMobileSessionTabsChanged(worktreeId) + } return finishCommittedClose()