fix(core): wrap print calls with try-except OSError#1358
Closed
mr-emmett-one wants to merge 1 commit into
Closed
Conversation
Prevents agent crashes in headless environments (Docker, systemd) where stdout might be unavailable. Fixes NousResearch#845.
Contributor
|
The approach is right but there's a bug: the Fix: keep those two lines before the try block. The try-except should only wrap the print() calls, not the variable assignments. |
teknium1
added a commit
that referenced
this pull request
Mar 17, 2026
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)
angelburgosrosado
pushed a commit
to angelburgosrosado/hermes-agent
that referenced
this pull request
Apr 27, 2026
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 NousResearch#845 Closes NousResearch#1358 (superseded — PR was 323 commits stale with a bug)
02356abc
pushed a commit
to 02356abc/hermes-agent
that referenced
this pull request
May 14, 2026
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 NousResearch#845 Closes NousResearch#1358 (superseded — PR was 323 commits stale with a bug)
olympus-terminal
pushed a commit
to olympus-terminal/hermes-agent
that referenced
this pull request
May 16, 2026
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 NousResearch#845 Closes NousResearch#1358 (superseded — PR was 323 commits stale with a bug)
gweeteve
pushed a commit
to gweeteve/hermes-agent
that referenced
this pull request
Jun 2, 2026
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 NousResearch#845 Closes NousResearch#1358 (superseded — PR was 323 commits stale with a bug)
Egavasyug
pushed a commit
to Egavasyug/hermes-agent
that referenced
this pull request
Jun 10, 2026
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 NousResearch#845 Closes NousResearch#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.
What does this PR do?
This PR wraps multiple
print()calls within therun_conversationfunction inrun_agent.pywithtry...except OSErrorblocks.It prevents the agent from crashing with a
Broken PipeorInput/output errorwhen running in headless environments (like Docker containers, systemd services, or remote CI/CD) where a terminal (stdout) might be unavailable or disconnected.Why is this necessary?
Currently, the agent's core loop can fail entirely if it attempts to output progress messages to a non-existent terminal. This change ensures that the agent's logic remains robust and continues to execute even if visual output fails.
Related Issue
Fixes #845