Skip to content

fix: remove synthetic error message injection, fix session resume after repeated failures#2303

Merged
teknium1 merged 2 commits intomainfrom
hermes/hermes-31d7db3b
Mar 21, 2026
Merged

fix: remove synthetic error message injection, fix session resume after repeated failures#2303
teknium1 merged 2 commits intomainfrom
hermes/hermes-31d7db3b

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

Summary

Two fixes to the error handler in the main agent loop (run_agent.py).

1. Remove synthetic error message injection

The if not pending_handled block injected [System error during processing: ...] messages into conversation history when API calls or response parsing failed. Problems:

  • Could inject with role: user, misattributing system errors to the user
  • Could create consecutive same-role messages (role alternation violation)
  • Polluted history with synthetic messages that burned tokens on retries
  • On repeated failures, spammed N synthetic messages into history

The error is already printed to the user via print(f"❌ {error_msg}"). The retry loop continues without needing a fake message.

The role: tool error-result path for pending tool_calls is preserved — that one is necessary because the API requires matching tool results.

2. Append error response at iteration limit

When all retries fail and the agent hits the iteration limit, the error final_response was returned but never appended to messages. On session resume, this caused consecutive user messages ([user, user]). Now the error response is appended as role: assistant.

Live tested

  • Parse failure → retry → clean recovery (no synthetic msgs)
  • Repeated failures → iteration limit → no history pollution
  • Session resume after failure → proper [user, assistant, user, assistant] alternation
  • Tool call errors → still get role: tool error results (preserved)

Closes #2263, #2253, #2236, #2231 (all reported the same role violation).

All 5671 tests pass.

Test and others added 2 commits March 20, 2026 20:50
…er repeated failures

Two changes to the error handler in the agent loop:

1. Remove the 'if not pending_handled' block that injected fake
   [System error during processing: ...] messages into conversation
   history.  These polluted history, burned tokens on retries, and
   could violate role alternation by injecting as role=user.
   The tool_calls error-result path (role=tool) is preserved.

2. Append the error final_response as an assistant message when
   hitting the iteration limit, so session resume doesn't produce
   consecutive user messages.
@teknium1 teknium1 merged commit 58b52df into main Mar 21, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant