Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(ingress): replay a stranded delivery with its HTTP method

Yudhi Armyndharis24722cadd19a
diff --git a/src/modules/integration/entities/ingress-event.entity.ts b/src/modules/integration/entities/ingress-event.entity.ts
index c5c80e5cf..c0e527e00 100644
--- a/src/modules/integration/entities/ingress-event.entity.ts
+++ b/src/modules/integration/entities/ingress-event.entity.ts
@@ -50,7 +50,15 @@ export class IngressEvent {
// only replays 'pending' rows, which always still carry the payload. NULL on a 'pending' row is
// unreadable history (e.g. imported without one) — the reconciler skips it loudly.
@Column({ type: jsonColumnType(), nullable: true })
- payload!: { headers: Record<string, string>; query: Record<string, string>; body: string; rawBody: string } | null;
+ // `method` is the request's HTTP method, so a replay reaches the handler as the live attempt did. Rows
+ // written before it was persisted lack it, and dispatch falls back to 'POST' for them.
+ payload!: {
+ headers: Record<string, string>;
+ query: Record<string, string>;
+ body: string;
+ rawBody: string;
+ method?: string;
+ } | null;
// sha256 hex of the rawBody, written at recordOrSkip. Survives payload retirement so operators can
// still correlate a dedup row with a provider delivery without storing the payload. NULL on rows
diff --git a/src/modules/integration/ingress-reconciler.service.spec.ts b/src/modules/integration/ingress-reconciler.service.spec.ts
index 738163b75..476b84001 100644
--- a/src/modules/integration/ingress-reconciler.service.spec.ts
+++ b/src/modules/integration/ingress-reconciler.service.spec.ts
@@ -104,6 +104,22 @@ describe('IngressReconcilerService.sweep', () => {
expect(event.lastDispatchAt).toBeInstanceOf(Date);
});
+ it('replays the persisted HTTP method, and carries it into the dead-letter row', async () => {
+ await insertEvent({
+ payload: { headers: {}, query: {}, body: '{}', rawBody: '{}', method: 'PUT' },
+ dispatchAttempts: 4,
+ });
+ enqueue.mockResolvedValue({ outcome: 'failed', error: 'sandbox 5xx' });
+
+ await service.sweep(OPTS);
+
+ const [data] = enqueuedJobs()[0];
+ expect(data.method).toBe('PUT');
+ expect(data.payload).toEqual({ headers: {}, query: {}, body: '{}', rawBody: '{}' });
+ const [dlq] = await failures.find({ where: { deliveryId: 'd-1' } });
+ expect((dlq.payload as { method?: string }).method).toBe('PUT');
+ });
+
it('retires the row payload once the replay is dispatched (the job data already carried it)', async () => {
const id = await insertEvent();
diff --git a/src/modules/integration/ingress-reconciler.service.ts b/src/modules/integration/ingress-reconciler.service.ts
index c24879bac..02ab89e8a 100644
--- a/src/modules/integration/ingress-reconciler.service.ts
+++ b/src/modules/integration/ingress-reconciler.service.ts
@@ -267,8 +267,8 @@ export class IngressReconcilerService implements OnModuleInit, OnModuleDestroy {
}
/**
- * Rebuild the dispatch job from the persisted row. `method` is the one request field the row does
- * not persist — dispatchWebhookForInstance defaults it to 'POST' (the same tolerance RedriveService
+ * Rebuild the dispatch job from the persisted row. A row written before the method was persisted
+ * has none, and dispatchWebhookForInstance defaults it to 'POST' (the same tolerance RedriveService
* applies to legacy DLQ rows). providerConversationId is re-derived from the CURRENT manifest route
* so the replay joins the same per-conversation ordering lane as live deliveries instead of
* degrading to the per-instance lane; a hot-swapped/missing route just yields no key.
@@ -277,14 +277,16 @@ export class IngressReconcilerService implements OnModuleInit, OnModuleDestroy {
const route = this.loader
.getPlugin(row.pluginId)
?.manifest.ingress?.find(candidate => candidate.route === row.route);
+ const { method, ...payload } = row.payload;
return {
pluginId: row.pluginId,
instanceId: row.instanceId,
route: row.route,
+ method,
deliveryId: row.providerDeliveryId,
sessionId: row.sessionId ?? undefined,
- providerConversationId: extractConversationId(route?.conversationId, row.payload.headers, row.payload.rawBody),
- payload: row.payload,
+ providerConversationId: extractConversationId(route?.conversationId, payload.headers, payload.rawBody),
+ payload,
};
}