fix(ui): surface model retry status (NAN-34) (#5504)

This commit is contained in:
chengyongru authored and GitHub committed 2026-09-07 15:12:39 +08:00
1 parent 0b1fa0c3e4
commit b581a496a6
52 files changed
+1697 -55

No files matched your search

@@ -140,6 +140,27 @@ function installReducedMotion() {
}
describe("AgentActivityCluster", () => {
it("shows model retries in the existing live activity header", () => {
render(
<AgentActivityCluster
messages={[]}
isTurnStreaming
hasBodyBelow={false}
retryStatus={{
state: "waiting",
attempt: 1,
max_attempts: 4,
error_kind: "connection",
next_retry_at: Date.now() / 1000 + 5,
}}
/>,
);
expect(
screen.getByText("Connection failed · retrying in 5s · attempt 1/4"),
).toBeInTheDocument();
});
it("keeps intermediate assistant output as normal Markdown inside live activity", async () => {
await act(async () => {
await preloadMarkdownText();
@@ -0,0 +1,48 @@
import { describe, expect, it } from "vitest";
import i18n from "@/i18n";
import { resolveModelRequestFailureCopy } from "@/lib/model-request-failure";
describe("model request failure copy", () => {
it("maps every sanitized provider error category to a specific cause", () => {
const titles = ["billing", "connection", "timeout", "rate_limit", "server", "unknown"].map(
(errorKind) => resolveModelRequestFailureCopy({ errorKind }, i18n.t).title,
);
expect(titles).toEqual([
"Model provider quota is unavailable",
"Could not connect to the model provider",
"Model provider request timed out",
"Model provider rate limit reached",
"Model provider service error",
"Model provider request failed",
]);
});
it("reports the final attempt and a concrete recovery action", () => {
expect(resolveModelRequestFailureCopy(
{ errorKind: "connection", attempts: 4 },
i18n.t,
).body).toBe(
"The request still failed on attempt 4, so retries stopped. "
+ "Check the provider configuration or service status, then try again.",
);
});
it("provides billing recovery without claiming a retry occurred", () => {
expect(resolveModelRequestFailureCopy(
{ errorKind: "billing" },
i18n.t,
).body).toBe(
"Add credit or check billing for the provider account, then try again.",
);
});
it("does not claim retries stopped without an attempt count", () => {
const body = resolveModelRequestFailureCopy({ errorKind: "unknown" }, i18n.t).body;
expect(body).toBe(
"Check the provider configuration or service status, then try again.",
);
});
});
+8
View File
@@ -3,6 +3,14 @@ import fixtures from "../../../packages/client-events/fixtures.json";
import { acceptsCompactionPhase, decodeNotification } from "../../../packages/client-events/notifications";
describe("shared notification contract", () => {
it("rejects malformed retry counters and relative delays", () => {
const retry = { event: "retry_status", chat_id: "chat", state: "waiting",
attempt: 1, max_attempts: 4, error_kind: "connection", retry_after_s: 2 };
for (const invalid of [
{ attempt: 0 }, { attempt: 1.5 }, { max_attempts: 0 }, { max_attempts: NaN },
{ retry_after_s: -1 }, { retry_after_s: Infinity }, { state: "unknown" },
]) expect(decodeNotification({ ...retry, ...invalid })).toBeNull();
});
it.each(fixtures)("accepts the Python wire fixture %#", (event) => {
expect(decodeNotification(event)).toEqual(event);
expect(decodeNotification({ ...event, turn_id: "turn" })).toMatchObject(event);
+51
View File
@@ -5,6 +5,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import { preloadMarkdownText } from "@/components/MarkdownText";
import { ThreadCameraController } from "@/components/thread/thread-camera";
import { ThreadShell } from "@/components/thread/ThreadShell";
import i18n from "@/i18n";
import { CLI_APPS_CHANGED_EVENT } from "@/lib/cli-app-events";
import type { CanonicalRunSnapshot, StreamError } from "@/lib/nanobot-client";
import { ClientProvider } from "@/providers/ClientProvider";
@@ -3793,6 +3794,56 @@ describe("ThreadShell", () => {
});
});
it("keeps a terminal model failure visible until the next user action", async () => {
const client = makeClient();
await act(async () => {
await i18n.changeLanguage("zh-CN");
});
render(
wrap(
client,
<ThreadShell
session={session("chat-model-failure")}
title="Chat model failure"
onToggleSidebar={() => {}}
onGoHome={() => {}}
onNewChat={() => {}}
/>,
),
);
await act(async () => {});
act(() => {
client._emitChat("chat-model-failure", {
event: "turn_end",
chat_id: "chat-model-failure",
turn_id: "turn-model-failure",
outcome: "failed",
failure_kind: "model",
failure_error_kind: "connection",
failure_attempts: 4,
failure_message: "Unlocalized server failure",
});
});
const banner = await screen.findByRole("alert");
expect(banner).toHaveTextContent("无法连接模型提供商");
expect(banner).toHaveTextContent(
"模型提供商请求在第 4 次尝试后仍然失败,已停止重试。请检查提供商配置或服务状态后重试。",
);
expect(banner).not.toHaveTextContent("Unlocalized server failure");
fireEvent.change(screen.getByLabelText("消息输入框"), {
target: { value: "try again" },
});
fireEvent.click(screen.getByRole("button", { name: "发送消息" }));
await waitFor(() => {
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
});
});
it("moves a correlated delivery error from the banner into the failed message tooltip", async () => {
const client = makeClient();
+69
View File
@@ -125,6 +125,9 @@ function fakeClient() {
const v = runStartedAtByChatId.get(chatId);
return v === undefined ? null : v;
},
getRunTurnId() {
return null;
},
getGoalState(chatId: string) {
return goalStateByChatId.get(chatId);
},
@@ -3227,6 +3230,72 @@ describe("useNanobotStream", () => {
expect(result.current.isStreaming).toBe(false);
});
it("clears retry status and exposes a terminal model failure at turn end", () => {
const dateNow = vi.spyOn(Date, "now").mockReturnValue(120_000);
const fake = fakeClient();
const { result } = renderHook(() => useNanobotStream("chat-retry", EMPTY_MESSAGES), {
wrapper: wrap(fake.client),
});
act(() => {
fake.emit("chat-retry", {
event: "retry_status",
chat_id: "chat-retry",
turn_id: "turn-1",
state: "waiting",
attempt: 2,
max_attempts: 4,
error_kind: "connection",
retry_after_s: 3.5,
});
});
expect(result.current.retryStatus).toEqual({
state: "waiting",
attempt: 2,
max_attempts: 4,
error_kind: "connection",
next_retry_at: 123.5,
turn_id: "turn-1",
});
expect(result.current.isStreaming).toBe(true);
act(() => {
fake.emit("chat-retry", {
event: "retry_status",
chat_id: "chat-retry",
turn_id: "turn-1",
state: "cleared",
attempt: 2,
max_attempts: 4,
error_kind: "connection",
});
});
expect(result.current.retryStatus).toBeNull();
act(() => {
fake.emit("chat-retry", {
event: "turn_end",
chat_id: "chat-retry",
turn_id: "turn-1",
outcome: "failed",
failure_kind: "model",
failure_error_kind: "connection",
failure_attempts: 4,
failure_message: "Unlocalized server failure",
});
});
expect(result.current.retryStatus).toBeNull();
expect(result.current.isStreaming).toBe(false);
expect(result.current.streamError).toEqual({
kind: "model_request_failed",
chatId: "chat-retry",
turnId: "turn-1",
errorKind: "connection",
attempts: 4,
});
dateNow.mockRestore();
});
it("clears runStartedAt on turn_end even without idle", () => {
const fake = fakeClient();
const { result } = renderHook(() => useNanobotStream("chat-g", EMPTY_MESSAGES), {