fix(background-agent): await stale task aborts before poller exits

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-03 17:12:18 +09:00
parent f39a0182eb
commit 4d40b44914
2 changed files with 93 additions and 2 deletions
+7 -2
View File
@@ -119,6 +119,7 @@ export async function checkAndInterruptStaleTasks(args: {
const staleTimeoutMs = config?.staleTimeoutMs ?? DEFAULT_STALE_TIMEOUT_MS
const sessionGoneTimeoutMs = config?.sessionGoneTimeoutMs ?? DEFAULT_SESSION_GONE_TIMEOUT_MS
const now = Date.now()
const abortPromises: Array<Promise<unknown>> = []
const messageStalenessMs = config?.messageStalenessTimeoutMs ?? DEFAULT_MESSAGE_STALENESS_TIMEOUT_MS
@@ -166,7 +167,7 @@ export async function checkAndInterruptStaleTasks(args: {
onTaskInterrupted(task)
client.session.abort({ path: { id: sessionID } }).catch(() => {})
abortPromises.push(client.session.abort({ path: { id: sessionID } }))
log(`[background-agent] Task ${task.id} interrupted: no progress since start`)
try {
@@ -204,7 +205,7 @@ export async function checkAndInterruptStaleTasks(args: {
onTaskInterrupted(task)
client.session.abort({ path: { id: sessionID } }).catch(() => {})
abortPromises.push(client.session.abort({ path: { id: sessionID } }))
log(`[background-agent] Task ${task.id} interrupted: stale timeout`)
try {
@@ -213,4 +214,8 @@ export async function checkAndInterruptStaleTasks(args: {
log("[background-agent] Error in notifyParentSession for stale task:", { taskId: task.id, error: err })
}
}
if (abortPromises.length > 0) {
await Promise.allSettled(abortPromises)
}
}