Surface failed-turn reason: host.py recovers it from thread_history, dispatch prints it

Real bad-model turn: relay returns 404, codex retries sampling
5 times, turn fails, but app-server's turn/completed event
carries status=failed with NO error and NO text, so worker
never saw any fallbackable signal. The 404 actually lives in
codex's thread_history_1.sqlite (thread_turns.error_json).
host.py Server.run_turn now best-effort recovers that message
(read-only query by thread_id+turn_id, any failure -> None,
never breaks the turn itself), and dispatch CLI prints the
error field (run CLI already printed the full result). Worker
_attempt_error prefers the error field when text is empty, so
a double failure keeps the real reasons, not just status codes.
Tests: host TurnErrorFromHistoryTest (recovery + missing/corrupt
DB -> None), full host + cloud suites pass.
This commit is contained in:
host committed 2026-10-26 06:13:27 +08:00
1 parent 6a857e06bd
commit c114178463
3 files changed
+105 -3

No files matched your search

+8
View File
@@ -905,6 +905,14 @@ class Worker:
parsed = None
if isinstance(parsed, dict) and parsed.get("text"):
return str(parsed["text"])
# dispatch 输出现在带 error 字段(host.py 从 thread_history
# 库里捞回的失败原因,如 404);text 为空时优先用它,
# 否则两次失败的拼接里只剩 host_status=404 这种代号。
if isinstance(parsed, dict) and parsed.get("error"):
err = parsed["error"]
if isinstance(err, dict):
err = err.get("message") or str(err)
return str(err)[:1000]
# host.py 崩溃时 stdout 常为空、真正的报错在 stderr(例如
# “缺少 --repo”、Read-only file system);只用 stdout 时
# 最终错误会被写成通用的 host execution failed,排障无从