Leo AI destructive error handling

# Leo AI destructive error handling

**Summary**

Leo fails to handle errors gracefully, destroying partial answers and restarting work. It mis-reports conversation length as the issue.

**Error message**

Conversation length exceeded. Please shorten your request or start a new conversation.

**Observed behavior**

- During generation, the rendered answer is removed and replaced with “thinking” status. This repeats multiple times within a single turn.

- The system re-performs web searches already completed in that turn, repeating all prior work.

- Pressing Stop mid-render does not predictably preserve the partial answer.

- Page reload reproduces the same error message without recovery.

- No feedback entry point exists in the Leo UI

**Evidence this is not a context window limit**

- A subsequent turn requesting “output your last answer” succeeds and returns content. Context grows monotonically per turn, so a longer context succeeding after a shorter one failed contradicts the stated cause.

- The failure occurs mid-turn during generation, not at submission time when context size would be evaluated.

- The system re-executes tool calls (web searches) rather than truncating history, indicating an error-handling path rather than token exhaustion.

**Reproduction steps**

1. Go to brave://leo-ai/

2. Submit a research-heavy prompt requiring multiple web lookups (e.g., provide a professional consultant homepage URL and ask which services are performed).

3. Observe the answer begin rendering normally.

4. Watch as rendered text is cleared and replaced with “thinking”; searches re-execute. This may happen 1-4 times.

5. On completion or timeout, the error dialog appears and no answer is retained.

6. Reload the page: same error persists.

7. Send a follow-up turn asking for the previous answer: a response is returned, confirming the context was never actually over-limit.

**Expected behavior**

On error, do not discard rendered output or silently re-run completed searches. Retain and display the partial answer. May include a notice such as: “An error occurred. The answer may be incomplete.”

**Environment**

Brave Browser desktop, current stable. Leo AI chat interface.

**Additional steps**

1. New turn: “Last turn, you rendered an answer multiple times and deleted it each time. After deletion, it seemed you re-performed steps, such as search. Please output the response.”

2. A complete, thorough answer was output, but the turn was still running. Thinking reported: “Executing code in the sandbox to help with your query”. (Conversation did not include any request for code generation; it was non-technical)

3. Click Stop

4. Answer remained displayed

Would you be willing to share the conversation in which this occurred with us so our devs can get more context on the issue?