Anthropic max_tokens stop is not raised as OutputTooLongError; OpenRouter Claude gets no cache_control; default gpt-5-nano shuts down 2026-12-11
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start with the cited provider paths in anthropic_llm.py, openai_compatible_llm.py, litellm_llm.py, and the defaults in config.py; then read the linked recovery paths in fact_extraction.py and llm_wrapper.py. The report proposes three independent fixes across provider error handling, OpenRouter caching, and model defaults. Check each against its cited scenario; the issue lists a concrete check for each.
Written by the indexing model from the issue text.
Description
Three things we found reading the LLM call paths at d8d03e0. Each has the file and line, what it costs, a suggested change and how to check it.
1. Anthropic: a reply cut off at max_tokens is retried unchanged and never reaches the split recovery
Where: anthropic_llm.py:485 reads stop_reason only for the trace span, and anthropic_llm.py:517 retries a JSONDecodeError with the same request. Only refusal and content_filter are acted on (_raise_on_refusal, line 86).
The other providers turn the same signal into OutputTooLongError: openai_compatible_llm.py:497, openai_responses_llm.py:308, litellm_llm.py:424. Two things depend on that error and never run for Anthropic. Retain splits the chunk in fact_extraction.py:2843, and the schema-held tool loop samples once more in llm_wrapper.py:1761. With the Anthropic provider a cut-off JSON reply instead fails to parse, the identical request is sent up to max_retries + 1 times (default 3, so 4), each paying for a reply of up to 64,000 output tokens, and retain fails the chunk. A cut-off free-form reply (no response_format) is returned as if complete.
The comment at openai_compatible_llm.py above line 497 already explains why a truncated free-form answer should fail the call, so this looks like a provider that was left out rather than a decision.
Cost (estimate, frequency unknown): if one reply in 10,000 reaches the cap, that is about 25,600 output tokens per 1,000 calls (4 attempts of up to 64,000 tokens, 0.1 events per 1,000 calls), plus the resent prompt.
Suggested change: next to _raise_on_refusal, raise OutputTooLongError when response.stop_reason == "max_tokens", in the sync path and in _translate_batch_message (line 672).
Check: with a small max_completion_tokens, one Anthropic retain call makes one request and then splits the chunk, instead of four identical requests.
2. OpenRouter with a Claude model sends no cache_control
Where: openai_compatible_llm.py:1318 builds messages as plain strings, and caches_marked_prefix() is only overridden by the Anthropic and LiteLLM providers. configuration.mdx shows the openrouter provider and mentions anthropic/claude-haiku-5.5 as a model it can serve.
OpenRouter's prompt-caching page (checked on 2026-12-03) says: "Most providers automatically enable prompt caching, but note that some (see Alibaba and Anthropic below) require you to enable it on a per-message basis." Anthropic models there need cache_control on a content block. The Anthropic provider marks the system block (anthropic_llm.py:150) and the LiteLLM provider does it for Claude models (litellm_llm.py:132), so a Claude model on the openrouter provider is the one route that re-reads the system prompt at full price on every call, and reflect's turn-history marking (#6671) does not apply to it either.
Cost (estimate): the retain extraction system prompt is _BASE_FACT_EXTRACTION_PROMPT, about 9,500 characters, so roughly 2,400 tokens, above the 512-token minimum for current Claude models on Anthropic's caching page (checked 2026-11-28). Sent on every chunk within seconds of the last, that is about 2.4M prompt tokens per 1,000 calls not served from cache, only for deployments that route Claude through OpenRouter.
Suggested change: for the openrouter provider (or openai pointed at openrouter.ai) with an anthropic/ model, wrap the system message in one text part with cache_control of type ephemeral, as _with_cached_system does in litellm_llm.py:123, and return true from caches_marked_prefix() there. A setting like HINDSIGHT_API_LLM_LITELLM_PROMPT_CACHE would cover proxied aliases.
Check: two retain calls a minute apart through OpenRouter; usage.prompt_tokens_details.cached_tokens on the second rises from 0 to about the size of the system prompt.
3. The default openai model, gpt-5-nano, has a shutdown date of 2026-12-11
Where: config.py:1347 ("openai": "gpt-5-nano"), with the same id for litellm (line 1371), requesty (line 1375) and DEFAULT_LLM_MODEL (line 1380). DEFAULT_LLM_PROVIDER is openai, so an install that sets only a key uses it.
OpenAI's deprecations page, checked on 2026-11-28, lists gpt-5-nano, gpt-5-nano-2025-08-07 with shutdown Dec 11, 2026 and the replacement gpt-6-luna (the repo already uses gpt-6-luna as the chatgpt default). PR #6589 picked gpt-5-nano on 2026-11-16 as a cheaper default and does not mention the date.
Suggested change: move these four defaults, and the Hermes openai default, to a model that is not on the list.
Check: start with only HINDSIGHT_API_LLM_PROVIDER=openai and an API key after 2026-12-11; the default model answers.
We know an unsolicited report is easy to file under noise, so this is the only post we will make here, and whatever you decide about it is fine with us.
This was found by leanprompt, our open-source set of skills for working with LLMs safely and efficiently, while we ran it on public repositories. The numbers above are estimates from reading the code, not measurements, so please treat them as a starting point. The suggested fix was written with an AI coding assistant and checked by hand.
If you want to see how other projects handled the same problems, the audits of dozens of public repositories show what each had and what the ones that shipped a fix changed. The checks grow as providers change their caching, limits and model lists: npx leanprompt install runs them in your own coding agent, and leanprompt score --github shows the open findings on your pull requests.
- Dominant language
- Python
- Stars
- 45.2k
- Forks
- 5.9k
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vectorize-io/hindsight
-
core
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
vectorize-io/hindsight#7254 ·
-
Control Plane shows different calendar dates for the same occurrence in Constellation and TimelineOpencore
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
vectorize-io/hindsight#7240 · 1 comment ·
-
core
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vectorize-io/hindsight#7233 ·
-
core
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
vectorize-io/hindsight#7231 ·
-
core
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
vectorize-io/hindsight#7228 · 1 comment ·
All issues in vectorize-io/hindsight
Similar issues
-
Test: to_hijri() accepts datetime.datetime and uses only the date partPossibly taken A pull request linked to this issue is open or already merged. Opengood first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 · 3 comments ·
Maintainers usually reply within 1 day
-
polish
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
521xueweihan/HelloGitHub#4729 ·
-
[Bug]: Score parser reads parts of scientific notation as valid scoresPossibly taken @AshutoshSingh840 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
UKGovernmentBEIS/control-arena#992 ·
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
mvalentsev/awesome-free-ai-coding#70 ·
Maintainers usually reply within 1 day