{"record":{"id":"7ee17d91635ad3ab","repo":"Aider-AI/aider","slug":"summarizer-unexpectedly-failed-for-all-models","errorCode":null,"errorMessage":"summarizer unexpectedly failed for all models","messagePattern":"summarizer unexpectedly failed for all models","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"aider/history.py","lineNumber":123,"sourceCode":"            content += msg[\"content\"]\n            if not content.endswith(\"\\n\"):\n                content += \"\\n\"\n\n        summarize_messages = [\n            dict(role=\"system\", content=prompts.summarize),\n            dict(role=\"user\", content=content),\n        ]\n\n        for model in self.models:\n            try:\n                summary = model.simple_send_with_retries(summarize_messages)\n                if summary is not None:\n                    summary = prompts.summary_prefix + summary\n                    return [dict(role=\"user\", content=summary)]\n            except Exception as e:\n                print(f\"Summarization failed for model {model.name}: {str(e)}\")\n\n        raise ValueError(\"summarizer unexpectedly failed for all models\")\n\n\ndef main():\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"filename\", help=\"Markdown file to parse\")\n    args = parser.parse_args()\n\n    model_names = [\"gpt-3.5-turbo\", \"gpt-4\"]  # Add more model names as needed\n    model_list = [models.Model(name) for name in model_names]\n    summarizer = ChatSummary(model_list)\n\n    with open(args.filename, \"r\") as f:\n        text = f.read()\n\n    summary = summarizer.summarize_chat_history_markdown(text)\n    dump(summary)\n\n","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/Aider-AI/aider/blob/5dc9490bb35f9729ef2c95d00a19ccd30c26339c/aider/history.py#L105-L141","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","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).","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.","As a workaround for very long sessions, start a fresh session or manually trim the chat history so summarization is not needed."],"exampleFix":"// before\nmodel_names = [\"gpt-3.5-turbo\", \"gpt-4\"]\nsummarizer = ChatSummary([models.Model(n) for n in model_names])\nsummary = summarizer.summarize(messages)  # raises if all models fail\n\n// after\ntry:\n    summary = summarizer.summarize(messages)\nexcept ValueError as e:\n    if \"summarizer unexpectedly failed\" in str(e):\n        # keep raw (truncated) history instead of aborting the session\n        summary = messages[-self.max_tokens:]\n    else:\n        raise","handlingStrategy":"fallback","validationCode":"from aider.history import ChatSummary\n\ndef summarize_safe(summarizer, messages, keep_last=50):\n    try:\n        return summarizer.summarize(messages)\n    except ValueError as e:\n        if \"summarizer unexpectedly failed\" in str(e):\n            # fallback: keep the most recent messages instead of a summary\n            return messages[-keep_last:]\n        raise","typeGuard":null,"tryCatchPattern":"try:\n    summary = summarizer.summarize(messages)\nexcept ValueError as e:\n    if \"summarizer unexpectedly failed\" in str(e):\n        messages = messages[-50:]  # degrade gracefully, keep session alive\n    else:\n        raise\nelse:\n    messages = summary","preventionTips":["Validate every summarization model's API key with a cheap test call (simple_send_with_retries on a one-line prompt) before starting a long session.","Watch the per-model 'Summarization failed for model ...' console lines — they carry the root cause before the aggregate raise.","Use a summarizer model with a context window larger than your expected session length.","Start a new session or /clear when token warnings appear, so summarization is never forced with a broken backend."],"tags":["llm","summarization","api-key","context-length","aider"],"backgroundTag":null,"analyzedSha":"5dc9490bb35f9729ef2c95d00a19ccd30c26339c","analyzedAt":"2026-08-15T05:40:10.498Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}