Aider-AI/aider · error · ValueError

summarizer unexpectedly failed for all models

Error message

summarizer unexpectedly failed for all models

What it means

Raised by ChatSummary.summarize_all in aider/history.py when every model in self.models fails to produce a summary. Each model's simple_send_with_retries is tried inside try/except; exceptions are printed per-model ('Summarization failed for model ...') and a None return is silently skipped. Only after the whole loop exhausts does it raise ValueError('summarizer unexpectedly failed for all models'). The root cause is almost never the summarizer itself — it is invalid API keys, exhausted context, rate limits, or unreachable endpoints on every configured summarization model.

Source

Thrown at aider/history.py:123

            content += msg["content"]
            if not content.endswith("\n"):
                content += "\n"

        summarize_messages = [
            dict(role="system", content=prompts.summarize),
            dict(role="user", content=content),
        ]

        for model in self.models:
            try:
                summary = model.simple_send_with_retries(summarize_messages)
                if summary is not None:
                    summary = prompts.summary_prefix + summary
                    return [dict(role="user", content=summary)]
            except Exception as e:
                print(f"Summarization failed for model {model.name}: {str(e)}")

        raise ValueError("summarizer unexpectedly failed for all models")


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("filename", help="Markdown file to parse")
    args = parser.parse_args()

    model_names = ["gpt-3.5-turbo", "gpt-4"]  # Add more model names as needed
    model_list = [models.Model(name) for name in model_names]
    summarizer = ChatSummary(model_list)

    with open(args.filename, "r") as f:
        text = f.read()

    summary = summarizer.summarize_chat_history_markdown(text)
    dump(summary)

View on GitHub (pinned to 5dc9490bb3)

Solutions

  1. Check console output: the per-model 'Summarization failed for model <name>: <error>' lines printed just before the raise carry the real per-model exception (auth error, rate limit, context length) — fix that underlying error first.
  2. Verify the API key and connectivity for every model passed to ChatSummary (they are constructed via models.Model(name), so the corresponding env key, e.g. OPENAI_API_KEY, must be valid).
  3. If the transcript exceeds a summarizer model's context, configure a larger-context summarization model (e.g. swap gpt-3.5-turbo for a bigger model) in the ChatSummary models list.
  4. As a workaround for very long sessions, start a fresh session or manually trim the chat history so summarization is not needed.

Example fix

// before
model_names = ["gpt-3.5-turbo", "gpt-4"]
summarizer = ChatSummary([models.Model(n) for n in model_names])
summary = summarizer.summarize(messages)  # raises if all models fail

// after
try:
    summary = summarizer.summarize(messages)
except ValueError as e:
    if "summarizer unexpectedly failed" in str(e):
        # keep raw (truncated) history instead of aborting the session
        summary = messages[-self.max_tokens:]
    else:
        raise
Defensive patterns

Strategy: fallback

Validate before calling

from aider.history import ChatSummary

def summarize_safe(summarizer, messages, keep_last=50):
    try:
        return summarizer.summarize(messages)
    except ValueError as e:
        if "summarizer unexpectedly failed" in str(e):
            # fallback: keep the most recent messages instead of a summary
            return messages[-keep_last:]
        raise

Try / catch

try:
    summary = summarizer.summarize(messages)
except ValueError as e:
    if "summarizer unexpectedly failed" in str(e):
        messages = messages[-50:]  # degrade gracefully, keep session alive
    else:
        raise
else:
    messages = summary

Prevention

When it happens

Trigger: Calling ChatSummary.summarize()/summarize_real() on a chat history whose token total exceeds max_tokens (default 1024), which routes to summarize_all. It fails when: (1) every model's API key is missing/invalid, (2) simple_send_with_retries returns None for all models (non-200 responses), (3) the concatenated USER/ASSISTANT transcript exceeds the summarization model's context window, or (4) network/proxy errors make all providers unreachable.

Common situations: Long aider coding sessions where chat history grows past max_tokens trigger summarization; if the user's main model works but the summarizer models (weak/legacy ones like gpt-3.5-turbo) have quota or deprecation issues, all retries fail. Also common when OPENAI_API_KEY was unset mid-session or an API balance hit zero.

Related errors


AI-assisted analysis of Aider-AI/aider@5dc9490bb3 (2026-08-15). Data as JSON: /api/errors/7ee17d91635ad3ab. Report an issue: GitHub.