mpfaffenberger / mpfaffenberger/code_puppy
Session history not saved when agent errors or cancellation occurs
@nhicks00 is already working on this.
Since Mar 3, 2026.
- Dominant language
- Python
- Stars
- 814
- Forks
- 278
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 76
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.