From 141f943a411cfbf5d1a91968652570d484d2ff93 Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Wed, 12 Aug 2026 10:25:47 +0530 Subject: [PATCH] fix(delivery): clear resolved ambiguity notices (#122438) Clear stale uncertainty debt when the same final reaches an authoritative terminal outcome, preventing false notices on the next inbound turn. Co-authored-by: Ayaan Zaidi --- src/infra/outbound/delivery-completion.test.ts | 2 +- src/infra/outbound/delivery-completion.ts | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/infra/outbound/delivery-completion.test.ts b/src/infra/outbound/delivery-completion.test.ts index 0bbcbddbae49..fabeae0e79bf 100644 --- a/src/infra/outbound/delivery-completion.test.ts +++ b/src/infra/outbound/delivery-completion.test.ts @@ -136,7 +136,7 @@ describe("pending-final delivery completion", () => { it("does not owe a notice for the pre-dispatch claim or terminal outcomes", async () => { await installContextOnPendingFinal(); - // prepared -> unknown is the pre-I/O claim on every healthy send. + await settlePendingFinalDelivery(completion, "queued", ["prepared"]); await settlePendingFinalDelivery(completion, "unknown", ["prepared", "queued"]); await settlePendingFinalDelivery(completion, "delivered"); diff --git a/src/infra/outbound/delivery-completion.ts b/src/infra/outbound/delivery-completion.ts index 6cce7418562d..78a13b0241db 100644 --- a/src/infra/outbound/delivery-completion.ts +++ b/src/infra/outbound/delivery-completion.ts @@ -94,9 +94,6 @@ export async function settlePendingFinalDelivery( current === "suppressed" || (current === "unknown" && state === "unknown"); settled = terminal ? current : state; - // Unknown affirmed after a claimed send is ambiguity the user must hear - // about: record durable notice debt for the next same-route turn. The - // prepared->unknown transition is the pre-I/O claim and never owes one. const pending = internalEntry.pendingFinalDelivery; const existingNotice = internalEntry.pendingDeliveryNotice; const owedNotice = @@ -115,7 +112,13 @@ export async function settlePendingFinalDelivery( }, } : undefined; - if (settled === current && !owedNotice) { + const clearsNotice = + settled !== "queued" && + settled !== "unknown" && + existingNotice?.intentId === pending.intentId; + // The pre-I/O claim preserves crash-window ambiguity. Any authoritative + // fate for that intent must clear debt before a later turn can surface it. + if (settled === current && !owedNotice && !clearsNotice) { return null; } wakeRecovery = @@ -135,7 +138,7 @@ export async function settlePendingFinalDelivery( ...internalEntry.pendingFinalDelivery, deliveries: deliveries.with(index, { id: completion.deliveryId, state: settled }), }, - ...owedNotice, + ...(clearsNotice ? { pendingDeliveryNotice: undefined } : owedNotice), updatedAt: Date.now(), }; },