Addresses two SIGKILL/wake-routing bugs: - setWorkspaceSession now merges prior tab.ptyId / ptyIdsByLeafId when the incoming snapshot's binding is empty, closing the second half of the SIGKILL race that could clobber persistPtyBinding. - DaemonPtyRouter.shutdown skips sessionAdapters.delete when keepHistory=true so legacy-adapter sessions wake on the right adapter on resume. Co-authored-by: orca-bot <bot@stably.ai>
This commit is contained in:
co-authored by
orca-bot
parent
cd686f58d0
commit
ba034c3c3d
@@ -65,7 +65,15 @@ export class DaemonPtyRouter implements IPtyProvider {
|
||||
|
||||
async shutdown(id: string, opts: { immediate?: boolean; keepHistory?: boolean }): Promise<void> {
|
||||
await this.adapterFor(id).shutdown(id, opts)
|
||||
this.sessionAdapters.delete(id)
|
||||
// Why: sleep passes keepHistory=true and re-spawns against the same
|
||||
// sessionId on wake. If we delete the routing entry here, adapterFor()
|
||||
// falls back to `this.current` on wake — for a session that originally
|
||||
// lived on a legacy adapter (different protocolVersion), the wake-side
|
||||
// createOrAttach lands on the wrong adapter and creates a fresh session,
|
||||
// losing the cold-restore from the legacy adapter's history dir.
|
||||
if (!opts.keepHistory) {
|
||||
this.sessionAdapters.delete(id)
|
||||
}
|
||||
}
|
||||
|
||||
async sendSignal(id: string, signal: string): Promise<void> {
|
||||
|
||||
@@ -671,6 +671,46 @@ export class Store {
|
||||
}
|
||||
|
||||
setWorkspaceSession(session: PersistedState['workspaceSession']): void {
|
||||
// Why: closes the second half of the SIGKILL race (Issue #217). The
|
||||
// renderer's debounced session writer captures its state BEFORE pty:spawn
|
||||
// returns, so the snapshot it later flushes via session:set has no
|
||||
// tab.ptyId / ptyIdsByLeafId for the just-spawned PTY. If that stale
|
||||
// snapshot lands AFTER persistPtyBinding's sync flush, it would overwrite
|
||||
// the durable binding and re-open the orphan window. Merge in any
|
||||
// existing bindings whenever the incoming snapshot's binding is empty.
|
||||
const prior = this.state.workspaceSession
|
||||
if (session && prior) {
|
||||
const priorTabs = prior.tabsByWorktree ?? {}
|
||||
const nextTabs = session.tabsByWorktree ?? {}
|
||||
for (const [worktreeId, tabs] of Object.entries(nextTabs)) {
|
||||
const priorList = priorTabs[worktreeId]
|
||||
if (!priorList) {
|
||||
continue
|
||||
}
|
||||
for (const tab of tabs) {
|
||||
if (tab.ptyId) {
|
||||
continue
|
||||
}
|
||||
const priorTab = priorList.find((t) => t.id === tab.id)
|
||||
if (priorTab?.ptyId) {
|
||||
tab.ptyId = priorTab.ptyId
|
||||
}
|
||||
}
|
||||
}
|
||||
const priorLayouts = prior.terminalLayoutsByTabId ?? {}
|
||||
const nextLayouts = session.terminalLayoutsByTabId ?? {}
|
||||
for (const [tabId, layout] of Object.entries(nextLayouts)) {
|
||||
const priorLayout = priorLayouts[tabId]
|
||||
if (!priorLayout?.ptyIdsByLeafId) {
|
||||
continue
|
||||
}
|
||||
const incoming = layout.ptyIdsByLeafId
|
||||
if (incoming && Object.keys(incoming).length > 0) {
|
||||
continue
|
||||
}
|
||||
layout.ptyIdsByLeafId = { ...priorLayout.ptyIdsByLeafId }
|
||||
}
|
||||
}
|
||||
this.state.workspaceSession = session
|
||||
this.scheduleSave()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user