Skip to content

Commit 7682871

Browse files
committed
fix(whatsapp): release deferred ingress lane so debounce merges same-chat bursts
A deferred claim means the message is sitting in the channel debounce window, not that the conversation lane is busy. WhatsApp inherited the core drain's default deferredLaneOccupancy="hold", so while message 1 waited in the debounce window the per-conversation lane stayed owned and message 2 from the same chat was blocked. Each message then entered a fresh, empty window and paid the full debounceMs, so a burst of N messages became N turns instead of one merged turn (regression of #101335 on WhatsApp after it moved to the shared durable-ingress drain). Mirror Telegram's deferredLaneOccupancy="release" opt-in so same-chat messages can reach the debouncer and merge.
1 parent 392e1c0 commit 7682871

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎extensions/whatsapp/src/inbound/durable-receive.test.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe("createWhatsAppIngressMonitor", () => {
135135
});
136136
});
137137

138-
it("keeps a second same-lane message pending until the first turn adopts", async () => {
138+
it("lets a second same-lane message reach the debouncer while the first is deferred", async () => {
139139
await withTempState(async (stateDir) => {
140140
const queue = createChannelIngressQueueForTests<WhatsAppDurableInboundPayload>({
141141
channelId: "whatsapp",
@@ -175,19 +175,21 @@ describe("createWhatsAppIngressMonitor", () => {
175175
monitor.start();
176176
await monitor.waitForIdle();
177177

178-
// Core drain serializes a conversation lane: msg-4b cannot reach the
179-
// channel debouncer until msg-4a transfers into the reply lane.
180-
expect(dispatched).toEqual(["msg-4a"]);
178+
// Deferred means the message sits in the channel debounce window, not
179+
// that the conversation lane is busy. The lane is released, so msg-4b
180+
// can also reach the debouncer and merge into the same turn.
181+
expect(dispatched).toEqual(["msg-4a", "msg-4b"]);
182+
// msg-4a is still deferred (claim held for debounce adoption); msg-4b
183+
// completed its dispatch and was tombstoned.
181184
expect((await queue.listClaims()).map((row) => row.id)).toEqual([firstId]);
182-
expect((await queue.listPending({ limit: "all" })).map((row) => row.id)).toEqual([secondId]);
185+
expect(await queue.listPending({ limit: "all" })).toEqual([]);
183186

184187
if (!adoptFirst) {
185188
throw new Error("expected first adoption callback");
186189
}
187190
await adoptFirst();
188191
await monitor.waitForIdle();
189192

190-
expect(dispatched).toEqual(["msg-4a", "msg-4b"]);
191193
expect(await queue.listClaims()).toEqual([]);
192194
expect(await queue.listPending({ limit: "all" })).toEqual([]);
193195
await monitor.stop();

‎extensions/whatsapp/src/inbound/durable-receive.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ export function createWhatsAppIngressMonitor(params: {
137137
failedMaxEntries: 450,
138138
},
139139
drain: {
140+
// A deferred claim means the message is sitting in the inbound debounce
141+
// window, not that the conversation lane is busy. Release the lane so a
142+
// same-chat burst can reach the debouncer and merge into one turn;
143+
// holding it starves the merge (see Telegram's identical opt-in).
144+
deferredLaneOccupancy: "release",
140145
resolveNonRetryableFailure: resolveWhatsAppIngressNonRetryableFailure,
141146
deriveLaneKey: (record) => {
142147
try {

0 commit comments

Comments
 (0)