This commit is contained in:
2026-10-10 22:44:51 +02:00
parent 8df5cf7a45
commit 0821adebfa
5 changed files with 12016 additions and 9578 deletions
+30 -2
View File
@@ -163,6 +163,31 @@ class ChatClient:
headers.update(extra)
return headers
@staticmethod
def summarize_errors(errors, shown=2, width=320):
"""One-line summary of a failed retry round.
Missing-CLI entries are expected on machines without those CLIs,
so actionable failures lead and the missing-CLI tail never takes
the only display slot (CLI candidates run last, and the muse
candidate is always appended even when its binary is absent).
"""
if not errors:
return "no details"
actionable = [entry for entry in errors if "CLI not found" not in entry]
pool = actionable or errors
unique = []
for entry in pool:
if entry not in unique:
unique.append(entry)
text = "; ".join(unique[:shown])
if len(unique) > shown:
text += "; +%d more" % (len(unique) - shown)
skipped = len(errors) - len(pool)
if skipped:
text += " (%d missing CLI skipped)" % skipped
return text[:width]
def complete(self, messages, tools=None, stream_sink=None, ephemeral=False, deadline=None):
payload = {"model": self.config.model, "messages": messages}
if tools:
@@ -183,8 +208,11 @@ class ChatClient:
pause = Consts.RETRY_BACKOFF[min(round_no, len(Consts.RETRY_BACKOFF) - 1)]
round_no += 1
if give_up is not None and time.time() + pause > give_up:
raise BackendError("all backends failed after %d rounds (%s)" % (round_no, "; ".join(errors[-6:])))
print(Render.paint("all %d backends failed (round %d), retrying in %ds: %s" % (len(cands), round_no, pause, (errors[-1] if errors else "")[:160]), Ansi.DIM), file=sys.stderr)
raise BackendError("all backends failed after %d rounds (%s)" % (round_no, self.summarize_errors(errors, shown=6, width=900)))
providers = len(set((cand["provider"], cand["chat_url"]) for cand in cands))
if sys.stderr.isatty():
sys.stderr.write("\n")
print(Render.paint("all %d candidate%s across %d backend%s failed (round %d), retrying in %ds: %s" % (len(cands), "" if len(cands) == 1 else "s", providers, "" if providers == 1 else "s", round_no, pause, self.summarize_errors(errors)), Ansi.DIM), file=sys.stderr)
if round_no == 1 and not Opencode.opencode_binary():
engine = Sandbox.container_engine()
if engine and Sandbox.box_state(engine) == "missing":