fix(ui): mark the announcement card's own cancellations as intentional aborts (#22380)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The browser UI shows an optional announcement card. The
`useAnnouncement` hook fetches it and cancels that fetch when the tab is
hidden, when the user dismisses the card, or when the hook unmounts
> - The hook aborts with no reason. The app handles that rejection. But
a `fetch` wrapper outside the app, such as a browser extension, can drop
it. The browser then reports `AbortError: signal is aborted without
reason` as an unhandled rejection, and Sentry records an error that has
no user effect
> - #22090 adds a marked abort reason, `intentionalAbortReason()`, and a
Sentry `beforeSend` rule that drops an unhandled rejection only when its
value is that exact marked object
> - This pull request makes the announcement hook use that marked reason
for its own cancellations
> - The benefit is that hiding a tab no longer appears as a production
error, and every other `AbortError` is still reported

## Linked Issues or Issue Description

Refs #22090, which is merged. This change uses its
`intentionalAbortReason()` marker and its Sentry `beforeSend` rule. The
diff against `master` contains only the `useAnnouncement` change.

**What happened?**
A hosted browser reported one unhandled rejection: `AbortError: signal
is aborted without reason` (DOMException code 20, mechanism
`onunhandledrejection`, native trusted promise, tab visibility `hidden`
less than one second after the change). The stack is: `document`
`visibilitychange` → `useAnnouncement` `onVisibility` → `suspend` →
`fetchController.abort()`.

**Expected behavior**
An intentional cancellation of the announcement fetch does not appear in
error monitoring. A real abort failure still appears.

**Steps to reproduce**
1. Replace `window.fetch` with a wrapper that calls the real `fetch` and
attaches only `.then(() => {})` to its promise. Some extensions and
injected scripts do this.
2. Sign in, so that the announcement hook starts its fetch.
3. Hide the tab while that fetch is in flight.
4. The hook aborts the fetch. The wrapper's derived promise rejects with
no handler. The app's own chain ends in `.catch()`, so the app does not
cause the rejection.

**Paperclip version or commit**
Reported on release `651749bdb4`. `ui/src/hooks/useAnnouncement.ts` and
`ui/src/api/announcements.ts` are unchanged on `master` up to this
branch's base.

**Deployment mode**
Hosted, browser UI (Chrome-family message text).

I searched open and closed PRs for this error message and for
`useAnnouncement` abort changes. I found only #22090, which this change
reuses.

## What Changed

- `ui/src/hooks/useAnnouncement.ts`: the hide, dismiss, and unmount
aborts now use `intentionalAbortReason()`. This includes the abort of
pending dismissal writes on unmount.
- The 10-second dismissal-write timeout still aborts with no reason. A
timeout is a real failure, not a cancellation, so it stays reportable.
- `ui/src/hooks/useAnnouncement.test.tsx`: a new test checks that each
of those aborts carries the marked reason.

## Verification

- Red first: with only the new test, `cd ui && npx vitest run
src/hooks/useAnnouncement.test.tsx` failed
(`isIntentionalAbortReason(hidden.reason)` was `false`).
- Green (also again after the merge of `master` with #22090, head
`afc31cb0ea`): `cd ui && npx vitest run
src/hooks/useAnnouncement.test.tsx
src/components/AnnouncementWell.test.tsx
src/components/AnnouncementWell.onboarding.test.tsx
src/lib/sentry.test.ts src/api/client.test.ts` → 5 files, 72 tests pass.
- `cd ui && npx tsc --noEmit -p .` shows no errors in the changed files.
The 14 errors it reports are in `storybook/support/feature-map` and are
the same without this change.
- The `beforeSend` filter itself is tested in #22090 with the real
Sentry SDK.

## Risks

- Low risk. The hook's behavior does not change: the same requests are
cancelled at the same times. Only the abort reason object changes, and
no code in the hook reads that reason.
- The marked reason has the message "The operation was aborted." instead
of the browser default. No code depends on the message.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used through Claude
Code with tool use (shell, file edit, test runs).

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: paperclipbugbot <356415228+paperclipbugbot@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-11-20 02:17:43 -08:00
1 parent 201abacd6e
commit 34a553a4b6
2 files changed
+29 -4

No files matched your search

+24
View File
@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { useAnnouncement } from "./useAnnouncement";
import { announcementPreview } from "@/lib/announcement-preview";
import { announcementStoragePrefix } from "@/lib/announcement-dismissals";
import { isIntentionalAbortReason } from "@/lib/intentional-abort";
const api = vi.hoisted(() => ({ current: vi.fn(), dismiss: vi.fn() }));
vi.mock("@/api/announcements", () => ({ announcementsApi: api }));
@@ -138,6 +139,29 @@ describe("announcement lifecycle", () => {
await settle();
expect(container.textContent).toBe("after-return");
});
it("aborts with an intentional reason when the tab is hidden, a card is dismissed, or the hook unmounts", async () => {
api.current.mockReturnValue(new Promise(() => {}));
await render();
const hidden = api.current.mock.calls[0][0] as AbortSignal;
await visibility("hidden");
expect(hidden.aborted).toBe(true);
expect(isIntentionalAbortReason(hidden.reason)).toBe(true);
await visibility("visible");
const dismissed = api.current.mock.calls[1][0] as AbortSignal;
api.dismiss.mockReturnValue(new Promise(() => {}));
await act(async () => observed.dismiss(announcementPreview.id));
expect(dismissed.aborted).toBe(true);
expect(isIntentionalAbortReason(dismissed.reason)).toBe(true);
const write = api.dismiss.mock.calls[0][2] as AbortSignal;
await visibility("hidden"); await visibility("visible");
const unmounted = api.current.mock.calls[2][0] as AbortSignal;
await act(async () => root.unmount());
root = createRoot(container);
expect(isIntentionalAbortReason(unmounted.reason)).toBe(true);
expect(isIntentionalAbortReason(write.reason)).toBe(true);
});
it("keeps failed writes pending and retries on reconnect", async () => {
api.dismiss.mockRejectedValueOnce(new Error("offline"));
await render(); await settle();
+5 -4
View File
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState } from "react";
import { announcementIdSchema, type Announcement } from "@paperclipai/shared";
import { announcementsApi } from "@/api/announcements";
import { announcementStoragePrefix, readAnnouncementDismissals, saveAnnouncementDismissal } from "@/lib/announcement-dismissals";
import { intentionalAbortReason } from "@/lib/intentional-abort";
export const ANNOUNCEMENT_SETTLE_MS = 3000;
interface Options {
@@ -61,7 +62,7 @@ export function useAnnouncement(options: Options) {
function suspend() {
generation++;
clearTimeout(settleTimer);
fetchController?.abort();
fetchController?.abort(intentionalAbortReason());
fetchController = null;
setState(null);
}
@@ -112,7 +113,7 @@ export function useAnnouncement(options: Options) {
setState(null);
// Invalidate any response that started before this dismissal.
generation++;
fetchController?.abort();
fetchController?.abort(intentionalAbortReason());
try { channel?.postMessage(id); } catch { /* Storage events are the fallback. */ }
void sync(id, savedLocally);
};
@@ -126,8 +127,8 @@ export function useAnnouncement(options: Options) {
disposed = true;
generation++;
clearTimeout(settleTimer);
fetchController?.abort();
for (const controller of writes.values()) controller.abort();
fetchController?.abort(intentionalAbortReason());
for (const controller of writes.values()) controller.abort(intentionalAbortReason());
channel?.close();
document.removeEventListener("visibilitychange", onVisibility);
window.removeEventListener("online", onOnline);