mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-07 02:51:50 +00:00
fix(api_server): emit run.failed when run_conversation returns failed=True
When run_conversation encounters a non-retryable client error (401, 400, etc.), it returns a dict with failed=True instead of raising. The gateway's _run_and_close only branched on exceptions, so it always emitted run.completed even for failed runs — clients could not distinguish success from failure. Inspect the result dict before emitting: if failed=True, emit run.failed with the error message; otherwise emit run.completed as before. The existing except Exception path is unchanged for genuine programming errors. Fixes #15561
This commit is contained in:
parent
b2b479b40e
commit
297eaa3533
1 changed files with 33 additions and 15 deletions
|
|
@ -2578,21 +2578,39 @@ class APIServerAdapter(BasePlatformAdapter):
|
||||||
return r, u
|
return r, u
|
||||||
|
|
||||||
result, usage = await asyncio.get_running_loop().run_in_executor(None, _run_sync)
|
result, usage = await asyncio.get_running_loop().run_in_executor(None, _run_sync)
|
||||||
final_response = result.get("final_response", "") if isinstance(result, dict) else ""
|
# Check for structured failure (non-retryable client errors like
|
||||||
q.put_nowait({
|
# 401/400 return failed=True instead of raising, so the except
|
||||||
"event": "run.completed",
|
# block below never fires — issue #15561).
|
||||||
"run_id": run_id,
|
if isinstance(result, dict) and result.get("failed"):
|
||||||
"timestamp": time.time(),
|
error_msg = result.get("error") or "agent run failed"
|
||||||
"output": final_response,
|
q.put_nowait({
|
||||||
"usage": usage,
|
"event": "run.failed",
|
||||||
})
|
"run_id": run_id,
|
||||||
self._set_run_status(
|
"timestamp": time.time(),
|
||||||
run_id,
|
"error": error_msg,
|
||||||
"completed",
|
})
|
||||||
output=final_response,
|
self._set_run_status(
|
||||||
usage=usage,
|
run_id,
|
||||||
last_event="run.completed",
|
"failed",
|
||||||
)
|
error=error_msg,
|
||||||
|
last_event="run.failed",
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
final_response = result.get("final_response", "") if isinstance(result, dict) else ""
|
||||||
|
q.put_nowait({
|
||||||
|
"event": "run.completed",
|
||||||
|
"run_id": run_id,
|
||||||
|
"timestamp": time.time(),
|
||||||
|
"output": final_response,
|
||||||
|
"usage": usage,
|
||||||
|
})
|
||||||
|
self._set_run_status(
|
||||||
|
run_id,
|
||||||
|
"completed",
|
||||||
|
output=final_response,
|
||||||
|
usage=usage,
|
||||||
|
last_event="run.completed",
|
||||||
|
)
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
self._set_run_status(
|
self._set_run_status(
|
||||||
run_id,
|
run_id,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue