Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(engine): report a failed WhatsApp Web version resolve instead of degrading in silence

Yudhi Armyndharisc39bdf0655de
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 86458ae26..42670545b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `docs/18-sdk-design.md` and the SDK READMEs now list every method the five clients ship: the whole `media` resource plus 26 methods across nine others were missing, so server-side media conversion, presence subscription, session config and webhook delivery diagnostics read as unavailable.
- The engine parity check no longer skips optional interface members. `probeLiveness?()` did not match its member pattern, so the capability matrix could omit any optional method while the check reported green; it now has a row recording that wwjs probes with a real round trip and Baileys with a local check.
- `.env.example` and the troubleshooting FAQ no longer name a specific WhatsApp Web build to pin with `WWEBJS_WEB_VERSION`. The build they named has since been withdrawn from the registry, and a build the registry no longer serves is fetched, missed and silently ignored — so an operator following the FAQ's own workaround got the default behaviour while the log claimed the pin had been applied. Both now point at the registry's `html/` folder for a build that is currently served.
+- A WhatsApp Web build that cannot be resolved from the wa-version registry is now reported (`web_version_resolve_failed`) with the reason, the registry URL and the remedy. A host that cannot reach the registry — a proxy, a firewalled VPS, regional blocking — silently continued without a pin and let whatsapp-web.js pick the build itself, which is the "authenticates then never reaches ready" class the pin exists to prevent; nothing was logged, so there was nothing to grep for. The existing one-minute backoff already bounds how often the warning can repeat.
### Security
diff --git a/src/engine/wa-web-version.spec.ts b/src/engine/wa-web-version.spec.ts
index ec12fecee..0e8430717 100644
--- a/src/engine/wa-web-version.spec.ts
+++ b/src/engine/wa-web-version.spec.ts
@@ -8,6 +8,7 @@ import {
pickSettledWebVersion,
resolveCurrentWebVersion,
resolveWebVersionPin,
+ WA_VERSION_REGISTRY_URL,
WEB_VERSION_SETTLE_MS,
} from './wa-web-version';
@@ -173,3 +174,58 @@ describe('resolveWebVersionPin remote-trust warning', () => {
);
});
});
+
+// A failed resolve degrades the engine to whatsapp-web.js's own version selection — the #488 class
+// the pin exists to prevent. It used to do so in total silence, so the operator had nothing to grep.
+describe('resolveCurrentWebVersion failure warning', () => {
+ const json = (body: unknown) => ({ ok: true, status: 200, json: () => Promise.resolve(body) });
+
+ beforeEach(() => {
+ __resetWebVersionCache();
+ mockWarn.mockClear();
+ });
+ afterEach(() => __resetWebVersionCache());
+
+ const failureMeta = () => (mockWarn.mock.calls[0] as [string, Record<string, string>])[1];
+
+ it('warns when the registry cannot be reached', async () => {
+ const fetcher = jest.fn(() => Promise.reject(new Error('getaddrinfo ENOTFOUND raw.githubusercontent.com')));
+ await expect(resolveCurrentWebVersion(fetcher as never)).resolves.toBeNull();
+ expect(mockWarn).toHaveBeenCalledTimes(1);
+ const meta = failureMeta();
+ expect(meta.action).toBe('web_version_resolve_failed');
+ expect(meta.reason).toContain('ENOTFOUND');
+ expect(meta.registry).toBe(WA_VERSION_REGISTRY_URL);
+ expect(meta.remedy).toContain('WWEBJS_WEB_VERSION');
+ });
+
+ it('warns when the registry answers a non-ok status', async () => {
+ const fetcher = jest.fn(() => Promise.resolve({ ok: false, status: 503, json: () => Promise.resolve({}) }));
+ await expect(resolveCurrentWebVersion(fetcher as never)).resolves.toBeNull();
+ expect(mockWarn).toHaveBeenCalledTimes(1);
+ expect(failureMeta().reason).toContain('503');
+ });
+
+ it('warns when the registry answers with no usable build', async () => {
+ const fetcher = jest.fn(() => Promise.resolve(json({ currentVersion: null, versions: [] })));
+ await expect(resolveCurrentWebVersion(fetcher as never)).resolves.toBeNull();
+ expect(mockWarn).toHaveBeenCalledTimes(1);
+ expect(failureMeta().reason).toContain('no usable build');
+ });
+
+ it('stays silent on a successful resolve', async () => {
+ const fetcher = jest.fn(() => Promise.resolve(json({ currentVersion: '2.3000.SOLO-alpha' })));
+ await expect(resolveCurrentWebVersion(fetcher as never)).resolves.toBe('2.3000.SOLO-alpha');
+ expect(mockWarn).not.toHaveBeenCalled();
+ });
+
+ // The warning repeats so it survives a bounded log window, but the existing backoff is what keeps
+ // that from becoming a per-call flood: the second call returns before the fetcher is even reached.
+ it('does not re-warn inside the failure backoff window', async () => {
+ const fetcher = jest.fn(() => Promise.reject(new Error('boom')));
+ await resolveCurrentWebVersion(fetcher as never);
+ await resolveCurrentWebVersion(fetcher as never);
+ expect(fetcher).toHaveBeenCalledTimes(1);
+ expect(mockWarn).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/src/engine/wa-web-version.ts b/src/engine/wa-web-version.ts
index 535c98584..b842a97d9 100644
--- a/src/engine/wa-web-version.ts
+++ b/src/engine/wa-web-version.ts
@@ -65,6 +65,32 @@ function warnRemoteTrustOnce(pin: WebVersionPin): void {
);
}
+/**
+ * Report a failed registry resolve. Without this the degradation is invisible: the fetch is
+ * swallowed, `resolveWebVersionPin` returns undefined, and the adapter logs only inside
+ * `if (versionPin)` — so a host that cannot reach the registry silently falls back to
+ * whatsapp-web.js's own version selection, which is the failure class the pin exists to prevent
+ * (#488), with nothing in the log to grep for.
+ *
+ * Deliberately NOT once-per-process like `warnRemoteTrustOnce`. The state is ongoing rather than a
+ * one-time decision, and an operator diagnosing a session days into a container's life reads a
+ * bounded log window (`docker compose logs --tail=…`) — a warning emitted only at first failure
+ * would have scrolled away exactly when it is needed. Repetition is already bounded: the
+ * `lastFailureAt` backoff returns before the fetch, so at most one attempt (hence one warning) per
+ * FAILURE_BACKOFF_MS.
+ */
+function warnResolveFailed(reason: string): void {
+ logger.warn('Could not resolve a WhatsApp Web build from the wa-version registry — continuing WITHOUT a pin', {
+ action: 'web_version_resolve_failed',
+ reason,
+ registry: WA_VERSION_REGISTRY_URL,
+ consequence:
+ "whatsapp-web.js selects the build itself, which on some setups authenticates then never reaches 'ready'",
+ remedy:
+ 'confirm the host can reach the registry URL, or set WWEBJS_WEB_VERSION to an exact build (or "off" to accept the first-party build)',
+ });
+}
+
function buildRemotePin(version: string): WebVersionPin {
const template = process.env.WWEBJS_WEB_VERSION_REMOTE_PATH?.trim() || DEFAULT_REMOTE_TEMPLATE;
return {
@@ -129,12 +155,14 @@ export async function resolveCurrentWebVersion(fetcher: typeof fetch = fetch): P
return picked;
}
lastFailureAt = Date.now(); // nothing usable — back off, then retry
+ warnResolveFailed('the registry carried no usable build');
return null;
} finally {
clearTimeout(timer);
}
- } catch {
+ } catch (error) {
lastFailureAt = Date.now(); // fetch failed — back off, then retry
+ warnResolveFailed(error instanceof Error ? error.message : String(error));
return null;
} finally {
inFlight = null;