From 767f687c436e121be1934cbbbfe39bfcb0ef4f5b Mon Sep 17 00:00:00 2001 From: Devin Foley Date: Fri, 4 Dec 2026 17:47:17 -0800 Subject: [PATCH] fix(ui): hide monitor waiting notices during active runs A retained monitor schedule can coexist with an active task run. Showing its waiting banner then falsely says the working agent is waiting or saving work. Hide both monitor surfaces while a task run is present, and restore them when the run ends. Keep retry holds visible. Add mounted regressions for schedule timing, run transitions, PR review controls, and retry waits. All 44 focused UI tests and UI typecheck pass. The token scan reports three unchanged violations on master. Co-Authored-By: Paperclip --- doc/PRODUCT.md | 3 + doc/idle-issue-monitors.md | 9 +- ui/src/components/IssueMonitorBanner.test.tsx | 94 ++++++++++++++----- ui/src/components/IssueMonitorBanner.tsx | 21 +---- ui/src/pages/IssueDetail.tsx | 2 +- 5 files changed, 83 insertions(+), 46 deletions(-) diff --git a/doc/PRODUCT.md b/doc/PRODUCT.md index 82bb69adc23..cce1eae90b7 100644 --- a/doc/PRODUCT.md +++ b/doc/PRODUCT.md @@ -153,6 +153,9 @@ Tasks waiting between automatic checks show **Monitoring** with a blue clock. Task lists, board columns, filters, search, recent navigation and task properties use the same read-only display state. The task retains its execution lifecycle status, and the monitor banner shows when the next check is due. +While a task-linked run is queued or running, hide its monitor banner and +composer notice. Restore them after the run ends if a monitor is still scheduled. +The saved schedule remains in place while work runs. Automatic monitor checks pause when a task is blocked. A person can use Check now to request one check of a retained monitor through normal execution admission. diff --git a/doc/idle-issue-monitors.md b/doc/idle-issue-monitors.md index 7923ac5268e..485aeec678c 100644 --- a/doc/idle-issue-monitors.md +++ b/doc/idle-issue-monitors.md @@ -14,10 +14,11 @@ failed or deferred admissions retain their bounded deadlines. A monitor deadline is the earliest time for a check. An active native run or an unfinished finalization holds the check until the prior work settles. The task -banner explains the active run wait instead of promising the next scheduler tick -or showing it as overdue. Once the run clears, the banner resumes its countdown -and offers Check now. Finalization notifications restore monitor scheduling from -the saved rows; they do not bypass execution admission. +banner and composer monitor notice stay hidden while a task-linked run is queued +or running. A saved follow-up schedule does not mean the active agent is waiting. +Once the run clears, a retained monitor shows its countdown and Check now again. +Finalization notifications restore monitor scheduling from the saved rows; they +do not bypass execution admission. Both idle drains and ordinary maintenance drains pause monitor dispatch. The worker retains its pending request without repeatedly reading monitor tables. diff --git a/ui/src/components/IssueMonitorBanner.test.tsx b/ui/src/components/IssueMonitorBanner.test.tsx index 825724a797b..d9c4daec719 100644 --- a/ui/src/components/IssueMonitorBanner.test.tsx +++ b/ui/src/components/IssueMonitorBanner.test.tsx @@ -2,18 +2,27 @@ import type { ReactElement } from "react"; import { flushSync } from "react-dom"; import { createRoot, type Root } from "react-dom/client"; -import { afterEach, expect, it } from "vitest"; +import { afterEach, beforeEach, expect, it, vi } from "vitest"; import type { Issue, IssueWorkProduct } from "@paperclipai/shared"; -import { IssueMonitorBanner, IssueMonitorComposerStrip } from "./IssueMonitorBanner"; +import { + hasVisibleMonitorSurface, + IssueMonitorBanner, + IssueMonitorComposerStrip, +} from "./IssueMonitorBanner"; const mounted: Array<{ root: Root; container: HTMLDivElement }> = []; +beforeEach(() => { + vi.useFakeTimers({ now: new Date("2099-01-01T12:00:00Z") }); +}); + afterEach(() => { while (mounted.length > 0) { const entry = mounted.pop()!; flushSync(() => entry.root.unmount()); entry.container.remove(); } + vi.useRealTimers(); }); function render(element: ReactElement): HTMLDivElement { @@ -25,6 +34,11 @@ function render(element: ReactElement): HTMLDivElement { return container; } +function rerender(container: HTMLDivElement, element: ReactElement) { + const entry = mounted.find((item) => item.container === container)!; + flushSync(() => entry.root.render(element)); +} + function findButton(container: HTMLElement, label: string): HTMLButtonElement | undefined { return Array.from(container.querySelectorAll("button")).find( (button) => button.textContent?.trim() === label, @@ -147,7 +161,7 @@ it("omits the reply wake copy and centers Check now for a scheduled monitor", () expect(bannerButton!.parentElement?.parentElement).toBe(banner); }); -it("renders the relocated pullRequestReview and active-run strip hints inside the centered row", () => { +it("renders the pull request review hint inside the centered row", () => { const workProducts = [pendingPullRequestWorkProduct()]; const reviewContainer = render( @@ -169,29 +183,61 @@ it("renders the relocated pullRequestReview and active-run strip hints inside th expect(reviewRow?.classList.contains("sm:items-center")).toBe(true); expect(reviewLeftColumn?.parentElement).toBe(reviewRow); expect(reviewLeftColumn?.contains(checkStatusButton!)).toBe(false); +}); - const activeReviewContainer = render( - {}} - />, +it.each([ + { state: "scheduled", offset: 3 * 60_000 }, + { state: "due now", offset: 0 }, + { state: "overdue", offset: -2 * 60_000 }, +])("hides both $state monitor surfaces during a run and restores them when it ends", ({ offset }) => { + const issue = monitoredIssue(); + issue.executionState!.monitor!.nextCheckAt = new Date(Date.now() + offset).toISOString(); + const surfaces = (hasActiveRun: boolean) => ( + <> + {}} /> + {}} /> + ); - expect(activeReviewContainer.textContent).toContain( - "Review on GitHub while the current run finishes saving its work.", + const container = render(surfaces(false)); + const idleText = container.textContent; + expect(hasVisibleMonitorSurface(issue, false)).toBe(true); + expect(container.querySelectorAll('[role="note"]')).toHaveLength(2); + expect(container.querySelectorAll("button")).toHaveLength(2); + + rerender(container, surfaces(true)); + expect(hasVisibleMonitorSurface(issue, true)).toBe(false); + expect(container.innerHTML).toBe(""); + + rerender(container, surfaces(false)); + expect(container.textContent).toBe(idleText); + expect(container.querySelectorAll('[role="note"]')).toHaveLength(2); + expect(container.querySelectorAll("button")).toHaveLength(2); +}); + +it("restores the PR review links and Check status after the active run ends", () => { + const issue = monitoredIssue("github"); + const workProducts = [pendingPullRequestWorkProduct()]; + const surfaces = (hasActiveRun: boolean) => ( + <> + {}} /> + {}} /> + ); - expect(findButton(activeReviewContainer, "Check status")).toBeUndefined(); + const container = render(surfaces(true)); + expect(container.innerHTML).toBe(""); - const activeRunContainer = render( - {}} - />, - ); - expect(activeRunContainer.textContent).toContain( - "You can keep sending instructions while the agent waits.", - ); - expect(findCheckNowButton(activeRunContainer)).toBeUndefined(); + rerender(container, surfaces(false)); + expect(container.textContent).toContain("Pull request review requested"); + expect(container.querySelectorAll('a[href="https://github.com/paperclipai/paperclip/pull/23763"]')).toHaveLength(2); + expect(Array.from(container.querySelectorAll("button")).map((button) => button.textContent)).toEqual([ + "Check status", "Check status", + ]); +}); + +it.each(["workspace_busy", "ai_connection_pool_wait"])("keeps the %s retry wait visible when a run is present", (reason) => { + const issue = waitingIssue(reason); + expect(hasVisibleMonitorSurface(issue, true)).toBe(true); + const container = render(); + expect(container.querySelector('[role="note"]')).not.toBeNull(); + expect(container.textContent).toContain(reason === "workspace_busy" ? "Waiting for workspace" : "Pool exhausted"); }); diff --git a/ui/src/components/IssueMonitorBanner.tsx b/ui/src/components/IssueMonitorBanner.tsx index 7eca5d53b46..7e2d279abde 100644 --- a/ui/src/components/IssueMonitorBanner.tsx +++ b/ui/src/components/IssueMonitorBanner.tsx @@ -47,9 +47,10 @@ export function isWaitingMonitorState(state: MonitorDisplayState): boolean { return WAITING_STATES.includes(state); } -export function hasVisibleMonitorSurface(issue: Issue): boolean { +export function hasVisibleMonitorSurface(issue: Issue, hasActiveRun = false): boolean { const derived = deriveMonitorState(issue); - return isWaitingMonitorState(derived.state) && derived.nextCheckAt !== null; + return isWaitingMonitorState(derived.state) && derived.nextCheckAt !== null + && !(derived.source === "monitor" && hasActiveRun); } export interface MonitorSurfaceCopy { @@ -88,6 +89,7 @@ export function buildMonitorSurfaceCopy( hasActiveRun = false, ): MonitorSurfaceCopy | null { if (!isWaitingMonitorState(derived.state) || !derived.nextCheckAt) return null; + if (derived.source === "monitor" && hasActiveRun) return null; if (derived.source === "monitor" && areAutomaticMonitorChecksPaused({ status: issueStatus })) { const canCheckNow = canCheckIssueMonitorNow({ status: issueStatus }, derived.serviceName); @@ -131,21 +133,6 @@ export function buildMonitorSurfaceCopy( const eta = formatMonitorEta(derived.nextCheckAt, now); // "in 2h 12m" | "due now" | "overdue by 18m" const absolute = formatMonitorAbsolute(derived.nextCheckAt, {}, now); // local time, e.g. "Today, 4:08 PM" const awaitingPullRequestReview = derived.source === "monitor" && derived.serviceName?.toLowerCase() === "github" && pendingPullRequestReviews > 0; - if (derived.source === "monitor" && hasActiveRun) { - const hint = "The check can start after the current run finishes saving its work."; - return { - bannerTitle: "Monitor waits for current run", - stripTitle: "Monitor waits for current run", - bannerMeta: [hint, `Scheduled for ${absolute} (your time)`], - stripMeta: [hint, `Scheduled for ${absolute}`], - stripHint: awaitingPullRequestReview - ? "Review on GitHub while the current run finishes saving its work." - : "You can keep sending instructions while the agent waits.", - tone: "info", - checkUnavailable: true, - pullRequestReview: awaitingPullRequestReview, - }; - } if (awaitingPullRequestReview) { return { bannerTitle: "Pull request review requested", diff --git a/ui/src/pages/IssueDetail.tsx b/ui/src/pages/IssueDetail.tsx index a2e67aa9b0d..4fe1481e7a2 100644 --- a/ui/src/pages/IssueDetail.tsx +++ b/ui/src/pages/IssueDetail.tsx @@ -8949,7 +8949,7 @@ export function TaskDetailSurface({ conversation, tasksTab }: { tasksTab?: TaskS className="mb-2" /> ) : null} - {hasVisibleMonitorSurface(issue) ? ( + {hasVisibleMonitorSurface(issue, hasLiveRuns) ? (