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 <hi@obviy.us>
This commit is contained in:
Ayaan Zaidi
2026-08-12 10:25:47 +05:30
committed by GitHub
parent e30df72045
commit 141f943a41
2 changed files with 9 additions and 6 deletions
@@ -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");
+8 -5
View File
@@ -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(),
};
},