reflect: Ollama's context-overflow 400 is not recognised as an overflow, and `REFLECT_MAX_CONTEXT_TOKENS` ignores `LLM_OLLAMA_NUM_CTX`
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 56/100
Research direction
Start by reading _is_context_overflow_error in engine/reflect/agent.py and trace where the reflect context-token budget is configured from HINDSIGHT_API_LLM_OLLAMA_NUM_CTX and HINDSIGHT_API_REFLECT_MAX_CONTEXT_TOKENS. Check the existing overflow and budget tests before changing behavior. Done means Ollama’s reported wording triggers final synthesis, and the default budget respects the configured context size when the override is unset.
Written by the indexing model from the issue text.
Description
Bug Description
With the Ollama provider, a mental-model refresh whose reflect loop outgrows the model's context fails outright
instead of falling back to a final synthesis from the evidence already gathered, and the page is then paused. Two
things combine:
_is_context_overflow_error(engine/reflect/agent.py) looks for phrases such ascontext_length_exceeded,
maximum context lengthandprompt is too long. Ollama words the error as "the prompt is longer than the context
length currently available to the model", which matches none of them, so the branch that forces final synthesis on
an overflow is skipped and the 400 ends the refresh.HINDSIGHT_API_REFLECT_MAX_CONTEXT_TOKENSkeeps its default of 100,000 even when
HINDSIGHT_API_LLM_OLLAMA_NUM_CTXtells Hindsight the model has 32,768. The budget is the threshold at which the
loop forces synthesis, so with these settings the loop keeps adding evidence long after the prompt has outgrown the
context Hindsight itself asked Ollama for.
Environment
hindsight-api1.3.0 (throughhindsight-embed) on macOS; both points are unchanged in v1.3.1 and onmain.HINDSIGHT_API_LLM_PROVIDER=ollama,HINDSIGHT_API_LLM_OLLAMA_NUM_CTX=32768,
HINDSIGHT_API_REFLECT_MAX_COMPLETION_TOKENS=8192;HINDSIGHT_API_REFLECT_MAX_CONTEXT_TOKENSnot set.- Ollama 0.40.19 with
qwen3.8:27b(Q4_K_M); Ollama's server log showsn_ctx = 32768on every load.
Actual Behavior
In the API logs we keep (2026-11-04 to 2026-12-04), 9 refresh_mental_model tasks failed with this error, one on
2026-11-25, seven on 2026-11-29 and one on 2026-11-30:
Task execution failed: refresh_mental_model, error: UpstreamHTTPError: HTTP 400 from http://127.0.0.1:11434/api/chat: {"error":"the prompt is longer than the context length currently available to the model; shorten the prompt, adjust the context length in settings, or use a model with a longer context length"}
The same 400 was logged twice more by reflect.agent as "closing done call failed, using the standalone prompt";
that fallback re-sends a prompt sized from the same budget. Each failed refresh set last_refresh_failed_at, so those
pages were left paused (they show in paused_mental_models since #6375).
Expected Behavior
- Ollama's wording counts as a context overflow, so the refresh synthesizes from what it has, as it would on
OpenAI'scontext_length_exceeded. - With
REFLECT_MAX_CONTEXT_TOKENSunset andLLM_OLLAMA_NUM_CTXset, the default follows the context: for example
num_ctx - reflect_max_completion_tokens, less a margin, since the budget is ano200k_baseestimate of the
messages that leaves out the tool schemas sent with each request (and with no completion cap set, some fixed share
ofnum_ctx). Withoutnum_ctx, Ollama 0.40.19 reports a loaded model's context ascontext_lengthin
GET /api/ps; a startup warning when the reflect budget exceeds it would at least make the mismatch visible.
Workaround
Setting HINDSIGHT_API_REFLECT_MAX_CONTEXT_TOKENS=24576 (32,768 - 8,192) has held since 2026-12-04 14:56: to 2026-12-05 08:49, 41 mental-model refreshes started (38 of them on 12-05) and none failed on the context.
- 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