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

+57 -32
View File
@@ -27,18 +27,40 @@ describe("RecoveryNotice", () => {
expect(onContinue).toHaveBeenCalledOnce();
});
it("uses the shared status surface and motion treatment", () => {
render(
it("keeps an active continuation hidden after remounting", async () => {
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
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)}
onDismiss={vi.fn().mockResolvedValue(undefined)}
/>,
);
const notice = screen.getByRole("status");
expect(notice).toHaveAttribute("data-recovery-status", "resuming");
expect(notice).toHaveAttribute("aria-live", "polite");
const notice = screen.getByRole("alert");
expect(notice).toHaveAttribute("data-recovery-status", "awaiting_user");
expect(notice).toHaveAttribute("aria-live", "assertive");
expect(notice).toHaveClass(
"max-w-[49.5rem]",
"rounded-control",
@@ -68,36 +90,39 @@ describe("RecoveryNotice", () => {
});
});
it("shows the decision surface again when a continuation is interrupted", async () => {
const onContinue = vi.fn().mockResolvedValue(undefined);
const { rerender } = render(
<RecoveryNotice
state={INTERRUPTED}
onContinue={onContinue}
onDismiss={vi.fn().mockResolvedValue(undefined)}
/>,
);
it.each(["awaiting_user", "failed"] as const)(
"shows the decision surface again when a continuation returns to %s",
async (status) => {
const onContinue = vi.fn().mockResolvedValue(undefined);
const { rerender } = render(
<RecoveryNotice
state={INTERRUPTED}
onContinue={onContinue}
onDismiss={vi.fn().mockResolvedValue(undefined)}
/>,
);
fireEvent.click(screen.getByRole("button", { name: "Continue" }));
await waitFor(() => expect(screen.queryByRole("alert")).not.toBeInTheDocument());
fireEvent.click(screen.getByRole("button", { name: "Continue" }));
await waitFor(() => expect(screen.queryByRole("alert")).not.toBeInTheDocument());
rerender(
<RecoveryNotice
state={{ status: "resuming", recovery_id: "recovery-1" }}
onContinue={onContinue}
onDismiss={vi.fn().mockResolvedValue(undefined)}
/>,
);
rerender(
<RecoveryNotice
state={{ ...INTERRUPTED, reason: "loop_guard" }}
onContinue={onContinue}
onDismiss={vi.fn().mockResolvedValue(undefined)}
/>,
);
rerender(
<RecoveryNotice
state={{ status: "resuming", recovery_id: "recovery-1" }}
onContinue={onContinue}
onDismiss={vi.fn().mockResolvedValue(undefined)}
/>,
);
rerender(
<RecoveryNotice
state={{ ...INTERRUPTED, status, reason: "loop_guard" }}
onContinue={onContinue}
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", () => {
render(
+25
View File
@@ -5478,6 +5478,31 @@ describe("ThreadShell", () => {
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 () => {
const client = makeClient();
render(wrap(