test(delegate-task): cover aborted concurrent background launches

This commit is contained in:
YeonGyu-Kim
2026-03-31 15:11:12 -07:00
parent 56cf16c4c5
commit 9a0f2ff9a7
3 changed files with 363 additions and 3 deletions
+86
View File
@@ -1453,6 +1453,92 @@ describe("sisyphus-task", () => {
expect(launchCalled).toBe(true)
expect(result).toContain("Background task launched")
}, { timeout: 10000 })
test("#given concurrent background launches from the same parent #when one parent call aborts during session wait #then sibling launch is not interrupted", async () => {
// given
const { createDelegateTask } = require("./tools")
const firstAbortController = new AbortController()
const secondAbortController = new AbortController()
const taskStates = new Map([
["bg_tool_first", { reads: 0, abortOnFirstRead: true, sessionID: "ses_tool_first" }],
["bg_tool_second", { reads: 0, abortOnFirstRead: false, sessionID: "ses_tool_second" }],
])
let launchCount = 0
const mockManager = {
launch: async () => {
launchCount += 1
return launchCount === 1
? {
id: "bg_tool_first",
sessionID: undefined,
description: "Tool first",
agent: "Sisyphus-Junior",
status: "running",
}
: {
id: "bg_tool_second",
sessionID: undefined,
description: "Tool second",
agent: "Sisyphus-Junior",
status: "running",
}
},
getTask: (taskID: string) => {
const state = taskStates.get(taskID)
if (!state) return undefined
state.reads += 1
if (state.abortOnFirstRead && state.reads === 1) {
firstAbortController.abort()
}
return state.reads >= 2
? { sessionID: state.sessionID, status: "running" }
: { sessionID: undefined, status: "pending" }
},
}
const mockClient = {
app: { agents: async () => ({ data: [] }) },
config: { get: async () => ({ data: { model: SYSTEM_DEFAULT_MODEL } }) },
model: { list: async () => [] },
session: {
create: async () => ({ data: { id: "ses_bg_explicit_true" } }),
prompt: async () => ({ data: {} }),
promptAsync: async () => ({ data: {} }),
messages: async () => ({ data: [] }),
},
}
const tool = createDelegateTask({ manager: mockManager, client: mockClient })
// when
const [firstResult, secondResult] = await Promise.all([
tool.execute(
{
description: "Tool first",
prompt: "Run background",
category: "quick",
run_in_background: true,
load_skills: [],
},
{ sessionID: "parent-session", messageID: "parent-message-1", agent: "sisyphus", abort: firstAbortController.signal }
),
tool.execute(
{
description: "Tool second",
prompt: "Run background",
category: "quick",
run_in_background: true,
load_skills: [],
},
{ sessionID: "parent-session", messageID: "parent-message-2", agent: "sisyphus", abort: secondAbortController.signal }
),
])
// then
expect(firstResult).toContain("Background task launched")
expect(firstResult).not.toContain("Task failed to start")
expect(secondResult).toContain("Background task launched")
expect(secondResult).toContain("session_id: ses_tool_second")
expect(secondResult).not.toContain("interrupt")
}, { timeout: 10000 })
})
describe("session_id with background parameter", () => {