Skip to content

[Feature]: Add postinstall hook to prevent code-splitting singleton bugs (WhatsApp active-listener, #45994) #47389

@longevityboris

Description

@longevityboris

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions