Skip to content

Commit b859968

Browse files
fix(web): a pending approval is announced once, not once per queued message (pingdotgg#25866)
1 parent 5c9a01b commit b859968

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

‎apps/web/src/components/ThreadNotificationCoordinator.badge.browser.test.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,19 @@ it.each(["hasPendingApprovals", "hasPendingUserInput"] as const)(
243243
);
244244

245245
it.each(["hasPendingApprovals", "hasPendingUserInput"] as const)(
246-
"notifies again when a new %s request replaces the pending one in the same run",
246+
"notifies once per %s request, not again as queued runs start behind it",
247247
async (flag) => {
248248
await using app = setup();
249249
app.start();
250-
state.shells.set("one", shell({ [flag]: true, pendingRequestId: "request-1" }));
251-
state.shells.set("one", shell({ [flag]: true, pendingRequestId: "request-2" }));
250+
const waiting = (turnId: string, pendingRequestId: string) =>
251+
shell({
252+
[flag]: true,
253+
pendingRequestId,
254+
latestTurn: { turnId, state: "running", completedAt: null },
255+
});
256+
state.shells.set("one", waiting("turn-1", "request-1"));
257+
state.shells.set("one", waiting("turn-2", "request-1"));
258+
state.shells.set("one", waiting("turn-2", "request-2"));
252259
const title = flag === "hasPendingApprovals" ? "Approval needed" : "Input needed";
253260
expect(TestNotification.sent.map(({ title }) => title)).toEqual([title, title]);
254261
},

‎apps/web/src/components/ThreadNotificationCoordinator.logic.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export type ThreadNotificationKind = "input" | "completion";
22

33
export interface ThreadNotificationObservation {
4-
/** Run, status and request key while the thread needs attention, otherwise null. */
4+
/** Status and request key, or status and run without a request, while the thread needs attention. */
55
readonly attention: string | null;
66
/** The pending request's id, when it has one; null whenever attention is. */
77
readonly requestId: string | null;

‎apps/web/src/components/ThreadNotificationCoordinator.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,13 @@ export function startThreadNotifications(
261261
status === "failed" ||
262262
status === "limited";
263263
const requestId = needsAttention ? resolveBackgroundThreadRequest(thread).requestId : null;
264-
const attention = needsAttention
265-
? `${thread.latestRun?.runId ?? ""}:${status}:${requestId ?? ""}`
266-
: null;
264+
// Queued messages become the latest run while a request stays pending, so a request
265+
// with an id is keyed by that id alone and announces once.
266+
const attention = !needsAttention
267+
? null
268+
: requestId !== null
269+
? `${status}:${requestId}`
270+
: `${thread.latestRun?.runId ?? ""}:${status}`;
267271
const completed = status === "ready" && thread.latestRun?.status === "completed";
268272
const settled = completed && !monitorHoldsWakeCompletion(rawThread);
269273
const parsedCompletedAt = Date.parse(thread.latestRun?.completedAt ?? "");

0 commit comments

Comments
 (0)