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.
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 thetry/exceptblock for agent execution. However, several code paths exit the current loop iteration viacontinueorbreakbefore reaching it:result is None(cancellation / swallowed API error)continuebreak/exitor/quitcommandbreakKeyboardInterruptbreakExceptionbreakThe primary user-visible case: API timeouts/errors are swallowed inside
run_agent_task()viaexcept*, making the coroutine returnNone, which triggers thecontinuepath and skips the save.Fix
Add
auto_save_session_if_enabled()calls before eachcontinue/breakin the missed paths. All changes are isolated tocli_runner.py.