Skip to content

fix(vlm): send Ollama num_ctx as a top-level option - #5033

Merged
qin-ctx merged 1 commit into
volcengine:mainfrom
CryoThrust:fix/ollama-num-ctx
Sep 17, 2026
Merged

qin-ctx merged 1 commit into
volcengine:mainfrom
CryoThrust:fix/ollama-num-ctx

Conversation

@CryoThrust

Copy link
Copy Markdown
Contributor

Summary

Send Ollama's num_ctx as a top-level LiteLLM argument instead of inside extra_body.

Why

For the ollama/ and ollama_chat/ routes, LiteLLM forwards extra_body verbatim as top-level request JSON, and Ollama only reads num_ctx from options. So the default (and any user value from vlm.extra_request_body) arrived as an unknown top-level field and was ignored — the model kept its 4096-token default and long prompts were truncated.

Verified against LiteLLM 1.91.1 by capturing the outbound body with a local HTTP server, rather than reading the transformation in isolation:

how OV passed it body sent to Ollama
extra_body={"num_ctx": 16384, "think": False} (before) {"options": {}, "num_ctx": 16384, "think": False} — ignored
num_ctx top-level, think in extra_body (after) {"options": {"num_ctx": 16384}, "think": False}

think is a valid top-level Ollama field, so it is left where it is; only num_ctx moves.

Tests

  • updated the three existing num_ctx assertions to check the top-level key
  • added a wire-level test that runs the built kwargs through OllamaChatConfig.transform_request and asserts options["num_ctx"], since asserting the built kwargs alone only proves where OV put the value, not the field Ollama reads
  • without the fix, 3 of those fail (assert kwargs["num_ctx"] == 16384, and the options one); with it, all pass
  • tests/unit/test_extra_headers_vlm.py: 39 passed; ruff check / ruff format --check clean

Related: #4879, #4898. Closes #5030.

LiteLLM forwards extra_body verbatim as top-level JSON for the ollama/ routes,
and Ollama only reads num_ctx from options. Putting the default (or a user's
extra_request_body value) inside extra_body therefore reached the server as an
unknown top-level field, so the model kept its 4096-token default and long
extraction prompts were truncated to ~2050 tokens.

Pass num_ctx as a top-level argument, which LiteLLM maps into options.num_ctx,
and drop it from extra_body. think is accepted top-level by Ollama either way,
so it stays in extra_body.
@qin-ctx
qin-ctx merged commit 9556402 into volcengine:main Sep 17, 2026
6 of 7 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Sep 17, 2026
frankyang2008-eng added a commit to frankyang2008-eng/OpenViking that referenced this pull request Oct 9, 2026
… isolation, plugin single-connection, VikingBot/Feishu studio, model network discovery)

22 upstream commits (PR volcengine#5096-volcengine#5139), 325 files, +13843/-3289.

Themes
- queuefs: isolate the background queue from the HTTP event loop (volcengine#5096)
- plugins: resolve one connection per plugin hooks + MCP proxy (volcengine#5132);
  run shell commands that carry viking URIs (volcengine#5131)
- studio: VikingBot conversations and Feishu onboarding (volcengine#5109); themes,
  dashboard and localized task pipeline (volcengine#5138, volcengine#5129, volcengine#5116, volcengine#5118)
- models: network service discovery hooks, new openviking/models/network.py
  (volcengine#5117); Ollama num_ctx as a top-level option (volcengine#5033)
- ingest: MiMo / MiMoCode log source, new openviking/ingest/sources/mimo.py
- server: fewer request cycles and lower GC latency (volcengine#5127)

Conflicts (7) and resolutions
- queuefs/{add,external_task,session_commit}_processor.py - upstream volcengine#5096
  removed OwnerLoopDispatcher and the service_loop constructor arg. The fork's
  only local change to these files was relocating task_work_index from
  openviking/service/ to openviking/storage/queuefs/. Took upstream's refactor,
  kept the fork's module path, dropped the now-unused import.
  Verified consistent: every construction site (service/core.py and all 5 test
  files) already uses the new signature; no get_running_loop is passed to any
  processor anywhere in the merged tree.
- examples/claude-code-memory-plugin/scripts/config.mjs - union of both
  improvements: upstream's injectable { env = process.env } = {} param plus the
  fork's HARNESS constant in place of the hardcoded "claude-code" literal.
- examples/memory-plugin-shared/credentials.test.mjs - upstream rewrote
  credentials.mjs; resolveOpenVikingCredentials no longer exists. Took upstream's
  imports, added back detectHarness/buildUserAgent for the fork's appended
  harness-detection tests (21 fork tests counted).
- web-studio/src/routes/tasks/route.tsx (7 hunks) - fork changes were Prettier
  reflows plus bilingual inline ternaries, both superseded by upstream volcengine#5116
  (t() i18n) and volcengine#5118 (skippedReason refactor). Took upstream's side.
  Verified: the merged onSuccess consumes result.skippedReason and
  localizeSkippedCommit is imported, so taking the fork's side would have
  orphaned that return and silently dropped the skip notice.
- examples/codex-memory-plugin/README.md - took upstream's hook table (adds the
  PreToolUse (Bash) row).

Not touched
- bot/ carries 1787 pre-existing mypy errors across 258 files and is in no type
  gate. Two upstream volcengine#5109 files surfaced findings; left byte-identical to main
  to avoid diverging the fork and re-conflicting every sync. See
  plans/upstream-type-debt-20260917.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Bug]: Ollama num_ctx from extra_request_body is never applied (LiteLLM sends it top-level), so extraction prompts are truncated to 2050 tokens

2 participants