fix(webui): hide recovery notice while resumed tasks run

Render recovery decisions only for awaiting_user and failed states so a reload cannot resurrect a resuming banner. Preserve the runtime recovery state and normal running controls.

Refs NAN-260
This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-16 18:25:40 +08:00
1 parent 8f6a5594fb
commit 559107172a
3 files changed
+109 -68

No files matched your search

+27 -36
View File
@@ -2,7 +2,7 @@ import {
ResumeIcon, ResumeIcon,
} from "@/components/icons/product-icons"; } from "@/components/icons/product-icons";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { AlertTriangle, LoaderCircle, X } from "lucide-react"; import { AlertTriangle, X } from "lucide-react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
@@ -27,22 +27,20 @@ export function RecoveryNotice({ state, onContinue, onDismiss }: RecoveryNoticeP
setHiddenRecoveryId(null); setHiddenRecoveryId(null);
} }
}, [state.recovery_id, state.status]); }, [state.recovery_id, state.status]);
if (state.status === "recovered" || hiddenRecoveryId === state.recovery_id) return null;
const waiting = state.status === "awaiting_user" || state.status === "failed"; const waiting = state.status === "awaiting_user" || state.status === "failed";
// Recovery metadata stays resuming until the continued turn commits, but
// execution progress belongs to the normal running-turn UI, even after reload.
if (!waiting || hiddenRecoveryId === state.recovery_id) return null;
const contextUnavailable = state.can_continue === false; const contextUnavailable = state.can_continue === false;
const title = state.status === "failed" const title = state.status === "failed"
? t("recovery.failed", { defaultValue: "Task recovery failed" }) ? t("recovery.failed", { defaultValue: "Task recovery failed" })
: waiting : t("recovery.interrupted", { defaultValue: "Task interrupted" });
? t("recovery.interrupted", { defaultValue: "Task interrupted" })
: t("recovery.resuming", { defaultValue: "Restoring interrupted task…" });
const detail = state.status === "failed" || contextUnavailable const detail = state.status === "failed" || contextUnavailable
? t("recovery.failedHelp", { ? t("recovery.failedHelp", {
defaultValue: "The saved task could not be restored safely. Review it before continuing.", defaultValue: "The saved task could not be restored safely. Review it before continuing.",
}) })
: waiting : t("recovery.review", { defaultValue: "Review the task before continuing. Tools will not be replayed automatically." });
? t("recovery.review", { defaultValue: "Review the task before continuing. Tools will not be replayed automatically." })
: t("recovery.safeResume", { defaultValue: "Continuing from saved conversation context." });
const run = (action: "continue" | "dismiss") => { const run = (action: "continue" | "dismiss") => {
setPending(action); setPending(action);
setError(null); setError(null);
@@ -59,17 +57,12 @@ export function RecoveryNotice({ state, onContinue, onDismiss }: RecoveryNoticeP
return ( return (
<div <div
role={waiting ? "alert" : "status"} role="alert"
aria-live={waiting ? "assertive" : "polite"} aria-live="assertive"
aria-busy={state.status === "resuming"}
data-recovery-status={state.status} data-recovery-status={state.status}
className="mx-auto mb-2 flex w-full max-w-[49.5rem] items-center gap-3 rounded-control border border-border/70 bg-muted/35 px-3 py-2 text-sm transition-[background-color,border-color,opacity,transform] duration-200 ease-out motion-reduce:transition-none animate-in fade-in-0 slide-in-from-bottom-1 duration-200 motion-reduce:animate-none" className="mx-auto mb-2 flex w-full max-w-[49.5rem] items-center gap-3 rounded-control border border-border/70 bg-muted/35 px-3 py-2 text-sm transition-[background-color,border-color,opacity,transform] duration-200 ease-out motion-reduce:transition-none animate-in fade-in-0 slide-in-from-bottom-1 duration-200 motion-reduce:animate-none"
> >
{waiting ? ( <AlertTriangle className="h-4 w-4 shrink-0 text-amber-600 dark:text-amber-400" aria-hidden />
<AlertTriangle className="h-4 w-4 shrink-0 text-amber-600 dark:text-amber-400" aria-hidden />
) : (
<LoaderCircle className="h-4 w-4 shrink-0 animate-spin text-primary motion-reduce:animate-none" aria-hidden />
)}
<div className="min-w-0 flex-1"> <div className="min-w-0 flex-1">
<p className="font-medium"> <p className="font-medium">
{title} {title}
@@ -81,31 +74,29 @@ export function RecoveryNotice({ state, onContinue, onDismiss }: RecoveryNoticeP
{error ?? detail} {error ?? detail}
</p> </p>
</div> </div>
{waiting ? ( <div className="flex shrink-0 items-center gap-1.5">
<div className="flex shrink-0 items-center gap-1.5"> <Button
type="button"
size="sm"
variant="outline"
disabled={pending !== null}
onClick={() => run("dismiss")}
>
<X className="mr-1 h-3.5 w-3.5" aria-hidden />
{t("recovery.dismiss", { defaultValue: "Dismiss" })}
</Button>
{!contextUnavailable ? (
<Button <Button
type="button" type="button"
size="sm" size="sm"
variant="outline"
disabled={pending !== null} disabled={pending !== null}
onClick={() => run("dismiss")} onClick={() => run("continue")}
> >
<X className="mr-1 h-3.5 w-3.5" aria-hidden /> <ResumeIcon className="mr-1 h-3.5 w-3.5" aria-hidden />
{t("recovery.dismiss", { defaultValue: "Dismiss" })} {t("recovery.continue", { defaultValue: "Continue" })}
</Button> </Button>
{!contextUnavailable ? ( ) : null}
<Button </div>
type="button"
size="sm"
disabled={pending !== null}
onClick={() => run("continue")}
>
<ResumeIcon className="mr-1 h-3.5 w-3.5" aria-hidden />
{t("recovery.continue", { defaultValue: "Continue" })}
</Button>
) : null}
</div>
) : null}
</div> </div>
); );
} }
+57 -32
View File
@@ -27,18 +27,40 @@ describe("RecoveryNotice", () => {
expect(onContinue).toHaveBeenCalledOnce(); expect(onContinue).toHaveBeenCalledOnce();
}); });
it("uses the shared status surface and motion treatment", () => { it("keeps an active continuation hidden after remounting", async () => {
render( const onContinue = vi.fn().mockResolvedValue(undefined);
const onDismiss = vi.fn().mockResolvedValue(undefined);
const { unmount } = render(
<RecoveryNotice state={INTERRUPTED} onContinue={onContinue} onDismiss={onDismiss} />,
);
fireEvent.click(screen.getByRole("button", { name: "Continue" }));
await waitFor(() => expect(screen.queryByRole("alert")).not.toBeInTheDocument());
unmount();
const { container } = render(
<RecoveryNotice <RecoveryNotice
state={{ status: "resuming", recovery_id: "recovery-1" }} state={{ status: "resuming", recovery_id: "recovery-1" }}
onContinue={onContinue}
onDismiss={onDismiss}
/>,
);
expect(container).toBeEmptyDOMElement();
});
it("uses the shared alert surface and motion treatment", () => {
render(
<RecoveryNotice
state={INTERRUPTED}
onContinue={vi.fn().mockResolvedValue(undefined)} onContinue={vi.fn().mockResolvedValue(undefined)}
onDismiss={vi.fn().mockResolvedValue(undefined)} onDismiss={vi.fn().mockResolvedValue(undefined)}
/>, />,
); );
const notice = screen.getByRole("status"); const notice = screen.getByRole("alert");
expect(notice).toHaveAttribute("data-recovery-status", "resuming"); expect(notice).toHaveAttribute("data-recovery-status", "awaiting_user");
expect(notice).toHaveAttribute("aria-live", "polite"); expect(notice).toHaveAttribute("aria-live", "assertive");
expect(notice).toHaveClass( expect(notice).toHaveClass(
"max-w-[49.5rem]", "max-w-[49.5rem]",
"rounded-control", "rounded-control",
@@ -68,36 +90,39 @@ describe("RecoveryNotice", () => {
}); });
}); });
it("shows the decision surface again when a continuation is interrupted", async () => { it.each(["awaiting_user", "failed"] as const)(
const onContinue = vi.fn().mockResolvedValue(undefined); "shows the decision surface again when a continuation returns to %s",
const { rerender } = render( async (status) => {
<RecoveryNotice const onContinue = vi.fn().mockResolvedValue(undefined);
state={INTERRUPTED} const { rerender } = render(
onContinue={onContinue} <RecoveryNotice
onDismiss={vi.fn().mockResolvedValue(undefined)} state={INTERRUPTED}
/>, onContinue={onContinue}
); onDismiss={vi.fn().mockResolvedValue(undefined)}
/>,
);
fireEvent.click(screen.getByRole("button", { name: "Continue" })); fireEvent.click(screen.getByRole("button", { name: "Continue" }));
await waitFor(() => expect(screen.queryByRole("alert")).not.toBeInTheDocument()); await waitFor(() => expect(screen.queryByRole("alert")).not.toBeInTheDocument());
rerender( rerender(
<RecoveryNotice <RecoveryNotice
state={{ status: "resuming", recovery_id: "recovery-1" }} state={{ status: "resuming", recovery_id: "recovery-1" }}
onContinue={onContinue} onContinue={onContinue}
onDismiss={vi.fn().mockResolvedValue(undefined)} onDismiss={vi.fn().mockResolvedValue(undefined)}
/>, />,
); );
rerender( rerender(
<RecoveryNotice <RecoveryNotice
state={{ ...INTERRUPTED, reason: "loop_guard" }} state={{ ...INTERRUPTED, status, reason: "loop_guard" }}
onContinue={onContinue} onContinue={onContinue}
onDismiss={vi.fn().mockResolvedValue(undefined)} onDismiss={vi.fn().mockResolvedValue(undefined)}
/>, />,
); );
await waitFor(() => expect(screen.getByRole("alert")).toBeInTheDocument()); await waitFor(() => expect(screen.getByRole("alert")).toBeInTheDocument());
}); },
);
it("does not offer Continue when saved conversation context is unavailable", () => { it("does not offer Continue when saved conversation context is unavailable", () => {
render( render(
+25
View File
@@ -5478,6 +5478,31 @@ describe("ThreadShell", () => {
expect(screen.getByRole("option", { name: /Other project/i })).toBeInTheDocument(); expect(screen.getByRole("option", { name: /Other project/i })).toBeInTheDocument();
}); });
it("keeps normal running controls when attaching to a resumed task", async () => {
const client = makeClient();
render(wrap(
client,
<ThreadShell
session={session("resuming-chat")}
title="Resuming chat"
onToggleSidebar={() => {}}
/>,
));
await screen.findByLabelText("Message input");
act(() => {
client._emitChat("resuming-chat", {
event: "attached",
chat_id: "resuming-chat",
recovery_state: { recovery_id: "recovery-1", status: "resuming" },
});
});
expect(screen.queryByText("Restoring interrupted task…")).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Stop response" }));
expect(client.sendMessage).toHaveBeenCalledWith("resuming-chat", "/stop");
});
it("allows a new turn after a completed recovery state", async () => { it("allows a new turn after a completed recovery state", async () => {
const client = makeClient(); const client = makeClient();
render(wrap( render(wrap(