Skip to content

fix: ignore BrokenPipeError from console prints in gateway mode - #911

Closed
Krlosimc wants to merge 1 commit into
NousResearch:mainfrom
Krlosimc:fix/telegram-broken-pipe
Closed

fix: ignore BrokenPipeError from console prints in gateway mode#911
Krlosimc wants to merge 1 commit into
NousResearch:mainfrom
Krlosimc:fix/telegram-broken-pipe

Conversation

@Krlosimc

Copy link
Copy Markdown

Summary

  • prevent gateway/Telegram conversations from failing when internal console prints raise BrokenPipeError
  • this surfaced to users as the generic 'unexpected error' response

Root cause

In gateway mode, run_agent.py can still emit debug/progress print() calls even with quiet_mode=True. If stdout/stderr is detached or its pipe closes, those prints raise BrokenPipeError, abort the turn, and gateway/run.py returns the generic error message to Telegram.

Fix

  • wrap module-level print() in run_agent.py
  • delegate to builtins.print()
  • swallow BrokenPipeError so best-effort console output cannot abort the conversation

Validation

  • ./venv/bin/python -m py_compile run_agent.py
  • restarted the local gateway and verified Telegram reconnects cleanly
  • reproduced from logs that the previous failure path came from BrokenPipeError in run_agent.py

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the report and patch here. Current main already landed a broader _SafeWriter-based fix for broken stdout during run_conversation, so I pulled the remaining init-time edge case you surfaced into PR #1271 instead of merging this stale branch directly. That follow-up fixes the Honcho init-time print path on current main and keeps the existing _SafeWriter approach as the single mechanism. Credit for surfacing the remaining gap.

@teknium1 teknium1 closed this Mar 14, 2026
bbasketballer75 added a commit to bbasketballer75/hermes-agent that referenced this pull request Jul 31, 2026
User messages that quote prior tool output (e.g. 'hermes verified that...'
or 'hermes reported that...') were being passed through to the Honcho
deriver, which then extracted those quoted phrases as Explicit Observations
on the 'hermes' observer peer. Each chat turn added a new
'hermes said/reported/verified/...' observation, feeding the
self-trust loop.

The new _strip_agent_self_quotes function runs over user_content
inside sync_turn() (after sanitize_context), before the content is
written to Honcho. It matches 'hermes <verb> ...' phrases and
replaces each match with a NUL character placeholder so the user's
surrounding prose is preserved but the substring cannot be parsed as
a meaningful sentence by the deriver's extraction prompt.

Patterns stripped:
  - 'hermes <said|reported|confirmed|identified|provided|outlined|
     created|saved|noted|asked|required|wants|received|believes|
     described|added|changed|verifies|verified|wanted|completed|
     commits|requires|has|is|was|continues|sent|started> ... [ending in
     . ! ? \n or end-of-string]'
  - '6631182039 has a long-term memory note stating that ...'
  - 'hermes verifies/describes ...'

Verified with 16 test cases (10 pollution patterns stripped, 0 false
positives on non-pollution text). Module loads cleanly, syntax checks
clean. Live install: 60s after gateway restart with this patch
loaded, zero new hermes-observer documents were generated.

Refs: PR NousResearch#66754 (peer-card sanitizer), PR NousResearch#66810 (self-narration
demote), Honcho NousResearch#911 (observation-cleanup API), Honcho NousResearch#913 (asyncio
loop frozen - separate from this fix).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants