feat: add auto-save scaffolding for periodic tool-result logging#216
Closed
sheeki03 wants to merge 5 commits intoGitHubSecurityLab:mainfrom
Closed
feat: add auto-save scaffolding for periodic tool-result logging#216sheeki03 wants to merge 5 commits intoGitHubSecurityLab:mainfrom
sheeki03 wants to merge 5 commits intoGitHubSecurityLab:mainfrom
Conversation
Adds _tool_call_counter, _auto_save_interval, _auto_save_dir, _write_auto_save, and _read_tool_log to run_main. When AUTO_SAVE_DIR and AUTO_SAVE_INTERVAL are set, tool results are periodically appended to an NDJSON log file. Disabled by default (interval=0).
Moves write_auto_save() and read_tool_log() from closures inside run_main() to module-level functions with explicit parameters. Tests now exercise the real implementation instead of duplicating the logic.
- Add encoding="utf-8" to open() in write_auto_save and read_tool_log - Catch ValueError on non-numeric AUTO_SAVE_INTERVAL with fallback to 0 - Soften docstring from "crash-safe" to "append-only"
This was referenced Apr 10, 2026
Comment on lines
+69
to
+70
| os.makedirs(auto_save_dir, exist_ok=True) | ||
| save_path = os.path.join(auto_save_dir, AUTO_SAVE_LOG_NAME) |
Collaborator
There was a problem hiding this comment.
We have utilities for generating files and directories for logging in path_utils.py.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a long-running taskflow crashes or is interrupted, all intermediate tool results are lost. There is no way to inspect what the agent found before the failure. This makes post-mortem debugging and forensic recovery difficult, especially for security audit workflows that may run for 45+ minutes.
Changes
Auto-save infrastructure (
runner.py)Adds opt-in periodic tool-result logging via two environment variables:
AUTO_SAVE_DIR: Directory where logs are written (empty = disabled)AUTO_SAVE_INTERVAL: Write every N tool calls (0 = disabled)When both are set, every Nth tool completion appends an NDJSON entry to
{AUTO_SAVE_DIR}/auto_save_tool_log.ndjsoncontaining:turn: tool call countertool: tool nameresult_preview: first 2000 chars of the resultDesign decisions:
write_auto_save()andread_tool_log()are extracted as importable, testable functions with explicit parameters. Theon_tool_end_hookclosure delegates to them.AUTO_SAVE_INTERVAL=0(default) short-circuits before the modulo check. Invalid (non-numeric) interval values are caught and fall back to 0 with a warning.encoding="utf-8"for cross-platform consistency.README documentation
Documents
AUTO_SAVE_DIRandAUTO_SAVE_INTERVALin the Session Recovery section.Tests (
test_runner.py, 7 new tests)All tests call the real
write_auto_saveandread_tool_logfunctions:OSError)[]