fix(background-agent): add post-compaction continuation + fix stale/idle race
Extract sendPostCompactionContinuation to dedicated file — council members now resume after compaction instead of silently failing. Refresh lastUpdate before async validation in both idle handler and polling path to prevent stale timeout from racing with completion detection. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -12,6 +12,7 @@ export function handleSessionIdleBackgroundEvent(args: {
|
||||
findBySession: (sessionID: string) => BackgroundTask | undefined
|
||||
idleDeferralTimers: Map<string, ReturnType<typeof setTimeout>>
|
||||
recentlyCompactedSessions?: Set<string>
|
||||
onPostCompactionIdle?: (task: BackgroundTask, sessionID: string) => void
|
||||
validateSessionHasOutput: (sessionID: string) => Promise<boolean>
|
||||
checkSessionTodos: (sessionID: string) => Promise<boolean>
|
||||
tryCompleteTask: (task: BackgroundTask, source: string) => Promise<boolean>
|
||||
@@ -22,6 +23,7 @@ export function handleSessionIdleBackgroundEvent(args: {
|
||||
findBySession,
|
||||
idleDeferralTimers,
|
||||
recentlyCompactedSessions,
|
||||
onPostCompactionIdle,
|
||||
validateSessionHasOutput,
|
||||
checkSessionTodos,
|
||||
tryCompleteTask,
|
||||
@@ -37,6 +39,7 @@ export function handleSessionIdleBackgroundEvent(args: {
|
||||
if (recentlyCompactedSessions?.has(sessionID)) {
|
||||
recentlyCompactedSessions.delete(sessionID)
|
||||
log("[background-agent] Skipping post-compaction session.idle:", { taskId: task.id, sessionID })
|
||||
onPostCompactionIdle?.(task, sessionID)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -63,6 +66,13 @@ export function handleSessionIdleBackgroundEvent(args: {
|
||||
return
|
||||
}
|
||||
|
||||
// Refresh lastUpdate to prevent stale timeout from racing with this async validation.
|
||||
// Without this, checkAndInterruptStaleTasks can kill the task synchronously
|
||||
// while validateSessionHasOutput is still awaiting an API response.
|
||||
if (task.progress) {
|
||||
task.progress.lastUpdate = new Date()
|
||||
}
|
||||
|
||||
validateSessionHasOutput(sessionID)
|
||||
.then(async (hasValidOutput) => {
|
||||
if (task.status !== "running") {
|
||||
|
||||
Reference in New Issue
Block a user