fix(core): guard print() calls in run_conversation() against OSError#1668
Merged
fix(core): guard print() calls in run_conversation() against OSError#1668
Conversation
In headless environments (systemd, Docker, nohup) stdout can become unavailable mid-session. Raw print() raises OSError which crashes cron jobs — agent finishes work but delivery never happens because the error handler's own print() also raises OSError. Fix: - Add _safe_print() static method that wraps print() with try/except OSError — silently drops output when stdout is broken - Make _vprint() use _safe_print() — protects all calls through the verbose print path - Convert raw print() calls in run_conversation() hot path to use _safe_print(): starting conversation, interrupt, budget exhausted, preflight compression, context cache, conversation completed - Error handler print (the cascading crash point) gets explicit try/except with logger.error() fallback so diagnostics aren't lost Fixes #845 Closes #1358 (superseded — PR was 323 commits stale with a bug)
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.
Summary
Reimplementation of the fix from PR #1358 by @mr-emmett-one (323 commits stale, had a variable deletion bug). Addresses issue #845.
Problem
In headless environments (systemd services, Docker, nohup), stdout can become unavailable mid-session. Raw
print()raisesOSError: [Errno 5] Input/output error. The critical failure cascade:print()in quiet_mode display raisesOSErrorexcept Exceptionhandler catches itprint(f"❌ {error_msg}")also raisesOSErrorrun_conversation()entirelyFix
_safe_print()— new static method that wrapsprint()withtry/except OSError. Silently drops output when stdout is broken._vprint()now uses_safe_print()— protects all calls through the verbose print path automatically.print()calls inrun_conversation()hot path converted to_safe_print(): starting conversation, interrupt, budget exhausted, preflight compression, context cache, conversation completed.try/exceptwithlogger.error()fallback so diagnostic messages aren't silently lost.Fixes #845