# WhatsApp Production Root-Cause Audit

Date: 2026-10-13  
Scope: repository analysis plus the production observations supplied with the task.  
Safety: no WhatsApp message, reconnect, container restart, session mutation, or destructive database operation was performed.

## Executive summary

The evidence does **not** establish why Meta temporarily restricted the account. The supplied 72-hour sample shows moderate aggregate traffic, but it also shows repeated business-initiated follow-ups without a recorded reply. Database history cannot prove consent, delivery, or the historical first WhatsApp interaction.

The application does contain independently verifiable reliability and control defects:

1. The scheduler runs the legacy mutating `evolution:health` command every minute. When the state is anything other than `open`, it calls `/instance/connect/{instance}` without a durable per-instance cooldown. It can also send alert and recovery messages through the same WhatsApp channel being diagnosed.
2. The host watchdog separately performs recovery after three failures and a 15-minute cooldown. The two recovery actors are not coordinated, which explains how app reconnect attempts can continue while the watchdog is also restarting infrastructure.
3. Outbound transport is selected through `WhatsAppService`, but send lifecycle control is not centralized. Manual text, manual resend, retry, media, auto-reply, and health alerts call the provider from different components.
4. Retry idempotency is a check-then-send operation. Two workers can read the same failed row before either updates it and both can dispatch it.
5. Auto-reply cooldown is also check-then-send. The log is created only after the provider call, so concurrent incoming jobs can both pass the cooldown check.
6. Webhook ingestion has a database unique key and message rows have a unique provider id. That is a strong baseline. Status changes are monotonic, but status-event dispatch itself has no event-level durable receipt record.
7. There is no modeled business-message consent, purpose, or opt-out state. There is also no auditable guard for repeated business-initiated follow-ups.
8. Provider HTTP success is recorded as `sent`/accepted-pending, not delivered/read, which is appropriate. However, ordinary HTTP 5xx errors are classified safe to retry even though some upstream failures can occur after acceptance; only network timeouts are currently treated as ambiguous.

## Evidence boundaries

### Confirmed from production observations supplied with the task

- 726 total messages in the stated 72-hour sample: 559 incoming and 167 outgoing.
- 62 conversations contained outgoing messages; maximum observed outgoing volume was 33 in one hour.
- Send-attempt distribution was 16 with zero attempts, 150 with one, and 1 with three.
- 37 conversations appeared to begin with an outgoing stored message; 27 had no later stored reply and 18 of those had multiple outgoing messages.
- Instance `main` remained `connecting`; the enabled watchdog restarted Evolution repeatedly without restoring readiness.
- cURL 28, cURL 56, HTTP 500, and malformed Evolution logging/JSON errors were observed.

These facts show operational risk. They do not prove spam, missing consent, delivery, or Meta's restriction reason.

### Confirmed from repository code

- Laravel defaults to SQLite; the local `.env` also selects SQLite. Evolution's PostgreSQL is a separate system.
- `routes/console.php` schedules `evolution:health` every minute.
- `EvolutionHealthCommand` calls `GET /instance/connect/{instance}` whenever state is not `open` and reconnect is enabled. HTTP 200 is only logged and is not treated as a proven connected session.
- `EvolutionHealthCheckCommand --no-recovery` and `EvolutionHealthChecker` already provide a deeper read-only root/connection/database-backed probe.
- `ops/evolution-watchdog.sh` has a lock, a three-failure threshold, and a 900-second default cooldown, but it is unaware of reconnects initiated by the legacy Laravel command.
- `EvolutionProvider` is the only Evolution HTTP sender, selected through `WhatsAppService`; callers nevertheless own validation, persistence, audit, retry, and locking separately.
- `UpdateMessageStatusJob` enforces forward-only status transitions.
- `webhook_events.event_id` and `messages.wa_message_id` are unique.
- No consent/opt-out domain fields or enforcement were found.

### Local-only observations (not production evidence)

The development SQLite database contains zero auto-reply rules/logs, six outgoing messages, three failed outgoing messages, and no pending/failed queue jobs. Local logs contain historical P2024 and send-failure signatures, but those logs are not asserted to be the current production state. Production auto-reply enablement and volume remain unverified until aggregate queries are run on the production database.

## Outbound send map

| Path | Entry point | Provider call | Persistence/result handling | Finding |
|---|---|---|---|---|
| Manual text | `MessageController::store` | `WhatsAppService::sendText` | `OutboundSendManager` | No atomic dispatch claim or client idempotency key |
| Manual resend | `MessageController::resend` | `sendText` | `OutboundSendManager` | Check-then-send race |
| Automatic retry | `RetryOutboundSendJob` | `sendText` | `OutboundSendManager` | Check-then-send race between workers |
| Manual media/voice | `MediaController::upload` | `sendMedia` | Part direct updates, part manager on failure | Success path bypasses manager/audit conventions |
| Keyword auto-reply | `ProcessIncomingMessageJob::applyAutoReply` | `sendText` | Creates log and message after the call | Cooldown race; send occurs inside the incoming DB transaction |
| Health incident/recovery alerts | `EvolutionHealthCommand` | `sendText` | Settings latch only | Hidden automation; uses failing WhatsApp channel |
| Incoming/outgoing phone echoes | webhook jobs | No outbound send | Store/dedupe only | Not a sender |
| Message edit/delete | `MessageEditService`, controller destroy | provider edit/delete endpoints | Separate audit/best-effort logic | Outbound mutation, not a new logical message |

No scheduled bulk/marketing sender was found. Creating a contact/start-chat creates database records only and does not send a message.

## Prioritized findings

### Critical

1. **Uncoordinated automatic recovery loop.** The one-minute Laravel command mutates connection state while the watchdog independently performs heavy recovery. This is a confirmed code defect and is consistent with the reported repeated reconnect/restart pattern.
2. **No concurrency-safe outbound dispatch claim.** Duplicate jobs or simultaneous manual/automatic retries can send the same logical message twice.
3. **No consent or opt-out enforcement for business-initiated sends.** The system cannot demonstrate why a business-initiated message was permitted.

### High

1. **Auto-reply cooldown race and no incoming-event reservation.** Concurrent jobs can emit duplicate replies.
2. **Outbound lifecycle is not centralized.** Media and auto-reply success paths bypass the common result manager; audit data and failure semantics differ.
3. **No repeated-unanswered-follow-up guard.** Operators can continue sending without a customer reply and receive no explicit warning/block reason.
4. **Ambiguous provider failures are under-modeled.** Timeout is preserved as unknown acceptance, but generic 5xx is assumed unaccepted/retryable.
5. **Sensitive identifiers in logs.** Evolution send logs include the destination phone number; webhook missing-id logging can emit a full request payload.

### Medium

1. Connection state vocabulary is provider-native (`open`, `connecting`, `error`) rather than the required normalized state machine.
2. Queue concurrency differs between systemd/supervisor and Horizon; conservative limits are not expressed as one operational policy.
3. Status webhook duplicates are harmless at the message row but not durably deduplicated as individual status events.
4. Database queue `retry_after` defaults to 90 seconds while the production worker allows jobs to run for 600 seconds, creating a potential duplicate execution window for long jobs.

### Low

1. Local diagnostics cannot establish production auto-reply rules or volumes.
2. The older deployment guide contains generic paths/worker examples that differ from the repository's production unit files.

## Root-cause position

The confirmed application root cause for the **recovery loop** is the coexistence of the mutating minute-by-minute Laravel health command and the independent watchdog. The confirmed causes of **duplicate-send risk** are non-atomic check-then-send flows in retry and auto-reply paths.

The cause of Meta's temporary restriction remains **undetermined**. Plausible contributors include business-initiated messaging without auditable consent, repeated unanswered follow-ups, operator behavior, phone-originated messages, provider/session instability, or Meta-side signals unavailable to this database. None should be presented as proven from the supplied sample.

## Production verification still required

Run only read-only aggregate checks after approval:

- Active auto-reply rule count grouped by cooldown (no reply text).
- Auto-reply sent/failed counts by rule id and hour (no phone/body).
- Message outcomes grouped by `error_category`, `send_attempts`, hour, and instance.
- Health-check state transitions and watchdog recovery timestamps.
- Queue worker count and `retry_after`/timeout alignment.
- Provider evidence for ambiguous sends by stored provider id.
- Confirmation of which instance (`main` or `main966`) each send used.

