ARIA: discard stale outgoing WhatsApp messages on reconnect#348
Open
holoduke wants to merge 1 commit into
Open
ARIA: discard stale outgoing WhatsApp messages on reconnect#348holoduke wants to merge 1 commit into
holoduke wants to merge 1 commit into
Conversation
…connect
When the WhatsApp socket drops and sendMessage is called while disconnected,
the call now queues the message instead of throwing. On 'open', the queue is
drained, but messages older than staleMsgThresholdMs (default 5 min, env
STALE_MSG_THRESHOLD_MS) are discarded and logged with reason. Scheduled
messages can opt out via { scheduled: true }.
On 2026-05-20 ~12:15-12:16 UTC, after a brief offline period, sends queued
from before the disconnect were flushed and arrived stale (e.g. "How is it
going" to Gillis), causing social damage. 5-min threshold matches the think
tick interval — anything older than one tick is by definition stale context.
Intent-summary: queued WhatsApp sends from before a disconnect were flushed on reconnect without checking their age, delivering messages with stale context to contacts.
Intent-tokens: whatsapp,stale,reconnect,queue,offline,flush,context
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the offline-reconnect bug from 2026-05-20 ~12:15 UTC where ARIA sent stale outgoing messages (notably "How is it going" to Gillis and a DM to 31620510229) right after a brief offline period. The sends had been queued before the disconnect and were flushed verbatim on reconnect, with the original context long gone.
Changes
backend/integrations/whatsapp.tspendingSendQueueof{ jid, text, queuedAt, scheduled, resolve, reject }.sendMessage(jid, text, options?)now queues with a timestamp whenisConnected === falseinstead of throwing. The returned promise resolves/rejects once the queue is drained.connection.update→"open",flushPendingSendQueue()runs: it discards any non-scheduled message where(now - queuedAt) > staleMsgThresholdMs, logs the discard with jid/age/preview, rejects the caller's promise with a descriptive error, and sends the rest.{ scheduled: true }.backend/brain-config.tsstaleMsgThresholdMs: numberfield onBrainConfig(default5 * 60 * 1000, env overrideSTALE_MSG_THRESHOLD_MS). 5 minutes matches the think-tick interval — anything older than one tick is by definition stale context.Why 5 minutes
Conversation context turns over roughly every think tick. A message that's been sitting in the queue for longer than that was almost certainly drafted in response to a state the recipient is no longer in.
Test plan
tsc --noEmit) passes — verified locally.brain-delivery.ts,owner-handler.ts,brain-ticks.ts) still handle rejected promises gracefully (all already wrap in try/catch).🤖 Generated with Claude Code