-
-
Notifications
You must be signed in to change notification settings - Fork 69.4k
[Feature]: Add postinstall hook to prevent code-splitting singleton bugs (WhatsApp active-listener, #45994) #47389
Description
Problem
Issue #45994 documents a critical code-splitting bug where active-listener.ts is duplicated across 7 bundle chunks, each with an independent Map() instance. This breaks all proactive WhatsApp outbound sends while inbound and auto-replies work fine.
The community workaround (patching globalThis into each chunk) works perfectly — but gets overwritten on every npm update -g openclaw, leaving users silently broken again.
Proposal
Short-term: postinstall validation
Add a build-time or postinstall check that verifies critical singletons (active-listener.ts, and any others covered by PR #43683) are not duplicated across chunks:
// scripts/verify-singletons.js
const fs = require('fs');
const path = require('path');
const dist = path.join(__dirname, '..', 'dist');
const SINGLETONS = [
{ pattern: 'src/web/active-listener.ts', symbol: 'listeners' },
// add others from PR #43683
];
for (const { pattern, symbol } of SINGLETONS) {
const files = fs.readdirSync(dist, { recursive: true })
.filter(f => f.endsWith('.js'))
.filter(f => fs.readFileSync(path.join(dist, f), 'utf8').includes(pattern));
if (files.length > 1) {
console.error(`SINGLETON VIOLATION: ${pattern} found in ${files.length} chunks: ${files.join(', ')}`);
process.exit(1);
}
}Long-term: Apply resolveGlobalSingleton() pattern to WhatsApp
PR #43683 fixed this exact bug class for Telegram, Slack, Signal, iMessage, and core pipeline singletons using resolveGlobalSingleton(Symbol.for(...)). WhatsApp's src/web/active-listener.ts was missed. Apply the same pattern.
Impact
This bug has been silently breaking WhatsApp outbound for users on v2026.3.12 and v2026.3.13. Multiple reports confirm it:
- WhatsApp active-listener singleton not shared across bundled chunks (outbound sends fail) #45994 (root cause)
- WhatsApp outbound sends broken in v2026.3.12+ — duplicate listeners Map instances #46251, WhatsApp outbound sends fail: dual Map instance bug in active-listener across bundles #46414, [Bug]: WhatsApp: message send fails "No active WhatsApp Web listener" but react succeeds (likely duplicate active-listener module) #46659 (duplicates)
- openclaw message send fails for WhatsApp only — No active WhatsApp Web listener (regression in 3.12, Telegram unaffected) #45511 (regression report)
- [Bug] message tool "No active WhatsApp Web listener" persists after hard restart (2026.3.13) #47313 (persists in 2026.3.13)
- [Bug]: WhatsApp: "No active WhatsApp Web listener" for all proactive sends (message tool, TTS) — auto-replies work fine #45391 (earliest report, 2026-03-13)
The workaround works but requires manual re-application after every update, which most users won't do.
Environment
- Confirmed on macOS arm64 (Node 24.12.0) and Linux (Node 22.22.0)
- Both npm and pnpm global installs affected