fix: prevent background agent race condition in session prompt (#2932)
Added await for session ready state before sending prompt in background-agent/manager.ts. Also improved image resizer error handling. 132 tests pass, tsc clean. Closes #2932
This commit is contained in:
@@ -345,6 +345,54 @@ describeFn("executeBackgroundTask output/session metadata compatibility", () =>
|
||||
expectFn(result).toContain("interrupt")
|
||||
})
|
||||
|
||||
testFn("reports failure when manager marks task as error during session startup", async () => {
|
||||
//#given - session created but startTask throws before prompt is sent
|
||||
const metadataCalls: any[] = []
|
||||
let reads = 0
|
||||
const manager = {
|
||||
launch: async () => ({
|
||||
id: "bg_crash_before_prompt",
|
||||
sessionID: undefined,
|
||||
description: "Crash before prompt",
|
||||
agent: "explore",
|
||||
status: "pending",
|
||||
}),
|
||||
getTask: () => {
|
||||
reads += 1
|
||||
if (reads >= 2) {
|
||||
return { sessionID: "ses_orphan", status: "error", error: "crash between session creation and prompt send" }
|
||||
}
|
||||
return { sessionID: undefined, status: "pending" }
|
||||
},
|
||||
}
|
||||
|
||||
//#when
|
||||
const result = await executeBackgroundTask(
|
||||
{
|
||||
description: "Crash before prompt",
|
||||
prompt: "check",
|
||||
run_in_background: true,
|
||||
load_skills: [],
|
||||
},
|
||||
{
|
||||
sessionID: "ses_parent",
|
||||
callID: "call_crash",
|
||||
metadata: async (value: any) => metadataCalls.push(value),
|
||||
abort: new AbortController().signal,
|
||||
},
|
||||
{ manager },
|
||||
{ sessionID: "ses_parent", messageID: "msg_crash" },
|
||||
"explore",
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
)
|
||||
|
||||
//#then - polling loop should detect terminal status and report failure
|
||||
expectFn(result).toContain("Task failed to start")
|
||||
expectFn(result).toContain("error")
|
||||
})
|
||||
|
||||
testFn("keeps sibling background launch alive when two tasks start concurrently", async () => {
|
||||
//#given - one aborted parent call should not interrupt a sibling launch from the same parent session
|
||||
const firstAbortController = new AbortController()
|
||||
|
||||
Reference in New Issue
Block a user