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 <noreply@paperclip.ing>
This commit is contained in:
Devin FoleyandPaperclip committed 2026-12-04 17:47:17 -08:00
1 parent dfe392dada
commit 767f687c43
5 files changed
+83 -46

No files matched your search

+3
View File
@@ -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.
+5 -4
View File
@@ -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.
+70 -24
View File
@@ -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(
<IssueMonitorComposerStrip
issue={monitoredIssue("github")}
workProducts={workProducts}
hasActiveRun
onCheckNow={() => {}}
/>,
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) => (
<>
<IssueMonitorBanner issue={issue} hasActiveRun={hasActiveRun} onCheckNow={() => {}} />
<IssueMonitorComposerStrip issue={issue} hasActiveRun={hasActiveRun} onCheckNow={() => {}} />
</>
);
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) => (
<>
<IssueMonitorBanner issue={issue} workProducts={workProducts} hasActiveRun={hasActiveRun} onCheckNow={() => {}} />
<IssueMonitorComposerStrip issue={issue} workProducts={workProducts} hasActiveRun={hasActiveRun} onCheckNow={() => {}} />
</>
);
expect(findButton(activeReviewContainer, "Check status")).toBeUndefined();
const container = render(surfaces(true));
expect(container.innerHTML).toBe("");
const activeRunContainer = render(
<IssueMonitorComposerStrip
issue={monitoredIssue()}
hasActiveRun
onCheckNow={() => {}}
/>,
);
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(<IssueMonitorComposerStrip issue={issue} hasActiveRun />);
expect(container.querySelector('[role="note"]')).not.toBeNull();
expect(container.textContent).toContain(reason === "workspace_busy" ? "Waiting for workspace" : "Pool exhausted");
});
+4 -17
View File
@@ -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",
+1 -1
View File
@@ -8949,7 +8949,7 @@ export function TaskDetailSurface({ conversation, tasksTab }: { tasksTab?: TaskS
className="mb-2"
/>
) : null}
{hasVisibleMonitorSurface(issue) ? (
{hasVisibleMonitorSurface(issue, hasLiveRuns) ? (
<IssueMonitorComposerStrip
issue={issue}
hasActiveRun={hasLiveRuns}