Skip to content

Session history not saved when agent errors or cancellation occurs #222

@nhicks00

Description

@nhicks00

Problem

When an API error, timeout, rate-limit rejection, or agent task cancellation occurs during agent execution, auto_save_session_if_enabled() is skipped and the user loses conversation history. The only recovery option is a manual /dump_context (if the user knows to do it in time) or retrying and hoping the next round autosaves.

Root Cause

In cli_runner.py, the autosave call lives at line 801 — after the try/except block for agent execution. However, several code paths exit the current loop iteration via continue or break before reaching it:

Path Location Result
result is None (cancellation / swallowed API error) line 742–763 continue save skipped
Ctrl+D (EOFError exit) line 566–581 break save skipped
/exit or /quit command line 583–602 break save skipped
Wiggum loop KeyboardInterrupt line 873–876 break save skipped
Wiggum loop Exception line 877–882 break save skipped

The primary user-visible case: API timeouts/errors are swallowed inside run_agent_task() via except*, making the coroutine return None, which triggers the continue path and skips the save.

Fix

Add auto_save_session_if_enabled() calls before each continue/break in the missed paths. All changes are isolated to cli_runner.py.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions