fix(team-mode): cleanup team runs on shutdown
This commit is contained in:
+23
-1
@@ -5,6 +5,7 @@ import type { PluginContext, TmuxConfig } from "./plugin/types"
|
||||
import type { SubagentSessionCreatedEvent } from "./features/background-agent"
|
||||
import { BackgroundManager } from "./features/background-agent"
|
||||
import { SkillMcpManager } from "./features/skill-mcp-manager"
|
||||
import { cleanupSessionTeamRuns } from "./features/team-mode/team-runtime/session-cleanup"
|
||||
import { createModelFallbackControllerAccessor } from "./hooks/model-fallback"
|
||||
import { initTaskToastManager } from "./features/task-toast-manager"
|
||||
import { TmuxSessionManager } from "./features/tmux-subagent"
|
||||
@@ -21,6 +22,7 @@ type CreateManagersDeps = {
|
||||
TmuxSessionManagerClass: typeof TmuxSessionManager
|
||||
initTaskToastManagerFn: typeof initTaskToastManager
|
||||
registerManagerForCleanupFn: typeof registerManagerForCleanup
|
||||
cleanupSessionTeamRunsFn: typeof cleanupSessionTeamRuns
|
||||
createConfigHandlerFn: typeof createConfigHandler
|
||||
markServerRunningInProcessFn: typeof markServerRunningInProcess
|
||||
}
|
||||
@@ -31,6 +33,7 @@ const defaultCreateManagersDeps: CreateManagersDeps = {
|
||||
TmuxSessionManagerClass: TmuxSessionManager,
|
||||
initTaskToastManagerFn: initTaskToastManager,
|
||||
registerManagerForCleanupFn: registerManagerForCleanup,
|
||||
cleanupSessionTeamRunsFn: cleanupSessionTeamRuns,
|
||||
createConfigHandlerFn: createConfigHandler,
|
||||
markServerRunningInProcessFn: markServerRunningInProcess,
|
||||
}
|
||||
@@ -59,16 +62,32 @@ export function createManagers(args: {
|
||||
}
|
||||
const tmuxSessionManager = new deps.TmuxSessionManagerClass(ctx, tmuxConfig)
|
||||
const modelFallbackControllerAccessor = createModelFallbackControllerAccessor()
|
||||
let backgroundManager: BackgroundManager | undefined
|
||||
|
||||
const cleanupTeamModeRuns = async (): Promise<void> => {
|
||||
if (!pluginConfig.team_mode?.enabled) return
|
||||
const report = await deps.cleanupSessionTeamRunsFn({
|
||||
config: pluginConfig.team_mode,
|
||||
tmuxMgr: tmuxSessionManager,
|
||||
bgMgr: backgroundManager,
|
||||
})
|
||||
if (report.cleanedTeamRunIds.length > 0 || report.errors.length > 0) {
|
||||
log("[create-managers] team-mode session cleanup complete", report)
|
||||
}
|
||||
}
|
||||
|
||||
deps.registerManagerForCleanupFn({
|
||||
shutdown: async () => {
|
||||
await cleanupTeamModeRuns().catch((error) => {
|
||||
log("[create-managers] team-mode cleanup error during process shutdown:", error)
|
||||
})
|
||||
await tmuxSessionManager.cleanup().catch((error) => {
|
||||
log("[create-managers] tmux cleanup error during process shutdown:", error)
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
const backgroundManager = new deps.BackgroundManagerClass({
|
||||
backgroundManager = new deps.BackgroundManagerClass({
|
||||
pluginContext: ctx,
|
||||
config: pluginConfig.background_task,
|
||||
tmuxConfig,
|
||||
@@ -105,6 +124,9 @@ export function createManagers(args: {
|
||||
log("[create-managers] onSubagentSessionCreated callback completed")
|
||||
},
|
||||
onShutdown: async () => {
|
||||
await cleanupTeamModeRuns().catch((error) => {
|
||||
log("[create-managers] team-mode cleanup error during shutdown:", error)
|
||||
})
|
||||
await tmuxSessionManager.cleanup().catch((error) => {
|
||||
log("[create-managers] tmux cleanup error during shutdown:", error)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user