Skip to content

Fix reconnection state management#26

Merged
toloco merged 1 commit into
mainfrom
fix-reconnection
Apr 13, 2026
Merged

Fix reconnection state management#26
toloco merged 1 commit into
mainfrom
fix-reconnection

Conversation

@toloco
Copy link
Copy Markdown
Owner

@toloco toloco commented Apr 13, 2026

Summary

Fixes the "WhatsApp is reconnecting" error that users hit when the connection drops and auto-reconnects.

Root cause

The connected channel was a one-shot signal — after it closed on first connect, reconnection events couldn't update state properly. Tools kept returning "reconnecting" even after WhatsApp successfully reconnected.

Fix

  • Replace one-shot connected channel with firstConn (initial wait only)
  • ready atomic bool is the sole source of truth for connection state
  • Debounce disconnect events — only log on actual connected→disconnected transition
  • Track disconnect timestamp for context-aware error messages:
    • < 30s: "reconnecting, try again"
    • > 30s: "connection lost, check internet"
    • Session expired: "run whasapo pair"

Also

  • Cap get_messages limit to 500 (prevents OOM on huge requests)
  • Add SQLite indexes on push_name and media_type for faster queries

Closes #25

Test plan

  • go test ./... -v passes
  • Server connects, disconnect WiFi, reconnect → tools work after reconnect
  • get_messages with limit=999999 caps at 500

the connected channel was one-shot — after first close, reconnection
events couldn't signal properly. replaced with firstConn channel for
initial wait only, atomic ready bool as source of truth for ongoing
state.

also:
- debounce disconnect events (only log on connected→disconnected)
- track disconnect timestamp for better error messages
- context-aware errors: "reconnecting" vs "connection lost" vs "expired"
- cap get_messages limit to 500 to prevent OOM
- add SQLite indexes on push_name and media_type

closes #25
@toloco toloco merged commit 3b80161 into main Apr 13, 2026
1 check passed
@toloco toloco deleted the fix-reconnection branch April 13, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: WhatsApp reconnection fails silently

1 participant