Skip to content

fix(whatsapp): prevent duplicate startup sockets and add diagnostics #687

Closed

Description

@khaira777

Summary

After restarting Flo Cafe on macOS with WhatsApp already paired, the app can report that it is disconnected until the user manually disconnects and reconnects. The fallback share flow can also report that WhatsApp failed to open.

Findings

  • WhatsApp initialization is currently reachable from two startup paths.
  • Socket creation checks for an existing socket before asynchronous auth and Baileys setup completes, allowing concurrent sockets to share one auth state.
  • The renderer fallback uses window.open while Electron opens external URLs asynchronously, so the renderer cannot observe an external-open failure.
  • Existing packaged logs do not contain enough WhatsApp lifecycle detail to diagnose the failure.

Scope

  • Keep one WhatsApp startup owner and serialize socket startup/reconnect work.
  • Add redacted lifecycle, phase, connection, reconnect, and send-result diagnostics.
  • Keep credentials, QR data, message bodies, phone numbers, and tokens out of logs.
  • Add a result-bearing and wa.me-constrained external-open path.
  • Add regression and integration coverage for the startup race and opener result.

Acceptance criteria

  • A cold restart with persisted WhatsApp credentials creates one socket attempt and reaches connected without manual reconnect.
  • Concurrent startup requests create one socket.
  • Reconnect and startup failures produce stable status reasons and useful redacted logs.
  • WhatsApp share failures are reported only when the system opener fails.
  • Tests cover the new behavior and existing WhatsApp flows remain green.

Activity

  1. self-assigned this
    on Sep 9, 2026
  2. added
    area:frontend
    area:backend
    platform:macos
    Ready-For-PR
    on Sep 9, 2026
  3. khaira777 commented on Sep 9, 2026

    @khaira777
    ContributorAuthor

    Work in progress. Investigation found duplicate WhatsApp initialization during startup, allowing concurrent Baileys sockets to use the same persisted auth state. The fix will serialize socket startup, add redacted lifecycle diagnostics, and make external WhatsApp-open failures observable.

  4. khaira777 commented on Sep 10, 2026

    @khaira777
    ContributorAuthor

    closed in #688

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Ready-For-PRarea:backendarea:frontendplatform:macos

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions