diff --git a/nodejs/test/e2e/session.e2e.test.ts b/nodejs/test/e2e/session.e2e.test.ts index 900ca4e859..1337410386 100644 --- a/nodejs/test/e2e/session.e2e.test.ts +++ b/nodejs/test/e2e/session.e2e.test.ts @@ -639,19 +639,17 @@ describe("Sessions", () => { await using session = await client.createSession({ onPermissionRequest: approveAll }); let disposed = false; - const disposedPromise = new Promise((resolve) => { - session.on((event) => { - if (event.type === "user.message") { - // Call disconnect from within a handler — must not deadlock. - session.disconnect().then(() => { - disposed = true; - resolve(); - }); - } - }); + let disposedPromise: Promise | undefined; + session.on((event) => { + if (event.type === "session.idle") { + // Isolate handler reentrancy from active-turn cancellation. + disposedPromise = session.disconnect().then(() => { + disposed = true; + }); + } }); - await session.send({ prompt: "What is 1+1?" }); + await session.sendAndWait({ prompt: "What is 1+1?" }); // If this times out, we deadlocked. await vi.waitFor(() => expect(disposed).toBe(true), { timeout: 10_000 }); diff --git a/python/e2e/test_mcp_and_agents_e2e.py b/python/e2e/test_mcp_and_agents_e2e.py index 6f443a970c..915928f1e3 100644 --- a/python/e2e/test_mcp_and_agents_e2e.py +++ b/python/e2e/test_mcp_and_agents_e2e.py @@ -183,6 +183,8 @@ async def test_should_accept_custom_agent_configuration_on_session_resume( ) session_id = session1.session_id await session1.send_and_wait("What is 1+1?") + # End the first attachment before testing resume-time reconfiguration. + await session1.disconnect() # Resume with custom agents custom_agents: list[CustomAgentConfig] = [