mpfaffenberger / mpfaffenberger/code_puppy
Sub-agent session history persisted via pickle: silent corruption fallback, version fragility, and avoidable pickle.load risk
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 814
- Forks
- 278
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 76
Description
Files:
code_puppy/tools/agent_tools.py(~lines 120-185):_save_session_history/_load_session_historycode_puppy/tools/subagent_invocation.pyuses the same.pklsession files
Severity: Medium (robustness; low-grade security footnote)
Sub-agent session history is persisted with pickle:
with open(tmp_pkl, "wb") as f:
pickle.dump(message_history, f)
...
with open(pkl_path, "rb") as f:
return pickle.load(f)
Problems:
- Errors pass silently:
_load_session_historycatches bareExceptionand returns[], so a corrupted/incompatible session silently restarts the sub-agent with no memory and no warning (refusing-to-guess violation). At minimumemit_warningthe load failure. - Version fragility: pydantic-ai message classes change between releases; pickled histories break on upgrade with no migration path. JSON serialization via
pydantic_core.to_jsonable_python/ModelMessagesTypeAdapter(which pydantic-ai provides specifically for message history persistence) is stable and human-inspectable. - pickle.load on a shared-location file (
~/.code_puppy/...) executes arbitrary code if anything else writes those files. Low practical risk (local user dir) but trivially avoided by using the JSON adapters. - The
.tmprename pattern here is fine, but the companion.txtmetadata uses a read-modify-write without locking - concurrent parallel sub-agents on the same session can interleave.
Suggested fix: switch to ModelMessagesTypeAdapter.dump_json() / validate_json() for session history, log load failures, and keep a one-release fallback that reads legacy .pkl files.
Filed by Zen Reviewer B (code-puppy-60635a)
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.
Research direction
Start with _save_session_history and _load_session_history in code_puppy/tools/agent_tools.py, then inspect how code_puppy/tools/subagent_invocation.py uses the .pkl and .txt session files. Use the pydantic-ai message adapters named in the issue, preserve a legacy .pkl fallback, and ensure load failures emit a warning; done means session history remains recoverable across versions without pickle as the primary format.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100