fix(background-agent): bound session abort waits

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-04 01:19:52 +09:00
parent 938c920092
commit f5740d68c7
5 changed files with 45 additions and 11 deletions
@@ -0,0 +1,35 @@
import { log } from "../../shared"
import type { OpencodeClient } from "./opencode-client"
export async function abortWithTimeout(
client: OpencodeClient,
sessionID: string,
timeoutMs = 10_000,
): Promise<boolean> {
let timeoutHandle: ReturnType<typeof setTimeout> | undefined
try {
const result = await Promise.race([
client.session.abort({ path: { id: sessionID } }).then(() => "aborted" as const),
new Promise<"timed_out">((resolve) => {
timeoutHandle = setTimeout(() => {
resolve("timed_out")
}, timeoutMs)
}),
])
if (result === "timed_out") {
log("[background-agent] Session abort timed out; continuing cleanup:", {
sessionID,
timeoutMs,
})
return false
}
return true
} finally {
if (timeoutHandle) {
clearTimeout(timeoutHandle)
}
}
}