From a2a5ff708ab004021543673c61fbc66d656a33db Mon Sep 17 00:00:00 2001 From: "lia-by-librechat[bot]" <328778573+lia-by-librechat[bot]@users.noreply.github.com> Date: Sun, 20 Sep 2026 20:20:09 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=8C=20test:=20Poll=20Instead=20of=20Sl?= =?UTF-8?q?eeping=20for=20Dead=20Subagent=20Owner=20Expiry=20(#16144)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lia --- .../src/agents/subagentTaskRouting.spec.ts | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/api/src/agents/subagentTaskRouting.spec.ts b/packages/api/src/agents/subagentTaskRouting.spec.ts index 21981e21e4..0c7ef0796f 100644 --- a/packages/api/src/agents/subagentTaskRouting.spec.ts +++ b/packages/api/src/agents/subagentTaskRouting.spec.ts @@ -549,9 +549,24 @@ describe('RedisSubagentTaskControlTransport', () => { await liveOwner.registerTask('scope-1', liveTask.taskId, 20); await deadOwner.destroy(); - await new Promise((resolve) => setTimeout(resolve, 35)); - - await expect(requester.list('scope-1')).resolves.toEqual([liveTask]); + /** The dead owner's entry lapses on its own TTL while the live owner's heartbeat + * re-registers its entry against that same TTL, so a runner that stalls past 20ms + * can find both gone for one beat. Poll until the directory settles rather than + * asserting on a single sleep. */ + let listed: SubagentTaskSnapshot[] = []; + for (let attempt = 0; attempt < 100 && listed.length === 0; attempt += 1) { + await new Promise((resolve) => setTimeout(resolve, 5)); + try { + listed = await requester.list('scope-1'); + } catch (error) { + /** The dead owner is still registered, so the request routes to a process that + * answers nothing. Anything else is a real failure. */ + if (!(error instanceof SubagentTaskOwnerUnavailableError)) { + throw error; + } + } + } + expect(listed).toEqual([liveTask]); await Promise.all([liveOwner.destroy(), requester.destroy()]); });