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:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user