fix(moa): skip aggregator synthesis when all references fail

When every MoA reference model returns a failure (HTTP error, timeout,
etc.) or is skipped by the recursion guard, the one-shot aggregator
synthesis call is now skipped entirely. Previously it would try to
synthesise a wall of failure sentinels, which could block for the full
provider timeout (observed ~6 min on SenseNova) before returning a
non-retryable error that left the session hanging.

The early return carries the sanitized unavailability notice (never raw
provider error text, per the failed-reference containment) so the main
agent loop can still act in single-model mode.

Salvaged from #56975, reworked atop the _is_failed_reference helpers.
This commit is contained in:
liuhao1024 2026-07-23 12:17:53 -07:00 • committed by Teknium
parent d3fc27bbf8
commit f0ed77b627
2 changed files with 82 additions and 0 deletions

View file

@ -963,6 +963,26 @@ def aggregate_moa_context(
degraded = _degraded_notice(failed_labels, degraded_reference_policy)
if degraded:
joined = f"{joined}\n\n{degraded}" if joined else degraded
# Skip the aggregator call when every reference failed or was skipped —
# synthesising over zero real advice wastes tokens and can block for the
# full provider timeout (observed: ~6 min on SenseNova) before returning
# a non-retryable error that leaves the session hanging. The early return
# carries only the sanitized unavailability notice (never raw provider
# error text) so the main agent loop can still act in single-model mode.
if reference_outputs and not successful_outputs:
logger.warning(
"MoA: all %d reference(s) failed — skipping aggregator synthesis",
len(reference_outputs),
)
notice = degraded or "[Reference models unavailable]"
return (
"[Mixture of Agents context — all reference models failed. "
"Proceeding without aggregated guidance.]\n"
f"References: {', '.join(_slot_label(slot) for slot in reference_models)}\n\n"
f"{notice}"
)
synth_prompt = (
"You are the aggregator in a Mixture of Agents process. Synthesize the "
"reference responses into concise, actionable guidance for the main "