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

+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), {