From 679908c9f5bfbe64699b7580093a0b3c9e570bcd Mon Sep 17 00:00:00 2001 From: Mike Olson Date: Sat, 21 Nov 2026 15:40:33 -0500 Subject: [PATCH] fix(web): Silence background thread announcements for monitor wakes and stopped runs Keep the screen-reader background thread announcer quiet when a monitor holds a background wake completion or when the latest run had a stop requested, matching ThreadNotificationCoordinator and agent awareness. --- .../components/BackgroundThreadAnnouncer.tsx | 10 +--- .../backgroundThreadAnnouncement.test.ts | 58 +++++++++++++++++++ .../backgroundThreadAnnouncement.ts | 29 ++++++++++ 3 files changed, 89 insertions(+), 8 deletions(-) diff --git a/apps/web/src/components/BackgroundThreadAnnouncer.tsx b/apps/web/src/components/BackgroundThreadAnnouncer.tsx index 9d66c150e4bf8..273fffbcdfd69 100644 --- a/apps/web/src/components/BackgroundThreadAnnouncer.tsx +++ b/apps/web/src/components/BackgroundThreadAnnouncer.tsx @@ -1,11 +1,9 @@ import { scopeThreadRef, scopedThreadKey } from "@t3tools/client-runtime/environment"; import { effectiveSnoozed } from "@t3tools/client-runtime/state/thread-settled"; import { isShownUnderParent } from "@t3tools/client-runtime/state/threads"; -import { isDelegatedAppThread } from "@t3tools/contracts"; import type { AnyRouter } from "@tanstack/react-router"; import type { AtomRegistry } from "effect/reactivity"; -import { backgroundWorkHoldsCompletion } from "@t3tools/shared/orchestrationV2PendingBackgroundWork"; import { useComposerDraftStore } from "../composerDraftStore"; import { createLiveRegion } from "../hooks/useLiveRegion"; import { liveShellEnvironmentIdsAtom } from "../state/shell"; @@ -16,6 +14,7 @@ import { type BackgroundThreadSnapshot, nextBackgroundThreadAnnouncement, resolveBackgroundThreadRequest, + resolveBackgroundThreadRunStatus, } from "./backgroundThreadAnnouncement"; const backgroundThreadLiveRegion = createLiveRegion(); @@ -59,12 +58,7 @@ export function startBackgroundThreadAnnouncements( title: thread.title, ...resolveBackgroundThreadRequest(thread), runId: thread.latestRun?.runId ?? null, - runStatus: - thread.latestRun?.status === "completed" && - (isDelegatedAppThread(thread.source) || - backgroundWorkHoldsCompletion(thread.pendingBackgroundTasks)) - ? null - : (thread.latestRun?.status ?? null), + runStatus: resolveBackgroundThreadRunStatus(thread), activeRunId: thread.runtime?.activeRunId ?? null, snoozed: effectiveSnoozed(thread, { now }), }); diff --git a/apps/web/src/components/backgroundThreadAnnouncement.test.ts b/apps/web/src/components/backgroundThreadAnnouncement.test.ts index 3e235407715fe..d0b7d113102e3 100644 --- a/apps/web/src/components/backgroundThreadAnnouncement.test.ts +++ b/apps/web/src/components/backgroundThreadAnnouncement.test.ts @@ -7,6 +7,7 @@ import { type BackgroundThreadSnapshot, nextBackgroundThreadAnnouncement, resolveBackgroundThreadRequest, + resolveBackgroundThreadRunStatus, } from "./backgroundThreadAnnouncement"; const firstRun = RunId.make("run-1"); @@ -266,3 +267,60 @@ describe("resolveBackgroundThreadRequest", () => { ).toEqual(["Needs approval: Fix login redirect"]); }); }); + +describe("resolveBackgroundThreadRunStatus", () => { + const rootLineage = { + rootThreadId: ThreadId.make("root"), + parentThreadId: null, + relationshipToParent: null, + } as const; + const completedRun = { runId: firstRun, status: "completed" as const }; + const base = { + latestRun: completedRun, + pendingBackgroundTasks: [], + source: { + lineage: rootLineage, + pendingBackgroundTasks: [], + }, + }; + + it("suppresses completed status while a monitor holds a wake or when stop was requested", () => { + const monitorTask = { taskId: "mon-1", kind: "monitor" as const, description: "tail -f" }; + expect(resolveBackgroundThreadRunStatus(base)).toBe("completed"); + expect( + resolveBackgroundThreadRunStatus({ + ...base, + source: { ...base.source, latestRunStopRequested: true }, + }), + ).toBeNull(); + expect( + resolveBackgroundThreadRunStatus({ + ...base, + pendingBackgroundTasks: [monitorTask], + source: { + ...base.source, + latestRunBackgroundWake: true, + pendingBackgroundTasks: [monitorTask], + }, + }), + ).toBeNull(); + expect( + resolveBackgroundThreadRunStatus({ + ...base, + pendingBackgroundTasks: [monitorTask], + source: { + ...base.source, + latestRunBackgroundWake: false, + pendingBackgroundTasks: [monitorTask], + }, + }), + ).toBe("completed"); + expect( + resolveBackgroundThreadRunStatus({ + ...base, + latestRun: { status: "failed" as const }, + source: { ...base.source, latestRunStopRequested: true }, + }), + ).toBe("failed"); + }); +}); diff --git a/apps/web/src/components/backgroundThreadAnnouncement.ts b/apps/web/src/components/backgroundThreadAnnouncement.ts index d618b56f8a5a4..955aa9d25bbe2 100644 --- a/apps/web/src/components/backgroundThreadAnnouncement.ts +++ b/apps/web/src/components/backgroundThreadAnnouncement.ts @@ -3,6 +3,10 @@ import { type OrchestrationV2RunStatus, type RunId, } from "@t3tools/contracts"; +import { + backgroundWorkHoldsCompletion, + monitorHoldsWakeCompletion, +} from "@t3tools/shared/orchestrationV2PendingBackgroundWork"; import { msg } from "gt-react"; @@ -51,6 +55,31 @@ export function resolveBackgroundThreadRequest( return { request: null, requestId: null }; } +export function resolveBackgroundThreadRunStatus(thread: { + readonly latestRun: { readonly status: OrchestrationV2RunStatus } | null; + readonly pendingBackgroundTasks: SidebarThreadSummary["pendingBackgroundTasks"]; + readonly source: Pick< + SidebarThreadSummary["source"], + | "lineage" + | "delegatedFrom" + | "latestRunBackgroundWake" + | "latestRunStopRequested" + | "pendingBackgroundTasks" + >; +}): OrchestrationV2RunStatus | null { + const status = thread.latestRun?.status ?? null; + if ( + status === "completed" && + (isDelegatedAppThread(thread.source) || + thread.source.latestRunStopRequested === true || + backgroundWorkHoldsCompletion(thread.pendingBackgroundTasks) || + monitorHoldsWakeCompletion(thread.source)) + ) { + return null; + } + return status; +} + interface BackgroundThreadMemoryEntry { readonly request: BackgroundThreadSnapshot["request"]; readonly requestId: string | null;