fix(background-task): retry transient missing output tasks
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -52,6 +52,47 @@ function createMockClient(): BackgroundOutputClient {
|
||||
}
|
||||
|
||||
describe("createBackgroundOutput block=true polling", () => {
|
||||
test("retries a missing background task id before reporting not found", async () => {
|
||||
// #given
|
||||
let lookupCount = 0
|
||||
const task = createTask({
|
||||
id: "bg_retry_visible",
|
||||
status: "completed",
|
||||
sessionId: "ses-retry-visible",
|
||||
})
|
||||
const manager: BackgroundOutputManager = {
|
||||
getTask: (id: string) => {
|
||||
if (id !== task.id) return undefined
|
||||
lookupCount += 1
|
||||
return lookupCount === 1 ? undefined : task
|
||||
},
|
||||
}
|
||||
const client: BackgroundOutputClient = {
|
||||
session: {
|
||||
messages: async () => ({
|
||||
data: [
|
||||
{
|
||||
id: "m1",
|
||||
info: { role: "assistant", time: "2026-01-01T00:00:00Z" },
|
||||
parts: [{ type: "text", text: "visible result" }],
|
||||
},
|
||||
],
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
const tool = createBackgroundOutput(manager, client)
|
||||
|
||||
// #when
|
||||
const output = await tool.execute({ task_id: task.id }, mockContext)
|
||||
|
||||
// #then
|
||||
expect(lookupCount).toBe(2)
|
||||
expect(output).toContain("Task Result")
|
||||
expect(output).toContain("visible result")
|
||||
expect(output).not.toContain("Task not found")
|
||||
})
|
||||
|
||||
test("returns terminal error output when task fails during blocking wait", async () => {
|
||||
// #given
|
||||
let pollCount = 0
|
||||
|
||||
Reference in New Issue
Block a user