Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): restore the sessions list retry after a recovery
Yudhi Armyndharisb456c0387a36
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6eaabd5b8..53328abe7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -50,7 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- A request forwarded to the node that owns its session answers `504` or `502`, not `503`, when the forward times out or breaks after the request was sent, so a client retrying on `503` no longer repeats a send the owner may have carried out; `503` remains for an owner that could not be reached at all.- The dashboard Logs page and its sidebar entry are shown to admin keys only, matching the ADMIN-only `GET /api/audit` it reads.- The dashboard Sessions page hides Show QR for viewer keys, since the QR is operator-only.-- The dashboard Sessions page re-reads the session list once live updates connect after a failed initial load, instead of keeping the error until a reload.+- The dashboard Sessions page re-reads the session list once after any read that fails while live updates are connected, instead of keeping the error until a reload.- The dashboard Templates page shows a load or permission error when the template list cannot be read, instead of "No templates saved".- The dashboard Webhooks Configured card shows a placeholder instead of 0 when the webhook list cannot be read.- Dashboard message search ignores a response that arrives after a newer query, so stale results no longer replace the current ones.diff --git a/dashboard/src/pages/Sessions.test.ts b/dashboard/src/pages/Sessions.test.tsindex 8e5b41d1c..a1d190030 100644--- a/dashboard/src/pages/Sessions.test.ts+++ b/dashboard/src/pages/Sessions.test.ts@@ -545,8 +545,12 @@ test('Refresh on a feed that never connected re-reads the list once the socket iawait waitFor(() => assert.equal(listReads(), 2));await screen.findByText('new-device');// Compared as booleans: a failing assert.equal renders both operands, and a jsdom node never finishes.- assert.equal(screen.queryByText('gateway unavailable') === null, true, 'the failed read error is still shown');- assert.equal(screen.queryByRole('alert') === null, true, 'the feed banner is still shown');+ assert.equal(+ screen.queryByText('gateway unavailable') === null,+ true,+ 'expected the re-read to clear the failed read error',+ );+ assert.equal(screen.queryByRole('alert') === null, true, 'expected the feed banner to be gone once connected');});test('a failed mount read is retried when the feed first connects after its own retries', async () => {@@ -569,7 +573,52 @@ test('a failed mount read is retried when the feed first connects after its ownawait waitFor(() => assert.equal(listReads(), 2));await screen.findByText('new-device');- assert.equal(screen.queryByText('gateway unavailable') === null, true, 'the failed read error is still shown');+ assert.equal(+ screen.queryByText('gateway unavailable') === null,+ true,+ 'expected the retry to clear the failed read error',+ );+});++test('a later failure on the same connection is retried too, once the first recovery succeeded', async () => {+ const { screen, waitFor, act } = rtl;+ resetFetchCalls();+ sessionListFailures = 1;+ window.sessionStorage.setItem('openwa_api_key', 'test-key');+ holdConnect();+ renderSessions();++ await screen.findByText('gateway unavailable');+ const listReads = (): number => fetchCalls.filter(c => c.method === 'GET' && c.path === '/api/sessions').length;+ const socket = lastSocket();+ assert.ok(socket, 'expected the page to have opened a socket');+ act(() => socket.receive('connect'));++ // The connect spends the one retry this connect is allowed and the read succeeds, so the page is+ // healthy again, and the allowance must come back with it.+ await waitFor(() => assert.equal(listReads(), 2));+ await screen.findByText('new-device');++ // Much later, on the SAME socket: a restriction push re-reads the list and that read fails. Nothing+ // else on the page re-reads (the banner's Refresh renders only on a dead feed), so a spent allowance+ // would leave the operator with a stale list under a red box and no control to clear it.+ sessionListFailures = 1;+ act(() => {+ socket.receive('message', {+ type: 'event',+ timestamp: '2026-01-01T00:00:00.000Z',+ payload: { event: 'session.restriction', sessionId: SESSION_QR.id, data: {} },+ });+ });++ await waitFor(() => assert.equal(listReads(), 4));+ await waitFor(() =>+ assert.equal(+ screen.queryByText('gateway unavailable') === null,+ true,+ 'expected the retry to clear the failed read error',+ ),+ );});test('a connect retries a failed list read once, even when each failure carries a new message', async () => {diff --git a/dashboard/src/pages/Sessions.tsx b/dashboard/src/pages/Sessions.tsxindex 989486bd5..e97a6badf 100644--- a/dashboard/src/pages/Sessions.tsx+++ b/dashboard/src/pages/Sessions.tsx@@ -102,6 +102,9 @@ export function Sessions() {// Set while the last list read failed. Cleared as a read starts, so a connect that already triggered// a reload (onReconnect) is not followed by a second read from the recovery effect below.const listReadFailed = useRef(false);+ // Spends the one retry the recovery effect below is allowed per connect. Given back by a read that+ // actually succeeded, so a later independent failure on the same connection is retried too.+ const retriedThisConnect = useRef(false);const fetchSessions = useCallback(async (): Promise<Session[]> => {listReadFailed.current = false;@@ -113,8 +116,9 @@ export function Sessions() {const data = await sessionApi.list();setSessions(data);// The list is current again, so an error left by an earlier failed read (or a create, whose toast- // already reported it) no longer describes the page.+ // already reported it) no longer describes the page, and the recovery retry is available again.setError(null);+ retriedThisConnect.current = false;// Keep the shared React Query cache (read by the Dashboard via useSessionsQuery /// useSessionStatsQuery) in sync after this page's mutations reload local state — otherwise the// Dashboard shows stale session counts/status. This runs on every reload (mount / WS-failed /@@ -268,8 +272,9 @@ export function Sessions() {// onReconnect, and no status push re-reads the list, so the failed mount read would stay on screen// with no cards. `error` is a dependency so a read that fails after the connect is retried too, but// only once per connect: failures whose messages differ (a 502, then a 504) would otherwise each- // change `error` and re-read the list with no backoff for as long as the upstream stays down.- const retriedThisConnect = useRef(false);+ // change `error` and re-read the list with no backoff for as long as the upstream stays down. The+ // allowance (declared with `listReadFailed` above) is given back by a successful read, so the loop+ // stays closed while a later failure on the same connection is still retried.useEffect(() => {if (!isConnected) {retriedThisConnect.current = false;