Repository navigation
fix(ollama_chat): backport streamed tool call indices to lts/1.108.x (#49183) - #50718
Conversation
Ollama streams parallel tool calls one per chunk with no top-level index, and the delta numbers the calls of each chunk from zero, so every call left the proxy as index 0 and OpenAI-style clients appended the arguments of each later call onto the first one. Number the calls with a counter that lives for the whole stream instead. Fixes BerriAI#33678 Backport of BerriAI#49183 to lts/1.108.x. Cherry-picked from df6126e (fix-ollama-chat-stream-tool-call-index).
…t JSON A chat history that already holds a merged tool call from an older stream used to fail with a 500 APIConnectionError. It now answers 400 naming the tool call. The streaming tests use Ollama's real tool call shape and drop a case the merge base already passed. Backport of BerriAI#49183 to lts/1.108.x. Cherry-picked from 84154df (fix-ollama-chat-stream-tool-call-index).
…repair parser Empty, null, and truncated arguments in a replayed assistant tool call now go through parse_tool_call_arguments, so they are forwarded as an object instead of answering 500. Arguments that still are not a JSON object answer 400 naming the call id. Backport of BerriAI#49183 to lts/1.108.x. Cherry-picked from 0ae806c (fix-ollama-chat-stream-tool-call-index). Adapted to the line. parse_tool_call_arguments is imported from common_utils, its home here, and the forwarded-object test expects no tool call id, since the line does not forward ids.
…nt text out of the repair warning
Replayed tool call arguments of the JSON string "null" used to reach Ollama and return 200. The shared parser turns them into None, so they now go out as {} like empty or missing arguments instead of answering 400.
The parser's repair warning logged up to 200 characters of the arguments. It now logs only the tool name, context, and length.
Backport of BerriAI#49183 to lts/1.108.x.
Cherry-picked from e604431 (fix-ollama-chat-stream-tool-call-index).
Adapted to the line. The repair warning change goes into common_utils.py, where parse_tool_call_arguments lives here, and its test goes into that module's test file.
…error chain Backport of BerriAI#49183 to lts/1.108.x. Cherry-picked from 0f7003a (fix-ollama-chat-stream-tool-call-index).
…e logging is off Backport of BerriAI#49183 to lts/1.108.x. Cherry-picked from 5ef6d62 (fix-ollama-chat-stream-tool-call-index). Adapted to the line. The repair warning lives in common_utils.py here.
Backport of BerriAI#49183 to lts/1.108.x. Cherry-picked from 1f71ed3 (fix-ollama-chat-stream-tool-call-index). Adapted to the line. The repair warning tests live in test_litellm_core_utils_prompt_templates_common_utils.py here.
PR overviewThe PR backports streamed tool-call index handling for Ollama chat to lts/1.108.x, touching shared tool-argument repair utilities. One issue remains open: tool-argument repair warnings can log the first 200 characters of argument contents despite request-level message redaction being enabled. This creates a limited disclosure path into logs for requests that explicitly disable message logging; no issues have been addressed yet. Open issues (1)
Fixed/addressed: 0 · PR risk: 5/10 Reviews |
|
|
||
|
|
||
| def _logged_arguments(arguments: str) -> str: | ||
| if litellm.turn_off_message_logging: |
There was a problem hiding this comment.
Medium: Repair warnings ignore request-level message redaction
With the global flag false, an Ollama completion using turn_off_message_logging=True or x-litellm-enable-message-redaction: true still logs the first 200 characters of repaired tool arguments; I reproduced both through litellm.completion with a mocked provider response. Pass the request’s effective redaction decision, computed by should_redact_message_logging, into the repair logger, or omit argument contents from this warning.
There was a problem hiding this comment.
This mirrors #49183 on main, and the line today logs full arguments under every setting. Request-level redaction for this warning is a tracked follow-up
[Medium impact] The PR appears safe to merge, with no outstanding findings SummaryThis backports separate streamed tool-call indices to the LTS branch. Replayed arguments use the shared repair parser, and rejected arguments return HTTP 400 naming the call The updated live proxy proof addresses the previous QA finding. No new actionable issues were found
Reviews (2) · Last reviewed commit: "Merge remote-tracking branch 'origin/lts..." · Reviewed by Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…rt_49183_lts_1_108_x # Conflicts: # litellm/litellm_core_utils/prompt_templates/common_utils.py
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 2fd636e. Configure here.
…tuses (#95) ## Summary `wiretruth lint` now checks that each stored PASS, LOSSY or WRONG grade follows from the MUST statuses next to it, along with the other gaps listed in #90. The same PR corrects four statements from #91: the upstream status of BerriAI/litellm#33678, the site's Suite label, and one sentence each in `docs/formats.md` and the README. Closes #90 Closes #91 ## Why Rule 7 says grades are computed, never hand-edited, but nothing checked a committed results file against its own requirement statuses. Conformance re-runs only the pinned version of each library, and the site and `docs/validation.md` also read the eight older files. #91 collects statements on the site and in the docs that no longer match the repository or the upstream state. ## What changed - `grading.py`: the step from MUST statuses to PASS, LOSSY or WRONG is `must_grade(statuses)`. `grade_cell` calls it and keeps its rule numbers (6, 7, 8) and `RULES`. - `lint.py`, for each results file: - a PASS, LOSSY or WRONG cell whose grade differs from `must_grade` of its MUST statuses, that has no requirements, or whose observation is a raised `internal` error (rule 5 gives CRASH) → error at `$.cells[i].grade`; - a duplicate requirement id → error at `$.cells[i].requirements[j].id`; the same scenario and provider twice → error at `$.cells[i]`; - CRASH, HANG, UNSUPPORTED and HARNESS cells are not recomputed, because their rules depend on the run. - `lint.py`, for `results/upstream.json`: an entry whose library has no `results/<library>/` directory, and a `released` entry with a null or empty `fixed_in`. Skipped when `results/` is missing, like the rest of the results checks. - `lint.py` also loads the built-in `shims/reference/` and `shims/liar/` manifests, which the `shims/*/*/` glob missed (146 → 148 files). - `results/upstream.json`: BerriAI/litellm#33678 is `fix-merged` with `pr` set to BerriAI/litellm#49183, and `fixed_in` stays null. The upstream merge commits are [6a232c9](BerriAI/litellm@6a232c9) on `main` (2026-11-09) and the backport [a354fb7](BerriAI/litellm@a354fb7) on `lts/1.108.x` (BerriAI/litellm#50718, merged after v1.108.4 was tagged). The cell stays WRONG: it also needs BerriAI/litellm#46543, which is open and keeps `reported`. No results file changes. - Site index: no "Suite" label (it showed the highest dev suite version among the current results files). "Updated" stays, and each results file keeps its `suite_version`. - `docs/formats.md`: the remark that shim manifests aren't linted is gone, and the list of lint checks names every check above plus the manifest schema, the manifest and `package.json` secret scan and the packages rule. - README Quickstart: Python libraries install into `.wiretruth/envs/`, JavaScript libraries into `node_modules` next to their shim. - `CHANGELOG.md`: Unreleased → Added (lint) and Changed (upstream status, site label). Out of scope, as #90 says: comparing a cell's requirement ids and levels with today's scenario file, and checking that an upstream entry's scenarios and providers still exist. ## How tested The reproduction from #90 plus the two upstream probes, on a copy of `suite/`, `results/` and `shims/` (the grade flipped to PASS with a SATISFIED copy of `finish-is-other` in front, the first upstream entry's library renamed to `no-such-lib`, one `released` entry with `fixed_in: null`): ```text $ wiretruth lint . results/litellm/1.105.5.json: $.cells[4].requirements[2].id: duplicate requirement id 'finish-is-other' results/litellm/1.105.5.json: $.cells[4].grade: PASS doesn't follow from its MUST statuses, which give WRONG results/upstream.json: $[0].library: no results directory for 'no-such-lib' results/upstream.json: $[5].fixed_in: a released entry must have a nonempty fixed_in wiretruth lint: 4 errors in 2 of 148 files ``` On this branch: ```text $ uv run ruff check . && uv run ruff format --check . && uv run mypy src All checks passed! / 91 files already formatted / Success: no issues found in 24 source files $ uv run pytest -q 2043 passed $ uv run pytest -q tests/unit/test_grading.py --cov=wiretruth.grading --cov-branch grading.py 100% $ uv run wiretruth lint wiretruth lint: 148 files, no errors $ uv run wiretruth site --out _site cells/litellm/tools.parallel-calls-stream/ollama.html shows fix-merged and links pull/49183; index.html has no "Suite" ``` Each new lint test fails with its check removed. Sample CRASH, HANG, UNSUPPORTED and HARNESS cells, with and without contradicting statuses, still pass. ## Results impact none (no grade changes; the committed results files all pass the new checks) ## Checklist - [x] Tests added or updated - [x] `uv run ruff check . && uv run ruff format --check . && uv run mypy src && uv run pytest -q` pass - [x] `uv run wiretruth lint` passes (suite data, secrets, truth) - [x] `CHANGELOG.md` updated under `Unreleased` (if user-facing) - [x] Docs updated (if behavior or formats changed) - [x] New WRONG / CRASH / HANG cells have an upstream issue linked in `results/upstream.json`: none
Handwritten 1-3 sentence description
This brings #49183 to the 1.108 LTS line. When an
ollama_chat/model streams several tool calls at once, each now gets its own index, so OpenCode runs every call. Replaying a glued call answers 400 naming it instead of 500, and empty arguments now workOriginal
TLDR
Backport of #49183 to
lts/1.108.xProblem this solves:
ollama_chat/streaming setsindex: 0on every tool call deltaHow it solves it:
turn_off_message_loggingis onBackport checklist
b8150535251as2fd636e6103, keeping both imports in its one conflict2fd636e6103the picks' two test files pass (302/302), and so do 6,911 other tests in files that reach the changeenterprise/andlitellm-proxy-extras/are unchanged)9dd965188fb,8421785a043,23603928924,2280aa224b9,d9011b1593fand2fd636e6103The 7 picks, adaptations, the confirmed finding, and rejected findings
df6126edaa0(one tool call counter per stream) applied clean asa547ed0a94b84154df9e98(400 for replayed arguments that are not JSON) applied clean as9dd965188fb0ae806cce40(shared repair parser for replayed arguments) adapted as8f84442124d, see belowe6044318cc2({}for"null"arguments, no argument text in the repair warning) adapted as8421785a043, see below0f7003a2aeb(no argument text in a rejected replay's error chain) applied clean as236039289245ef6d62cca7(repair warning preview kept unless message logging is off) adapted as2280aa224b9, see below1f71ed377f4(more repair warning tests) adapted asd9011b1593f, see below8f84442124dimportsparse_tool_call_argumentsfromcommon_utils, its home on the line. One test expects no tool callid, since fix(ollama): forward assistant tool call ids in ollama_chat requests #49278 is not on the line8421785a043and2280aa224b9make their repair warning changes incommon_utils, the warning's home on the line, and they andd9011b1593fput their tests in that module's test fileConfirmed by run 8d1a27df4e46 on
8f84442124d. Replayed"null"arguments went from 200 to 400. fix(ollama_chat): give each streamed tool call its own index #49183 fixed it ine6044318cc2, picked as8421785a043, which run 840a315cb670 reviewedStrongest dissent, rejected. One tool call streamed as string fragments across chunks would get two indices, but Ollama 0.40.14 sends each call whole, and fix(ollama_chat): give each streamed tool call its own index #49183 on main does the same
Rejected. A mixed-provider group with retries, or
fallback_on_unsupported_params: false, does not retry the 400, which is the intended answer, and default fallbacks still fireRejected. Style nits and a missing 201-character case in the picked tests mirror fix(ollama_chat): give each streamed tool call its own index #49183
Strongest dissent on
8421785a043, rejected. Arguments the parser cannot repair still reach a WARNING log in full through its error text, which the line tip and main already doRejected. A no-argument streamed tool call that Ollama sends without an id is dropped when the stream is rebuilt, the same on the line tip and main, and Ollama 0.40.14 sends ids
Rejected. Deeply nested array arguments raise a 500 through
RecursionError, the same on the line tipStrongest dissent on
23603928924, rejected. The parse error stays on the 400's__context__, so code that reads it directly could still see the arguments, but nothing on the line does, and tracebacks, logging and Sentry skip itRejected. The
[]case's traceback check cannot fail, but the case still catches aparsed or {}rewrite, the same as fix(ollama_chat): give each streamed tool call its own index #49183Strongest dissent on
2280aa224b9, rejected. A request that turns message logging off only for itself, per key or through compaction, still gets the 200-character preview, but the line's release logs it under every setting and fix(ollama_chat): give each streamed tool call its own index #49183 does the sameRejected. A secret that crosses character 200 is cut before the secret filter sees it, the same as the line's release
Rejected. No test pins a short argument string being logged in full, the same as fix(ollama_chat): give each streamed tool call its own index #49183
Run 61c0db3b0a08 on the merge
2fd636e6103found nothing the merge causes. The line's new code incommon_utilsandfactorynever calls what the picks changed, and every side note it raised (a history tool call with notypeanswering 500, a streamed no-argument call with no id, the per-request logging flag) behaves the same on the line tipUser Flow
Before: an OpenCode user on an Ollama model behind the proxy asks for two files at once and only the first is read
@ai-sdk/openai-compatibleprovider at https://litellm-domain/v1 with anollama_chat/model"index": 0Read a.rsand never reads b.rs (the OpenAI SDK glues both into one call with arguments{"path": "a.rs"}{"path": "b.rs"})litellm.APIConnectionError: Extra dataAfter: the same request comes back as two tool calls and OpenCode reads both files
"index": 0and"index": 1Read a.rsandRead b.rsRelevant issues
The fix for #33678 on
lts/1.108.x. #49183, its main PR, merges firstPre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CIScreenshots / Proof of Fix
Ollama 0.40.14 serves
qwen3:0.6b. Each leg runs 2 workers with its own Redis and no--reload. Each OpenCode trial typesRead the files a.rs and b.rs. Call the read tool once for each file, both calls at once.qa_config_<leg>.yaml (only the Redis port differs)
opencode.json (OpenCode 1.19.5 TUI under tmux, isolated HOME)
{ "$schema": "https://opencode.ai/config.json", "autoupdate": false, "share": "disabled", "provider": { "litellm": { "npm": "@ai-sdk/openai-compatible", "name": "LiteLLM proxy", "options": { "baseURL": "http://127.0.0.1:<proxy port>/v1", "apiKey": "{env:LITELLM_MASTER_KEY}" }, "models": { "ollama-qwen3-opencode": { "name": "qwen3:0.6b on Ollama via LiteLLM", "tool_call": true, "limit": { "context": 32768, "output": 4096 } } } } }, "model": "litellm/ollama-qwen3-opencode" }qa_client.py (OpenAI Python SDK 3.46.0 and Anthropic Python SDK 2.6.0, three runs per case)
Each case matched on all 3 runs
9dd965188fbchat, turn 1chat, turn 2Extra dataresponses, two parallel callsfunction_callitemsmessages, two parallel callstool_useblockstool_useblocksreplay, a glued callcall_0replay_emptyExpecting valuereplay_null, arguments"null"Before (831a14c)
Proxy boot
Both legs drop
--reload, since uvicorn then ignores--num_workersOpenCode, two parallel reads
opencodeon port 26471 in a folder holdinga.rsandb.rs, and send the prompt abovePane text, trial 2
Trials 1 and 3
Client cases
qa_client.py <case>three times for each case belowchat, 3 runs
replay, 3 runs
replay_empty and replay_null, 3 runs each
responsesandmessagesqa_client.py responsesandqa_client.py messagesthree times eachProxy boot for this run
responses and messages, 3 runs each
After (2fd636e)
Proxy boot
OpenCode, two parallel reads
These trials ran at
9dd965188fb. Later commits change only how replays are parsed and logged, and the merged line changes do not touch Ollamaalpha()andbeta()Pane text, trial 2
Trials 1 and 3
Client cases
chat, 3 runs
responses and messages, 3 runs each
replay, 3 runs
replay_empty and replay_null, 3 runs each
Type
🐛 Bug Fix
Caveats (if any)
Low
function.index, so a server that omits or repeats that field still gets unique indicesollama/route still answers 500 for these histories, and it is followed up separatelyqwen3:0.6b, since newer Qwen models start at 27BFinal Attestation
Note
Medium Risk
Touches Ollama request transformation and streaming tool-call indexing on a widely used chat path; behavior changes (400 vs 500, distinct indices) but is covered by targeted unit tests.
Overview
Backports Ollama chat fixes so parallel streamed tool calls get sequential
indexvalues across chunks (fixes clients merging every delta into index 0), and replayed assistant tool arguments go through the sharedparse_tool_call_argumentspath with HTTP 400 when they are not a JSON object (instead of 500 on bad JSON).common_utils: repair warnings now log argument previews via_logged_arguments(200-char cap, full redaction whenturn_off_message_loggingis on) instead of echoing the raw string.Tests cover log preview/redaction, Ollama history argument forwarding, invalid replay errors, and streaming index numbering.
Reviewed by Cursor Bugbot for commit 2fd636e. Bugbot is set up for automated code reviews on this repo. Configure here.