From 27dfba9e314568ae361045916a0f48a4cd9caddf Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Feb 2026 16:33:54 +0000 Subject: [PATCH] improve: clarify app state sync log when decryption key is unavailable Changes the log message when an app-state-sync key is not found (404) to clearly indicate this is expected behavior for new sessions, not an error. Old encryption keys from previous sessions are not shared by the WhatsApp server to newly paired devices. Before: "failed to sync state from version" (looks like an error) After: "app state sync: decryption key not available for X -- expected for new sessions where old keys are not shared by the server" https://claude.ai/code/session_01XaA7GwNaB6azTHFYQ8WEpB --- src/Socket/chats.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index 759227b1..c1118e27 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -638,14 +638,23 @@ export const makeChatsSocket = (config: SocketConfig) => { } catch (error: any) { // if retry attempts overshoot // or key not found + const isKeyNotFound = error.output?.statusCode === 404 const isIrrecoverableError = (attemptsMap[name] || 0) >= MAX_SYNC_ATTEMPTS || - error.output?.statusCode === 404 || + isKeyNotFound || error.name === 'TypeError' - logger.info( - { name, error: error.stack }, - `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}` - ) + if (isKeyNotFound) { + const currentVersion = states[name]?.version ?? 0 + logger.info( + { name }, + `app state sync: decryption key not available for "${name}" (syncing from v${currentVersion}) -- expected for new sessions where old keys are not shared by the server` + ) + } else { + logger.info( + { name, error: error.stack }, + `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}` + ) + } await authState.keys.set({ 'app-state-sync-version': { [name]: null } }) // increment number of retries attemptsMap[name] = (attemptsMap[name] || 0) + 1