From a9e5f4b17c84cce29e2cd76c563ceb429b52826e Mon Sep 17 00:00:00 2001 From: c001estb0y <422867803@qq.com> Date: Fri, 8 May 2026 17:40:10 +0800 Subject: [PATCH] fix(cli): gracefully handle model API errors instead of crashing When the model provider returns 503/429/5xx, the error was re-thrown from the agent loop hook, causing the Ink process to crash and exit. Now the error is caught and displayed as an assistant message so the user can retry without restarting the session. --- src/cli/tui/hooks/use-agent-loop.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cli/tui/hooks/use-agent-loop.ts b/src/cli/tui/hooks/use-agent-loop.ts index 28dcddd..3f602bd 100644 --- a/src/cli/tui/hooks/use-agent-loop.ts +++ b/src/cli/tui/hooks/use-agent-loop.ts @@ -133,7 +133,12 @@ export function AgentLoopProvider({ } } catch (error) { if (isAbortError(error)) return; - throw error; + // Display API/model errors as assistant messages instead of crashing + const errorMessage = error instanceof Error ? error.message : String(error); + enqueueMessage({ + role: "assistant", + content: [{ type: "text", text: `Error: ${errorMessage}\n\nYou can try again.` }], + }); } finally { agent.setRequestedSkillName(null); flushPendingMessages();