From 8a15eef2c8456c88982136cb794ac1cacb0fe312 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 26 Jun 2026 13:01:15 +0000 Subject: [PATCH] fix: wait for session switch settle in web probe --- .../src/hwlab-node-web-observe-runner-source.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/src/hwlab-node-web-observe-runner-source.ts b/scripts/src/hwlab-node-web-observe-runner-source.ts index 0374d979..c2a746ff 100644 --- a/scripts/src/hwlab-node-web-observe-runner-source.ts +++ b/scripts/src/hwlab-node-web-observe-runner-source.ts @@ -1746,14 +1746,21 @@ async function switchAwayAndBack(command) { } if (!alternateSessionId) throw new Error("switchAwayAndBack could not find an alternate session with strategy=" + strategy); const switchAway = await clickSession(alternateSessionId); - const away = await workbenchSessionSnapshot(); + const awaySettle = await waitForWorkbenchSessionHydrated(page, alternateSessionId, { timeoutMs: 15000 }); + const away = awaySettle.snapshot ?? await workbenchSessionSnapshot(); const switchBack = await gotoTarget("/workbench/sessions/" + encodeURIComponent(canarySessionId)); - const after = await workbenchSessionSnapshot(); + const backSettle = await waitForWorkbenchSessionHydrated(page, canarySessionId, { timeoutMs: 15000 }); + const after = backSettle.snapshot ?? await workbenchSessionSnapshot(); const routeOk = after?.routeSessionId === canarySessionId; const activeOk = after?.activeSessionId === canarySessionId; + if (awaySettle.ok !== true) { + const error = new Error("switchAwayAndBack did not settle on the alternate session"); + error.details = { canarySessionId, alternateSessionId, routeSessionId: away?.routeSessionId ?? null, activeSessionId: away?.activeSessionId ?? null, settle: awaySettle, pageId, valuesRedacted: true }; + throw error; + } if (!routeOk || !activeOk) { const error = new Error("switchAwayAndBack did not return to the canary session"); - error.details = { canarySessionId, alternateSessionId, routeSessionId: after?.routeSessionId ?? null, activeSessionId: after?.activeSessionId ?? null, pageId, valuesRedacted: true }; + error.details = { canarySessionId, alternateSessionId, routeSessionId: after?.routeSessionId ?? null, activeSessionId: after?.activeSessionId ?? null, settle: backSettle, pageId, valuesRedacted: true }; throw error; } return { @@ -1768,6 +1775,7 @@ async function switchAwayAndBack(command) { beforeSessionCount: beforeSessionIds.length, createResult: createResult === null ? null : { sessionId: alternateSessionId, valuesRedacted: true }, switchAway, + awaySettle, away: { routeSessionId: away?.routeSessionId ?? null, activeSessionId: away?.activeSessionId ?? null, @@ -1775,6 +1783,7 @@ async function switchAwayAndBack(command) { valuesRedacted: true, }, switchBack, + backSettle, routeSessionId: after?.routeSessionId ?? null, activeSessionId: after?.activeSessionId ?? null, routeOk,