fix: guard all print() against OSError with _SafeWriter#963
Merged
Conversation
When hermes-agent runs as a systemd service, Docker container, or headless daemon, the stdout pipe can become unavailable (idle timeout, buffer exhaustion, socket reset). Any print() call then raises OSError: [Errno 5] Input/output error, crashing run_conversation() and causing cron jobs to fail. Rather than wrapping individual print() calls (68 in run_conversation alone), this adds a transparent _SafeWriter wrapper installed once at the start of run_conversation(). It delegates all writes to the real stdout and silently catches OSError. Zero overhead on the happy path, comprehensive coverage of all print calls including future ones. Fixes #845 Co-authored-by: J0hnLawMississippi <J0hnLawMississippi@users.noreply.github.com>
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 hermes-agent runs as a systemd service or headless daemon, stdout can become unavailable (idle timeout, buffer exhaustion, socket reset). Any
print()raisesOSError: [Errno 5], crashingrun_conversation()— especially via double-fault when the except handler also tries to print (#845).PR #858 attempted to fix this by wrapping 7 individual print() calls in try/except, but
run_conversation()has 68 print() calls and the PR left adjacent prints in the same blocks unguarded.Fix
A transparent
_SafeWriterwrapper installed once at the start ofrun_conversation(). It delegates all writes to the real stdout and silently catches OSError.isinstanceguard prevents double-wrapping across multiplerun_conversation()callsFixes #845
Co-authored-by: J0hnLawMississippi J0hnLawMississippi@users.noreply.github.com