Skip to content

fix(cli): handle closed stdout ValueError in safe print paths#3843

Merged
teknium1 merged 1 commit intomainfrom
hermes/hermes-b2abefdf
Mar 30, 2026
Merged

fix(cli): handle closed stdout ValueError in safe print paths#3843
teknium1 merged 1 commit intomainfrom
hermes/hermes-b2abefdf

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

When stdout is closed (piped to a dead process, broken terminal), Python raises ValueError('I/O operation on closed file'), not OSError. _safe_print and the API error printer only caught OSError, letting the ValueError propagate and crash the agent.

Bug verified: Created an AIAgent with a print function that raises ValueError — confirmed it crashes through _safe_print on current main, handled gracefully after the fix.

Fixes #3534. Salvaged from PR #3760 by @apexscaleai with authorship preserved.

When stdout is closed (piped to a dead process, broken terminal),
Python raises ValueError('I/O operation on closed file'), not OSError.
_safe_print and the API error printer only caught OSError, letting the
ValueError propagate and crash the agent.

Salvaged from PR #3760 by @apexscaleai. Fixes #3534.
@teknium1 teknium1 merged commit 2a0e8b0 into main Mar 30, 2026
4 of 5 checks passed
itsXactlY pushed a commit to itsXactlY/hermes-agent that referenced this pull request Mar 30, 2026
…search#3843)

When stdout is closed (piped to a dead process, broken terminal),
Python raises ValueError('I/O operation on closed file'), not OSError.
_safe_print and the API error printer only caught OSError, letting the
ValueError propagate and crash the agent.

Salvaged from PR NousResearch#3760 by @apexscaleai. Fixes NousResearch#3534.

Co-authored-by: apexscaleai <apexscaleai@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants