惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tailwind CSS Blog
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
L
LangChain Blog
博客园_首页
Recent Announcements
Recent Announcements
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Hackread – Cybersecurity News, Data Breaches, AI and More
爱范儿
爱范儿
博客园 - 叶小钗
博客园 - 【当耐特】
The Cloudflare Blog
J
Java Code Geeks
G
Google Developers Blog
云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(whatsapp): retry QR login 408 timeouts (#88183) · ope...
mcaxtr · 2026-05-30 · via Recent Commits to openclaw:main
11

import { EventEmitter } from "node:events";

2+

import { DisconnectReason } from "baileys";

23

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

34

import { getRegisteredWhatsAppConnectionController } from "./connection-controller-registry.js";

4-

import { closeWaSocket, WhatsAppConnectionController } from "./connection-controller.js";

5+

import {

6+

closeWaSocket,

7+

waitForWhatsAppLoginResult,

8+

WhatsAppConnectionController,

9+

} from "./connection-controller.js";

510

import type { WhatsAppSendKind, WhatsAppSendResult } from "./inbound/send-result.js";

611

import { createWaSocket, waitForWaConnection } from "./session.js";

712

@@ -127,6 +132,120 @@ describe("WhatsAppConnectionController", () => {

127132

expect(callOrder).toEqual(["create", "wait-for-connection"]);

128133

});

129134135+

it("restarts login once on status 408 and preserves replacement socket options", async () => {

136+

const initialSock = createSocketWithTransportEmitter();

137+

const replacementSock = createSocketWithTransportEmitter();

138+

const waitForConnection = vi

139+

.fn()

140+

.mockRejectedValueOnce({ output: { statusCode: DisconnectReason.timedOut } })

141+

.mockResolvedValueOnce(undefined);

142+

const onQr = vi.fn();

143+

const onSocketReplaced = vi.fn();

144+

const createSocket = vi.fn(

145+

async (_printQr: boolean, _verbose: boolean, opts?: { onQr?: (qr: string) => void }) => {

146+

opts?.onQr?.("qr-after-timeout");

147+

return replacementSock;

148+

},

149+

);

150+151+

const result = await waitForWhatsAppLoginResult({

152+

sock: initialSock as never,

153+

authDir: "/tmp/wa-auth",

154+

isLegacyAuthDir: false,

155+

verbose: true,

156+

runtime: { log: vi.fn() } as never,

157+

waitForConnection: waitForConnection as never,

158+

createSocket: createSocket as never,

159+

socketTiming: {

160+

connectTimeoutMs: 10_000,

161+

defaultQueryTimeoutMs: 20_000,

162+

keepAliveIntervalMs: 30_000,

163+

},

164+

onQr,

165+

onSocketReplaced,

166+

});

167+168+

expect(result).toEqual({

169+

outcome: "connected",

170+

restarted: true,

171+

sock: replacementSock,

172+

});

173+

expect(initialSock.end).toHaveBeenCalledOnce();

174+

expect(createSocket).toHaveBeenCalledWith(false, true, {

175+

authDir: "/tmp/wa-auth",

176+

connectTimeoutMs: 10_000,

177+

defaultQueryTimeoutMs: 20_000,

178+

keepAliveIntervalMs: 30_000,

179+

onQr,

180+

});

181+

expect(onQr).toHaveBeenCalledWith("qr-after-timeout");

182+

expect(onSocketReplaced).toHaveBeenCalledWith(replacementSock);

183+

});

184+185+

it("still honors the post-pairing 515 restart after a status 408 recovery", async () => {

186+

const initialSock = createSocketWithTransportEmitter();

187+

const afterTimeoutSock = createSocketWithTransportEmitter();

188+

const afterPairingRestartSock = createSocketWithTransportEmitter();

189+

const waitForConnection = vi

190+

.fn()

191+

.mockRejectedValueOnce({ output: { statusCode: DisconnectReason.timedOut } })

192+

.mockRejectedValueOnce({ output: { statusCode: 515 } })

193+

.mockResolvedValueOnce(undefined);

194+

const createSocket = vi

195+

.fn()

196+

.mockResolvedValueOnce(afterTimeoutSock)

197+

.mockResolvedValueOnce(afterPairingRestartSock);

198+199+

const result = await waitForWhatsAppLoginResult({

200+

sock: initialSock as never,

201+

authDir: "/tmp/wa-auth",

202+

isLegacyAuthDir: false,

203+

verbose: false,

204+

runtime: { log: vi.fn() } as never,

205+

waitForConnection: waitForConnection as never,

206+

createSocket: createSocket as never,

207+

});

208+209+

expect(result).toEqual({

210+

outcome: "connected",

211+

restarted: true,

212+

sock: afterPairingRestartSock,

213+

});

214+

expect(createSocket).toHaveBeenCalledTimes(2);

215+

expect(waitForConnection).toHaveBeenCalledTimes(3);

216+

expect(initialSock.end).toHaveBeenCalledOnce();

217+

expect(afterTimeoutSock.end).toHaveBeenCalledOnce();

218+

});

219+220+

it("does not keep recreating sockets when login status 408 persists", async () => {

221+

const initialSock = createSocketWithTransportEmitter();

222+

const replacementSock = createSocketWithTransportEmitter();

223+

const timeoutError = { output: { statusCode: DisconnectReason.timedOut } };

224+

const waitForConnection = vi

225+

.fn()

226+

.mockRejectedValueOnce(timeoutError)

227+

.mockRejectedValueOnce(timeoutError);

228+

const createSocket = vi.fn(async () => replacementSock);

229+230+

const result = await waitForWhatsAppLoginResult({

231+

sock: initialSock as never,

232+

authDir: "/tmp/wa-auth",

233+

isLegacyAuthDir: false,

234+

verbose: false,

235+

runtime: { log: vi.fn() } as never,

236+

waitForConnection: waitForConnection as never,

237+

createSocket: createSocket as never,

238+

});

239+240+

expect(result).toMatchObject({

241+

outcome: "failed",

242+

statusCode: DisconnectReason.timedOut,

243+

error: timeoutError,

244+

});

245+

expect(createSocket).toHaveBeenCalledOnce();

246+

expect(waitForConnection).toHaveBeenCalledTimes(2);

247+

});

248+130249

it("keeps the previous registered controller until a replacement listener is ready", async () => {

131250

const liveController = new WhatsAppConnectionController({

132251

accountId: "work",