fix(agent): preserve final_response on failure returns - #56176
Merged
Conversation
teknium1
force-pushed
the
hermes/hermes-c48666d6
branch
from
July 1, 2026 08:30
2675fd4 to
025eafc
Compare
teknium1
force-pushed
the
hermes/hermes-c48666d6
branch
2 times, most recently
from
July 1, 2026 08:53
86cf697 to
c80f024
Compare
AIAgent.run_conversation() promises a dict with final_response, but 16 terminal-failure branches returned dicts that either omitted the key or set it to None. Callers that index result['final_response'] directly (run_agent.py chat() + the __main__ printer) turn a real provider/context failure into an opaque KeyError instead of surfacing the actionable error. Every offending branch already carried usable 'error' text, so this mirrors that text into final_response for all 16 sites (8 that omitted the key, 8 that returned None). Adds an AST regression test that fails if any run_conversation() dict return omits final_response or sets it to a literal None, and tightens the invalid-response test to assert final_response == error.
teknium1
force-pushed
the
hermes/hermes-c48666d6
branch
from
July 1, 2026 08:54
c80f024 to
b4f71a9
Compare
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
AIAgent.run_conversation()now returns an actionablefinal_responseon every terminal-failure branch, so callers that indexresult["final_response"]directly surface the real error instead of crashing with aKeyError.Root cause:
run_conversation()promises a dict withfinal_response, but 16 failure branches violated that contract — 8 omitted the key entirely, 8 set it to literalNone.run_agent.py'schat()(result["final_response"]) and the__main__printer index it directly, turning a real provider/context failure into an opaqueKeyError: 'final_response'. The original report: a MeshBoard worker exited withhermes -z: agent failed: 'final_response'after upstream stream drops + 400/502s.Changes
agent/conversation_loop.py: all 16 offending terminal-failure returns now setfinal_responseto the same actionable text already present inerror(invalid-response retry exhaustion, stream-drop/truncation, 413 payload + context-compression exhaustion, max_tokens-over-cap, incomplete REASONING_SCRATCHPAD, Codex incomplete, invalid tool call). Every branch already carried usableerrortext — this mirrors it intofinal_response.tests/run_agent/test_run_agent.py: AST regression test that fails if anyrun_conversation()dict return omitsfinal_responseor sets it to a literalNone; tightens the invalid-response test to assertfinal_response == error.scripts/release.py: AUTHOR_MAP entry for the contributor.Validation
run_conversation()failure-branch contractfinal_response, 8 returnNoneKeyError: 'final_response'tests/run_agent/test_run_agent.pytests/run_agent/test_413_compression.pyfinal_response == error, non-None strSalvage of #39345 by @OmarB97 — his fix approach and AST regression test reapplied to current
main(line numbers had drifted ~4 months); authorship preserved.Infographic