From 698f154c281c5a5267d328c3ea5f993bf2e3d478 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 22 Apr 2026 23:11:21 +0100 Subject: [PATCH] fix(qa): recheck Matrix sync events after poll --- extensions/qa-matrix/src/substrate/sync.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/extensions/qa-matrix/src/substrate/sync.ts b/extensions/qa-matrix/src/substrate/sync.ts index 966c3052740..9d9983eaeae 100644 --- a/extensions/qa-matrix/src/substrate/sync.ts +++ b/extensions/qa-matrix/src/substrate/sync.ts @@ -144,7 +144,7 @@ export function createMatrixQaRoomObserver( const startSince = await this.prime(); const startedAt = Date.now(); let cursorIndex = roomObserver.cursorIndex; - while (Date.now() - startedAt < waitParams.timeoutMs) { + while (true) { const matched = findMatrixQaObservedEventMatch({ cursorIndex, events: roomObserver.events, @@ -160,8 +160,17 @@ export function createMatrixQaRoomObserver( }; } + const elapsedMs = Date.now() - startedAt; + if (elapsedMs >= waitParams.timeoutMs) { + roomObserver.cursorIndex = Math.max(roomObserver.cursorIndex, cursorIndex); + return { + matched: false, + since: roomObserver.since ?? startSince, + }; + } + cursorIndex = roomObserver.events.length; - const remainingMs = Math.max(1_000, waitParams.timeoutMs - (Date.now() - startedAt)); + const remainingMs = Math.max(1_000, waitParams.timeoutMs - elapsedMs); await pollMatrixQaRoomObserver({ ...params, observedEvents: params.observedEvents, @@ -169,11 +178,6 @@ export function createMatrixQaRoomObserver( timeoutMs: remainingMs, }); } - roomObserver.cursorIndex = Math.max(roomObserver.cursorIndex, cursorIndex); - return { - matched: false, - since: roomObserver.since ?? startSince, - }; }, async waitForRoomEvent(waitParams) { const result = await this.waitForOptionalRoomEvent(waitParams);