From f7363aea6579e4e681cfeb1d297d5ed93f9146af Mon Sep 17 00:00:00 2001 From: mtoohey Date: Mon, 9 Nov 2026 11:20:41 +0000 Subject: [PATCH] fix(messages): offer Retry as soon as a send fails When the relay refuses a plain-text send it answers in about 50 ms, but the message row stayed quiet until `created_at + 10 s` and only then showed Retry. `deliveryFeedback` applied the 10 s delivery grace to every non-`seen` state, `failed` included. The grace exists to hide uncertainty, and a `failed` send is not uncertain: every path to `failed` (relay refusal, rate-limited `PublishNotSent`, HTTP refusal, pre-publish error) proves the message was not delivered, while a transport error mid-publish becomes `unknown`. So the grace check now applies only when `delivery !== "failed"`. `sending`, `accepted` and `unknown` keep waiting ten seconds from the message timestamp; a failed send restored after a reload still shows Retry at once. `DeliveryNotice` needs no change: a new row re-renders it, and its grace timer is harmless for failed rows. The `failed` guard is keyed on the delivery state rather than the outbox item's `refused` flag, which never reaches `ChannelMessage`, is dropped on reload, and is not set for rate-limit refusals. Tests: `delivery.test.ts` narrows the ten-second quiet case to unconfirmed states and adds a failed-inside-the-grace case; `DeliveryNotice.test.tsx` rerenders a row inside the grace as `sending`, `failed`, then `unknown` and expects no status, Retry, then no status. Both new tests failed before the fix. `docs/shell-design.md` and `docs/buzz-help.md` describe the new rule. Co-Authored-By: Claude Opus 5.5 Signed-off-by: mtoohey --- docs/buzz-help.md | 2 ++ docs/shell-design.md | 9 ++++--- src/features/messages/DeliveryNotice.test.tsx | 26 ++++++++++++++++++- src/features/messages/delivery.test.ts | 14 +++++----- src/features/messages/delivery.ts | 4 ++- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/docs/buzz-help.md b/docs/buzz-help.md index 5cad4d8354..084e687a21 100644 --- a/docs/buzz-help.md +++ b/docs/buzz-help.md @@ -458,6 +458,8 @@ revokes all of them, and a pairing unused for 30 days expires. **Settings → Shortcuts → Sending messages → Send with ⌘ Enter** (Ctrl+Enter outside Apple platforms) swaps that on this device: Enter adds a line and ⌘/Ctrl+Enter sends. It starts off. +- If a message can't be sent, **Retry** appears under it right away. If its + delivery is only unconfirmed, Buzz waits about ten seconds before saying so. - A plugin can require a recipient for a new conversation. Its default recipient also applies to a saved draft with no recipients. Your text and formatting stay. A recipient you select takes priority. diff --git a/docs/shell-design.md b/docs/shell-design.md index ed84742a91..1976c4c8e9 100644 --- a/docs/shell-design.md +++ b/docs/shell-design.md @@ -534,10 +534,11 @@ and their retry controls remain visible. The composer preserves the session's text sending and keyboard behavior. Its rounded input and lavender send arrow follow the reference; unsupported upload, mention, and rich-formatting actions are not presented as working controls. -Delivery renders like an ordinary message immediately. After ten seconds from the -message timestamp, unsuccessful/unconfirmed sends show a small notice. Confirmed -messages never show a success label. Retry remains available for failed/unknown -operations. `delivery.test.ts` covers the timing boundary and terminal states. +Delivery renders like an ordinary message immediately. A failed send shows a +small notice as soon as it fails; an unconfirmed send shows one only after ten +seconds from the message timestamp. Confirmed messages never show a success +label. Retry remains available for failed/unknown operations. `delivery.test.ts` +covers the timing boundary and terminal states. The shared conversation layer now supplies bounded thread reading/replies and [session-owned unread indicators](unread.md). These are separate from this styling diff --git a/src/features/messages/DeliveryNotice.test.tsx b/src/features/messages/DeliveryNotice.test.tsx index dc68bd2e10..b0b84d4c2f 100644 --- a/src/features/messages/DeliveryNotice.test.tsx +++ b/src/features/messages/DeliveryNotice.test.tsx @@ -5,7 +5,10 @@ import { afterEach, expect, it, vi } from "vitest"; import { DeliveryNotice } from "./DeliveryNotice"; import type { ChannelMessage } from "../relay/contracts"; -afterEach(cleanup); +afterEach(() => { + cleanup(); + vi.useRealTimers(); +}); const row: ChannelMessage = { id: "message", channelId: "channel", @@ -41,3 +44,24 @@ it.each(["sending", "accepted", "unknown", "failed"] as const)( expect(!!screen.queryByRole("button", { name: "Retry" })).toBe(canRetry); }, ); + +it("offers Retry as soon as a pending send fails, and stays quiet while unconfirmed", () => { + vi.useFakeTimers({ now: 100_050 }); + const pending = { ...row, createdAt: 100 }; + const retry = vi.fn(); + const view = render( + , + ); + expect(screen.queryByRole("status")).not.toBeInTheDocument(); + view.rerender( + , + ); + expect(screen.getByRole("status")).toHaveTextContent( + "Couldn’t send this message.", + ); + expect(screen.getByRole("button", { name: "Retry" })).toBeInTheDocument(); + view.rerender( + , + ); + expect(screen.queryByRole("status")).not.toBeInTheDocument(); +}); diff --git a/src/features/messages/delivery.test.ts b/src/features/messages/delivery.test.ts index 39dbdbd6af..21df24c5b7 100644 --- a/src/features/messages/delivery.test.ts +++ b/src/features/messages/delivery.test.ts @@ -1,19 +1,19 @@ import { expect, it } from "vitest"; import { deliveryFeedback } from "./delivery"; -it("keeps pending and rejected optimistic messages quiet for ten seconds", () => { - for (const delivery of [ - "sending", - "accepted", - "unknown", - "failed", - ] as const) { +it("keeps unconfirmed optimistic messages quiet for ten seconds", () => { + for (const delivery of ["sending", "accepted", "unknown"] as const) { expect( deliveryFeedback({ delivery, createdAt: 100 }, 109999), ).toBeUndefined(); expect(deliveryFeedback({ delivery, createdAt: 100 }, 110000)).toBeTruthy(); } }); +it("shows a failed send at once, inside the grace", () => { + expect( + deliveryFeedback({ delivery: "failed", createdAt: 100 }, 100_000), + ).toBe("Couldn’t send this message."); +}); it("never adds success labels to confirmed or remote messages", () => { expect( deliveryFeedback({ delivery: "seen", createdAt: 100 }, 999999), diff --git a/src/features/messages/delivery.ts b/src/features/messages/delivery.ts index 33e0c4f481..cf85e6745c 100644 --- a/src/features/messages/delivery.ts +++ b/src/features/messages/delivery.ts @@ -8,7 +8,9 @@ export function deliveryFeedback( if ( !row.delivery || row.delivery === "seen" || - now < row.createdAt * 1000 + DELIVERY_GRACE_MS + // Only an unconfirmed send waits; a failed one is already known. + (row.delivery !== "failed" && + now < row.createdAt * 1000 + DELIVERY_GRACE_MS) ) return undefined; if (row.delivery === "failed") return "Couldn’t send this message.";