mirror of
https://github.com/stablyai/orca.git
synced 2026-10-28 08:02:54 +00:00
Preserve OpenCode session across command completion, control SessionStart emission (#14866)
* Preserve OpenCode session across command completion - Add session start events and launch token tracking to establish session boundaries - Defer retiring launch authority until OpenCode process actually exits, not just when a command finishes - Fence previous tokens after restarts to prevent status updates from stale sessions - Maps SessionStart as a session boundary for proper turn/state management * Emit SessionStart only from OpenCode, not mimo-code Restrict SessionStart lifecycle events to OpenCode exclusively. Mimo-code no longer emits SessionStart, as it should rely on OpenCode for session boundary signals. This prevents duplicate lifecycle events that could interfere with pane authority tracking and session state management. Also tighten foreground process result validation to reject stale results after title observation changes, fixing a race where a delayed foreground read from a previous cycle would incorrectly retire authority.
This commit is contained in:
@@ -11119,7 +11119,7 @@ export class OrcaRuntimeService {
|
||||
this.recordTerminalSideEffectFact(ptyId, { kind: 'bell' })
|
||||
return
|
||||
case 'command-finished':
|
||||
this.retirePtyAgentLaunchAuthority(ptyId)
|
||||
this.retirePtyAgentLaunchAuthorityAfterCommandFinished(ptyId)
|
||||
this.recordTerminalSideEffectFact(ptyId, {
|
||||
kind: 'command-finished',
|
||||
exitCode: fact.exitCode
|
||||
@@ -11408,7 +11408,7 @@ export class OrcaRuntimeService {
|
||||
this.confirmPtyAgentExit(ptyId)
|
||||
},
|
||||
onCommandFinished: (exitCode: number | null) => {
|
||||
this.retirePtyAgentLaunchAuthority(ptyId)
|
||||
this.retirePtyAgentLaunchAuthorityAfterCommandFinished(ptyId)
|
||||
this.recordTerminalSideEffectFact(ptyId, { kind: 'command-finished', exitCode })
|
||||
},
|
||||
onBell: () => {
|
||||
@@ -13536,6 +13536,36 @@ export class OrcaRuntimeService {
|
||||
}
|
||||
}
|
||||
|
||||
private retirePtyAgentLaunchAuthorityAfterCommandFinished(ptyId: string): void {
|
||||
const pty = this.ptysById.get(ptyId)
|
||||
if (pty?.launchAgent !== 'opencode') {
|
||||
this.retirePtyAgentLaunchAuthority(ptyId)
|
||||
return
|
||||
}
|
||||
const titleObservedAt = pty.lastOscTitleAt ?? null
|
||||
const foregroundRead = this.readPtyForegroundProcessFromController(ptyId, titleObservedAt ?? 0)
|
||||
if (!foregroundRead) {
|
||||
this.retirePtyAgentLaunchAuthority(ptyId)
|
||||
return
|
||||
}
|
||||
const incarnationId = pty.incarnationId
|
||||
void foregroundRead.then((result) => {
|
||||
const current = this.ptysById.get(ptyId)
|
||||
if (
|
||||
current !== pty ||
|
||||
current.incarnationId !== incarnationId ||
|
||||
current.lastOscTitleAt !== titleObservedAt ||
|
||||
result.controller !== this.ptyController
|
||||
) {
|
||||
return
|
||||
}
|
||||
if (result.available && recognizeAgentProcess(result.process)?.agent === 'opencode') {
|
||||
return
|
||||
}
|
||||
this.retirePtyAgentLaunchAuthority(ptyId)
|
||||
})
|
||||
}
|
||||
|
||||
async resolveTerminalCwd(handle: string): Promise<string | null> {
|
||||
const ptyId = this.resolveLeafForHandle(handle)?.ptyId
|
||||
if (!ptyId) {
|
||||
|
||||
Reference in New Issue
Block a user