fix(parent-wake): recognize sdk tool progress

This commit is contained in:
YeonGyu-Kim
2026-05-19 13:48:26 +09:00
parent 67bd324987
commit 5f733f471c
3 changed files with 133 additions and 2 deletions
@@ -597,6 +597,52 @@ describe("BackgroundManager.notifyParentSession cleanup scheduling", () => {
expect(notificationPayload).toContain("ALL BACKGROUND TASKS COMPLETE")
})
test("#when stale sdk tool-call part keeps blocking an all-complete wake #then completion eventually wakes the parent", async () => {
// given
const sessionStatuses: Record<string, { type: string }> = {
"parent-1": { type: "idle" },
}
const sessionMessages: SessionMessageForTest[] = [
{
info: { role: "user", time: { created: 1778819814009 } },
parts: [{ type: "text" }],
},
{
info: { role: "assistant", time: { created: 1778819997535 } },
parts: [{ type: "tool-call", state: { status: "running" } }],
},
]
const { manager, promptAsyncCalls } = createManager(true, sessionStatuses, undefined, sessionMessages)
managerUnderTest = manager
const task = createTask({
id: "task-a",
parentSessionId: "parent-1",
description: "task A",
status: "completed",
completedAt: new Date("2026-05-15T13:40:19.368Z"),
})
getTasks(manager).set(task.id, task)
getPendingByParent(manager).set(task.parentSessionId, new Set([task.id]))
await notifyParentSessionForTest(manager, task)
await waitForCoalescedFlush()
const pendingWake = getPendingParentWakes(manager).get("parent-1")
expect(pendingWake).toBeDefined()
if (!pendingWake) {
throw new Error("Missing pending parent wake")
}
pendingWake.toolCallDeferralStartedAt = Date.now() - 60_000
// when
manager.handleEvent({ type: "session.idle", properties: { sessionID: "parent-1" } })
await waitForDeferredWake(promptAsyncCalls)
// then
expect(promptAsyncCalls).toHaveLength(1)
expect(promptAsyncCalls[0]?.body.noReply).toBe(false)
const notificationPayload = JSON.stringify(promptAsyncCalls[0]?.body.parts)
expect(notificationPayload).toContain("ALL BACKGROUND TASKS COMPLETE")
})
test("#when stale deferral age is exceeded but latest tool turn is recent #then all-complete wake still waits", async () => {
// given
const originalDateNow = Date.now