Merge pull request #4092 from code-yeongyu/fix/status-timeout-hang

fix(shared): add timeout to isSessionActive to prevent infinite hang
This commit is contained in:
YeonGyu-Kim
2026-05-21 12:58:14 +09:00
committed by GitHub
5 changed files with 170 additions and 3 deletions
@@ -1423,4 +1423,32 @@ describe("dispatchInternalPrompt shared gate behavior", () => {
response: { accepted: true, sessionID: "ses_bound_prompt" },
})
})
test("#given session.status hangs forever #when promptAsync gate checks activity #then it dispatches after status timeout", { timeout: 10_000 }, async () => {
// given
let promptCalls = 0
const neverSettles = new Promise<never>(() => {})
const client = {
session: {
status: () => neverSettles,
promptAsync: async () => {
promptCalls += 1
},
},
}
// when
const result = await promptAsyncAfterSessionIdle({
client,
sessionID: "ses_status_timeout",
input: { path: { id: "ses_status_timeout" }, body: { parts: [] } },
source: "test:status-timeout",
settleMs: 0,
postDispatchHoldMs: 0,
})
// then
expect(result.status).toBe("dispatched")
expect(promptCalls).toBe(1)
})
})
@@ -52,4 +52,20 @@ describe("session idle prompt guard", () => {
// then
expect(shouldPrompt).toBe(true)
})
test("#given session.status hangs forever #when checking active session #then it returns false after timeout", async () => {
// given
const neverSettles = new Promise<never>(() => {})
const client = {
session: {
status: () => neverSettles,
},
}
// when
const active = await isSessionActive(client, "ses-hang", 50)
// then
expect(active).toBe(false)
})
})