fix(tmux-subagent): retry stale sweep if first attempt throws
Oracle flagged: staleSweepCompleted was set to true BEFORE
sweepStaleOmoAgentSessions() ran, so any throw from the first
invocation would permanently disable stale cleanup for the rest
of the process lifetime.
Fix:
- Move staleSweepCompleted=true into the try-block success branch.
- Add staleSweepInProgress guard so concurrent onSessionCreated calls
do not invoke sweep twice in parallel (sweep is idempotent, but the
guard prevents doubled log noise).
- finally{} clears the inProgress flag regardless of outcome.
- cleanup() resets both flags.
Two new tests cover: retry after a thrown first attempt, and single
invocation when subsequent spawns follow a successful first sweep.
This commit is contained in:
@@ -67,6 +67,7 @@ export class TmuxSessionManager {
|
||||
private isolatedWindowPaneId: string | undefined
|
||||
private isolatedContainerNullStateCount = 0
|
||||
private staleSweepCompleted = false
|
||||
private staleSweepInProgress = false
|
||||
constructor(ctx: PluginInput, tmuxConfig: TmuxConfig, deps: TmuxUtilDeps = defaultTmuxDeps) {
|
||||
this.client = ctx.client
|
||||
this.tmuxConfig = tmuxConfig
|
||||
@@ -977,27 +978,32 @@ export class TmuxSessionManager {
|
||||
}
|
||||
|
||||
this.staleSweepCompleted = false
|
||||
this.staleSweepInProgress = false
|
||||
|
||||
log("[tmux-session-manager] cleanup complete")
|
||||
}
|
||||
|
||||
private async sweepStaleIsolatedSessionsOnce(): Promise<void> {
|
||||
if (this.staleSweepCompleted) return
|
||||
if (this.staleSweepInProgress) return
|
||||
if (this.tmuxConfig.isolation !== "session") {
|
||||
this.staleSweepCompleted = true
|
||||
return
|
||||
}
|
||||
|
||||
this.staleSweepCompleted = true
|
||||
this.staleSweepInProgress = true
|
||||
try {
|
||||
const killed = await sweepStaleOmoAgentSessions()
|
||||
if (killed > 0) {
|
||||
log("[tmux-session-manager] stale isolated sessions swept", { killed })
|
||||
}
|
||||
this.staleSweepCompleted = true
|
||||
} catch (error) {
|
||||
log("[tmux-session-manager] stale sweep failed", {
|
||||
error: String(error),
|
||||
})
|
||||
} finally {
|
||||
this.staleSweepInProgress = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user