Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs(integration): describe the integration DLQ as written inbound only (#1821)

Yudhi Armyndharis8f41c9a70a37
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bad41243e..0e44aac92 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -110,12 +110,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Documentation
+- The integration docs say `integration_delivery_failures` is written only for failed inbound deliveries.
- The API reference, database design, runbook and glossary describe when the webhook outbox copy is retired after a sweep replay or a redrive, and which rows neither path recovers.
- Document the memory media messages and parked webhook deliveries hold during a media burst, and the settings that limit it.
- The storage migration guide says to check the store size and file count against the import caps before switching backends, and how to re-run an aborted import.
- The README and architecture docs describe the Local/S3 storage backend as the live media store, not a backup target.
- Document how to recover a lost admin API key without revoking the other keys, on source, Compose and Helm installs.
-- The integration docs say `integration_delivery_failures` holds only failed inbound deliveries.
- The webhook runbook documents the ADMIN delivery-failure redrive and no longer says failed deliveries retry on their own.
### Dependencies
diff --git a/docs/05-database-design.md b/docs/05-database-design.md
index a652d920a..5542ad27c 100644
--- a/docs/05-database-design.md
+++ b/docs/05-database-design.md
@@ -714,7 +714,7 @@ The data connection also owns:
- **`plugin_instances`** — one configured instance of an adapter plugin, keyed `${pluginId}:${instanceId}` (`src/modules/integration/entities/plugin-instance.entity.ts`); holds the host-minted ingress HMAC secret, masked on API reads.
- **`ingress_events`** — persist-before-ack durable row and inbound dedup oracle, unique on `(pluginId, instanceId, providerDeliveryId)` (`src/modules/integration/entities/ingress-event.entity.ts`). The full payload is retired to `NULL` once dispatch is settled, leaving a slim dedup marker.
- **`conversation_mappings`** — bidirectional WA-chat ↔ provider-conversation mapping plus handover state (`src/modules/integration/entities/conversation-mapping.entity.ts`).
-- **`integration_delivery_failures`** — DLQ-of-record for failed inbound (ingress) deliveries, the rows the instance redrive replays; only the ingress path writes it, so `direction` is always `inbound` (`src/modules/integration/entities/integration-delivery-failure.entity.ts`).
+- **`integration_delivery_failures`**: DLQ-of-record for failed inbound (ingress) deliveries, the rows the instance redrive replays; only the ingress path writes it, and only as `inbound`. A data import restores each row's `direction` as stored, and redrive replays only `inbound` rows (`src/modules/integration/entities/integration-delivery-failure.entity.ts`).
- **`baileys_stored_messages`** — Baileys engine message store — the serialized WAMessage proto (`src/engine/adapters/baileys-stored-message.entity.ts`); present only when the Baileys engine is used. (Credentials live on the filesystem, not here.)
- **`lid_mappings`** — LID↔phone-number identity mappings (`src/engine/identity/lid-mapping.entity.ts`).
- **`chat_states`** (engine): per-session mute, archive and pin state of each Baileys chat (`src/engine/adapters/baileys-chat-state.entity.ts`), keyed `(sessionId, chatId)`. `chatId` is the person's phone JID (`<phone>@s.whatsapp.net`) whenever their lid resolves, so a state WhatsApp syncs under the lid and one set through the phone number land on the same row; it stays `<lid>@lid` while the lid is unresolved, and a row found under the lid later is folded onto the phone JID on the chat's next change (reads and the fold take each field from the newest row that observed it: `observed` lists the fields a row has seen, and null, on a row not written since the column was added, means the fields it holds a set value for; the next write that can read the row records the list). WhatsApp does not re-deliver that state, so it is kept in backups. A chat deleted on the phone or through the API loses its row, so a later message starts it clean.
diff --git a/docs/25-integration-fabric.md b/docs/25-integration-fabric.md
index 863e03401..c489b614c 100644
--- a/docs/25-integration-fabric.md
+++ b/docs/25-integration-fabric.md
@@ -161,8 +161,9 @@ Four tables live on the data connection, each created by a hand-authored dual-di
oracle is not an audit log, and `<= 0` falls back to the default rather than disabling the prune
into unbounded growth).
- **`integration_delivery_failures`** — a dead-letter record of last resort for inbound (ingress)
- deliveries, with a redrive path (added in P1). Only the ingress path writes it, so every row's
- `direction` is `inbound`; a failed outbound call to the provider is not dead-lettered.
+ deliveries, with a redrive path (added in P1). Only the ingress path writes it, and only as
+ `inbound`; a failed outbound call to the provider is not dead-lettered. A data import restores each
+ row's `direction` as stored, and redrive replays only `inbound` rows.
## 25.6 Security model
@@ -280,8 +281,10 @@ row), and a row whose instance or bound session was deleted is dropped, since re
deleted instance and a session delete purges its dead letters. A delivery whose completed job was
already removed from the queue, or whose job lookup failed while Redis was down (or, for a Redis
slow to start at boot, not yet connected within that first-connect wait), is dead-lettered anyway and
-may already have been delivered: check before redriving it. A dead-letter row the startup prune writes
-before plugins load carries no conversation id, and its redrive takes the per-instance lane. There is
+may already have been delivered: check before redriving it. A dead-letter row the prune writes takes
+its conversation id from the plugin's current manifest route, as the live path does, so a row whose
+plugin package or route is gone, whose route declares no `conversationId` pointer, or whose pointer
+does not resolve in that delivery carries none and its redrive takes the per-instance lane. There is
deliberately no per-instance row-count cap: eviction under a flood of forged delivery ids would
silently drop legit dedup rows and re-admit their replays, which is worse than the bounded growth it
would prevent.
diff --git a/src/common/docs-governance.spec.ts b/src/common/docs-governance.spec.ts
index 816883c8f..882aa3d9d 100644
--- a/src/common/docs-governance.spec.ts
+++ b/src/common/docs-governance.spec.ts
@@ -319,6 +319,34 @@ describe('governance docs match the repository', () => {
expect(faq).toMatch(/last seeded, which still works while that key is an active, unscoped ADMIN key/);
});
+ // The gateway writes only 'inbound' dead letters, but the data import copies `direction` as stored.
+ // Plugin manifests load in the global PluginsModule's onModuleInit, before the startup prune runs, so
+ // a prune-written dead letter derives its conversation id from the current manifest route.
+ it('describes integration dead letters as written inbound and restored as stored', () => {
+ const flat = (text: string): string => text.replace(/\s+/g, ' ');
+ const importer = between(read('src/modules/infra/table-importers.ts'), "key: 'integrationDeliveryFailures'", '}),');
+ expect(importer).toMatch(/map: \(df: IntegrationDeliveryFailureRow\) => \[\s*df\.id,\s*df\.direction,/);
+ expect(read('src/modules/integration/redrive.service.ts')).toMatch(/direction: 'inbound'/);
+ expect(read('src/core/plugins/plugins.module.ts')).toMatch(/@Global\(\)/);
+ expect(read('src/core/plugins/plugin-loader.service.ts')).toMatch(
+ /onModuleInit\(\): void \{\s*this\.scanner\.scanAtBoot\(\)/,
+ );
+ const table = '- **`integration_delivery_failures`**';
+ const fabric = flat(read('docs/25-integration-fabric.md'));
+ for (const entry of [
+ between(flat(read('docs/05-database-design.md')), table, ' - **'),
+ between(fabric, table, ' ## '),
+ ]) {
+ expect(entry).not.toMatch(/`direction` is (always )?`inbound`/);
+ expect(entry).toContain("A data import restores each row's `direction` as stored");
+ }
+ expect(fabric).not.toMatch(/before plugins load/);
+ expect(fabric).toContain(
+ "A dead-letter row the prune writes takes its conversation id from the plugin's current manifest route, as the live path does",
+ );
+ expect(fabric).toContain('or whose pointer does not resolve in that delivery carries none');
+ });
+
it('keeps the README non-affiliation disclaimer', () => {
const section = between(read('README.md'), '## Disclaimer', '\n## ');
expect(section).toMatch(/not affiliated/);
diff --git a/src/modules/infra/table-importers.ts b/src/modules/infra/table-importers.ts
index a3cc3974b..7b6db5b49 100644
--- a/src/modules/infra/table-importers.ts
+++ b/src/modules/infra/table-importers.ts
@@ -460,7 +460,7 @@ export const TABLE_IMPORTERS: AnyTableImporter[] = [
],
}),
- // Import integration delivery failures (inbound + outbound DLQ)
+ // Import integration delivery failures (inbound DLQ; direction restored as stored)
defineTableImporter({
key: 'integrationDeliveryFailures',
label: 'integration delivery failure',