Skip to content

Commit a9e5f4b

Browse files
committed
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.
1 parent 0fca927 commit a9e5f4b

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/cli/tui/hooks/use-agent-loop.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ export function AgentLoopProvider({
133133
}
134134
} catch (error) {
135135
if (isAbortError(error)) return;
136-
throw error;
136+
// Display API/model errors as assistant messages instead of crashing
137+
const errorMessage = error instanceof Error ? error.message : String(error);
138+
enqueueMessage({
139+
role: "assistant",
140+
content: [{ type: "text", text: `Error: ${errorMessage}\n\nYou can try again.` }],
141+
});
137142
} finally {
138143
agent.setRequestedSkillName(null);
139144
flushPendingMessages();

0 commit comments

Comments
 (0)