By MV2 of Munim, Inc., with AI agents. Written on 13 November 2026 from Ollama v0.40.16's source (openai/responses_compact.go, server/responses_compact.go, server/routes.go, api/types.go) and the public reports linked below. We did not reproduce the error ourselves, and the diagnostic script below has not been run against a real session. See the limits.
A long agent thread (most reports are Codex Desktop or the Codex CLI pointed at Ollama, with a local or :cloud model) has been working for hours. Then it reaches its context limit, tries to compact, and fails with HTTP 400:
item_000008: function output has no matching call "call_ollama_compaction_4a3e91772b24"
The item number and the 12 hex characters differ from thread to thread. From then on, every compaction of that thread fails the same way. Retrying doesn't help, and neither does switching the model.
| What you see | What it means | What to do |
|---|---|---|
The quoted ID starts with call_ollama_compaction_ | An Ollama bug, open as ollama#19623. An earlier compaction saved the result of an older summary without the call that goes with it. That broken summary now travels with the thread, and Ollama's compaction rejects it every time. | Carry the summary into a new thread, or run a build with one of the open fixes. Retrying the same thread won't work. |
The quoted ID is anything else (for example call_abc123…) | The orphaned tool result came from your client's own history, not from an Ollama summary. Ollama only checks call/result pairs when it compacts, so the problem shows up there. | See if the ID is not an Ollama one. |
When a client such as Codex asks Ollama to compact a conversation on /v1/responses, Ollama doesn't return an opaque blob the way OpenAI does. It asks the model for a summary and a list of items to keep, and returns one item of type compaction. Its encrypted_content is plain JSON, not encrypted: {"type":"ollama_compaction","version":1,"summary":"…","retained":[…]}. The client stores that item and sends it back with every later request. Ollama then unpacks it into a synthetic tool call named ollama_compaction_summary with the ID call_ollama_compaction_ plus the first 6 bytes of the payload's SHA-256 in hex, followed by that call's result (the summary text), followed by the retained messages.
In v0.40.16 the bug works like this:
analyzeCompactionToolState deliberately leaves summary pairs out of its list of call/result groups (so trimming never drops a summary). But the code that keeps a call and its result together only looks at that list. So if the model keeps S1's result but not its call, the result alone goes into S2's retained list.analyzeCompactionToolState stops with fmt.Errorf("%s: function output has no matching call %q", item.Ref, callID). The server turns that into HTTP 400 with error.code invalid_request_error.This explains the details people report:
compaction_trigger, or POST /v1/responses/compact. The thread works until it next needs to compact.:cloud models are affected too. In routes.go, /v1/responses runs Ollama's compaction middleware before the cloud passthrough. So the check happens on your local Ollama even when the model runs on ollama.com.item_000008 is the item's 1-based position in the list Ollama built for this compaction, after unpacking the saved summary. It only helps with locating the item, not with fixing it.Credit: the reporter of ollama#19623 (9 Nov 2026, Ollama 0.40.15, Codex Desktop with DeepSeek) found the pattern and a synthetic reproduction. The cause above matches the descriptions in the two fix pull requests, and we checked it against the v0.40.16 source.
Because the payload is plain JSON, the broken summary can be read from the file where your client saves the conversation. Codex keeps its sessions as JSON Lines files under ~/.codex/sessions/. This read-only script searches any .json or .jsonl file for Ollama compaction payloads and lists retained tool results that have no matching call:
# find_orphans.py (Apache-2.0, MV2 of Munim, Inc., made with AI agents). Read-only.
# usage: python3 find_orphans.py SESSION.jsonl [--summary]
import json, sys
def strings(x):
if isinstance(x, dict):
for v in x.values(): yield from strings(v)
elif isinstance(x, list):
for v in x: yield from strings(v)
elif isinstance(x, str):
yield x
def docs(path):
text = open(path, encoding="utf-8").read()
try:
yield json.loads(text)
except ValueError:
for line in text.splitlines():
try:
yield json.loads(line)
except ValueError:
pass
found, last = 0, None
for doc in docs(sys.argv[1]):
for s in strings(doc):
if '"ollama_compaction"' not in s:
continue
try:
p = json.loads(s)
except ValueError:
continue
if not isinstance(p, dict) or p.get("type") != "ollama_compaction":
continue
found, last = found + 1, p
msgs = p.get("retained") or []
calls = {tc.get("id") for m in msgs for tc in (m.get("tool_calls") or [])}
orphans = [m.get("tool_call_id") for m in msgs if m.get("role") == "tool"
and m.get("tool_call_id") and m.get("tool_call_id") not in calls]
print("summary %d: %d retained messages; orphaned results: %s"
% (found, len(msgs), ", ".join(orphans) or "none"))
print(found, "Ollama compaction summaries found")
if last and "--summary" in sys.argv:
print("\n--- newest summary text ---\n" + last.get("summary", ""))
The same payload can appear several times in one file, because clients often log it more than once. The last line printed is usually the newest one, and Ollama uses only the newest. If that line lists an ID starting with call_ollama_compaction_, you have the bug above. Results inside the payload are matched against calls in the same payload. That is how Ollama unpacks them: a newer summary replaces the older ones, and its kept call/result pairs travel together.
python3 find_orphans.py SESSION.jsonl --summary prints the newest summary text. It is the same text the model would have seen after a successful compaction, so pasting it into the first message of a new thread carries over most of the context. Check it for secrets or private data before pasting it anywhere else.| Pull request | What it changes | State |
|---|---|---|
| ollama#19635 "openai: keep the compaction summary call with its result" | Keeps a summary's call and result together when items are selected, and restores the missing call when unpacking summaries saved before the fix, so threads that are already broken should work again. The author lists a test for each half. | Open, not reviewed, not merged |
| ollama#19532 "openai: keep prior compaction summary pairs paired" | Drops the special case that leaves summary pairs out of normal pair checks, protects them in trimming, and rejects orphaned, duplicate or mismatched summary calls | Open, draft |
Neither change is in a release. openai/responses_compact.go was last changed on 29 October 2026, so v0.40.16 and v0.40.17-rc0 still have the bug. When a release notes a compaction fix, update with ollama -v to check the version you run. Going by #19635's description, an affected thread should then compact again without changes on your side, but check the merged code: #19532 takes a different approach and may not repair summaries that were already saved. If you build Ollama from source, you can test a branch yourself. It is unreviewed code, so keep it away from anything that matters.
When Ollama compacts, every tool result in the history must have a call with the same call_id earlier in that history. Results with no call_id at all are accepted as standalone results. A result whose call_id has no call fails with the same message, naming that ID. Ollama doesn't check this on ordinary turns, so a client history that was broken long ago only fails at compaction. Several Codex reports describe client-side ways tool results lose their calls: injected or automation outputs (codex#45450, codex#49173), and pairing being enforced only when history is rebuilt (codex#46193). Starting a new thread works around those too. Report them to the client's maintainers, not to Ollama.
AI agents working for MV2 of Munim, Inc. read, on 13 November 2026: Ollama v0.40.16's openai/responses_compact.go, openai/responses.go, server/responses_compact.go, the /v1/responses route in server/routes.go, and api/types.go; the commit history of openai/responses_compact.go; issue #19623; pull requests #19635 and #19532; and the Codex issues linked above. Limits:
find_orphans.py has not been run against a real Codex session file. It assumes the payload fields Ollama writes in v0.40.16 (type, summary, retained, and in messages role, tool_calls[].id, tool_call_id). Other clients may store the item differently. The script only reads and prints.Corrections are welcome as issues at github.com/munimtechnologies/local-ai-checkup.
The free local-ai-checkup script shows which AI ports on your machine other computers can reach. The CVE checker tells you which security advisories affect your Open WebUI or Ollama version. Both are read-only and send nothing off the machine.
MV2 of Munim, Inc. does a $49 local AI health check for one machine, or a $199 small-office check for up to 5 machines or one shared Ollama, vLLM or Open WebUI server. You get a written report of what's exposed, risky or slow and what to fix first, with exact commands for your OS. See a sample report. Pay $49 or pay $199 on Stripe, then email mv2@munimtech.com the output of python3 local_ai_checkup.py --json, your OS, and what you use it for. MV2 never asks for passwords, keys or remote access.