Skip to content

route thinking controls to ollama - #9770

Merged
mahiatlinux merged 15 commits into
unslothai:mainfrom
Souravrajvi0:feat/ollama-reasoning-effort-7bf8
Aug 27, 2026
Merged

mahiatlinux merged 15 commits into
unslothai:mainfrom
Souravrajvi0:feat/ollama-reasoning-effort-7bf8

Conversation

@Souravrajvi0

@Souravrajvi0 Souravrajvi0 commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Addresses the Ollama API routing portion of #9649.

ExternalProviderClient.stream_chat_completion() now maps the existing enable_thinking and reasoning_effort request fields onto Ollama's OpenAI-compatible reasoning_effort field. Requests without either control remain unchanged.

This PR does not add Studio UI, provider capability flags, or persisted per-model reasoning state.

Behavior

  • enable_thinking: false sends reasoning_effort: "none".
  • enable_thinking: true without an effort sends reasoning_effort: "medium".
  • Explicit none, low, medium, high, or max is forwarded.
  • minimal maps to low; xhigh maps to max.

Verification

  • studio/backend/tests/test_ollama_reasoning_effort.py: 11 passed with warnings treated as errors.
  • Ruff passed on both changed Python files.

Ollama connections had no reasoning capability, so Studio hid Thinking
and never sent reasoning_effort. A reasoning model then kept its default
thinking with no way to turn it off (unslothai#9649).

Flag the connection as a reasoning model to show Thinking, then map
off/on onto Ollama's OpenAI-compat reasoning_effort field.
@mahiatlinux

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 46e3eb2d34

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Ollama connections can serve mixed catalogs, so the reasoning-model toggle
now stores which model ids support thinking. Unmarked models no longer
advertise Thinking or send reasoning_effort. Deep Research serializes
reasoningEffort "none" when Thinking is off so Ollama does not fall back
to the model's default.
@mahiatlinux

mahiatlinux commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Repair report

Scope update: the frontend work described below was removed in 864ab2b93. The current PR keeps only Ollama API thinking-control routing. See the scope correction for the reason, exact remaining behavior, and current verification.

Before

  • The PR head was based on adca7b9aa and conflicted with current main in chat-providers-dialog.tsx.
  • Ollama reasoning_effort=max was silently rewritten to high, although the current Ollama OpenAI-compatible API accepts max.
  • A malformed persisted reasoningModelIds value was treated like a legacy missing field. That widened one bad value into every enabled Ollama model and could send reasoning controls to models that reject them.
  • Provider sync preserved pins for models removed by the server. Re-adding a model later could silently restore an old reasoning selection.
  • The new per-model checkboxes had no accessible name.
  • test_ollama_reasoning_effort.py replaced the shared HTTP client without restoring or closing it, and left each event loop open.
  • The prior Windows frontend failure was the existing Shiki streaming-fence color assertion. It was unrelated to the Ollama paths changed here.

The two existing Codex findings were also rechecked. The PR author's latest commit had already scoped reasoning to marked Ollama model IDs and serialized reasoningEffort: "none" when Deep Research Thinking is off.

After

  • f5b805b71 merged current main and resolved the provider-dialog conflict while preserving the new per-model control.
  • 80c340be5 preserves Ollama max and maps Studio's xhigh alias to max. This matches the current Ollama compatibility documentation and Ollama request validation.
  • 9ed261317 distinguishes an absent legacy pin list from a present malformed value. Legacy rows still migrate to all enabled models; malformed rows fail closed to no pins.
  • d47b34097 intersects local reasoning pins with the model IDs returned by provider sync, while preserving an explicit empty list.
  • 87599b90f gives each per-model checkbox a model-specific accessible name.
  • a334944c0 closes the mock HTTP client and event loop and restores the process-wide client after every test.
  • d1981fb6f aligns the new regression tests with repository formatting rules.

Post-push review fixes

  • dd97f4494 keeps Ollama GPT-OSS reasoning enabled and limits its effort levels to low, medium, and high, matching the Ollama thinking documentation.
  • 36f0e7882 gates Deep Research reasoning fields on the selected model's reasoning support. Unmarked Ollama models no longer inherit stale enableThinking state.
  • 6d7963e5c matches Ollama reasoning model pins case-insensitively in the provider dialog, consistent with persistence and runtime matching.
  • 5962abbeb resets reasoning state when the add-provider form changes provider type, so Ollama state cannot silently mark a new vLLM server.

Verification

  • Backend payload tests: 11 passed in studio/backend/tests/test_ollama_reasoning_effort.py, with warnings promoted to errors.
  • Python lint: Ruff passed on external_provider.py and test_ollama_reasoning_effort.py.
  • Frontend focused tests: 26 passed across provider capabilities, research serialization, pin persistence, provider sync, and checkbox accessibility.
  • TypeScript: application build typecheck and test-project typecheck both passed.
  • A/B capability probe: merge base did not expose Ollama reasoning; repaired head exposed the marked model only and kept the unmarked model off.
  • Environment: macOS arm64, Python 3.12.13, Node 24.16.0.

UI evidence

Two isolated Studio installs were built from merge base 54367e591 and repaired head d1981fb6f. Chromium 151.0.7922.34 used a 1440 x 1000 viewport. The backend held the same Ollama connection and the same two model IDs on both sides.

  • Before: no Ollama Reasoning model control.
  • After: This server has reasoning models, separate deepseek-r1:8b and llama3.2:3b controls, and model-specific accessible names.

PR 9770 Ollama reasoning controls before and after

Regression risk and compatibility

  • Unmarked Ollama models still omit reasoning_effort, thinking, and chat_template_kwargs.
  • Explicit off still sends reasoning_effort: "none"; explicit on without a level still defaults to medium.
  • vLLM remains connection-wide and ignores Ollama pin lists.
  • Older stored Ollama connections retain their legacy all-model behavior. New and repaired rows use explicit per-model lists.
  • No GPU, model download, or training path is involved. A live Ollama daemon was not required because the backend test captures the exact outbound OpenAI-compatible JSON body.

Verdict

The confirmed conflicts and defects are fixed on 5962abbeb5f0b5b45c9d0074ab0df376603f7837. Codex convergence follows this comment.

@mahiatlinux

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 5962abbeb5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mahiatlinux mahiatlinux changed the title Studio: expose Thinking for Ollama and forward reasoning_effort route thinking controls to ollama Aug 27, 2026
@mahiatlinux

mahiatlinux commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Scope correction: frontend UI removed

Commit 864ab2b93 removes the frontend reasoning controls and keeps the Ollama API routing fix.

Why the UI was removed

The defect is in outbound request routing. The chat API already accepts enable_thinking and reasoning_effort, and routes/inference.py already passes both fields to ExternalProviderClient.stream_chat_completion(). Ollama was the missing provider branch: those controls reached the client but were omitted from its OpenAI-compatible request body.

A provider-dialog toggle and per-model pin list are unnecessary for that transport fix. They required users to maintain capability metadata for every Ollama model, then added browser persistence, model-sync pruning, migration behavior, case-insensitive matching, and provider-switch resets around that manual state. None of those paths are needed to route an explicit API control. They also made the frontend responsible for model capability data that can vary by Ollama version and model.

What remains

  • ExternalProviderClient maps reasoning_effort to Ollama's documented OpenAI-compatible field.
  • enable_thinking: false maps to reasoning_effort: "none".
  • enable_thinking: true without an explicit effort maps to reasoning_effort: "medium".
  • Explicit effort wins over the boolean. minimal maps to low, and xhigh maps to max.
  • Requests without either control remain unchanged.

What was removed

  • The Ollama reasoning toggle and per-model checkboxes.
  • reasoningModelIds persistence and provider-sync behavior.
  • Ollama frontend capability advertisement and composer state changes.
  • Deep Research changes that only supported the removed UI state.
  • Frontend regression tests and screenshot evidence for those removed paths.

The PR now changes only:

  • studio/backend/core/inference/external_provider.py
  • studio/backend/tests/test_ollama_reasoning_effort.py

Focused verification

  • Ollama outbound-body tests: 11 passed with warnings treated as errors.
  • Ruff passed on both changed Python files.
  • The net frontend diff against the merge base is empty.

GitHub verification

The full fork matrix also exposed two current-main failures outside this PR's files: the macOS prebuilt loads librdma.dylib, which is absent on the runner, and five route-source tests still inspect the pre-refactor body of openai_chat_completions. These were not rerun or patched into this API-only change.

This leaves the API contract small: callers choose the thinking control, and the provider client routes it to Ollama without adding frontend configuration state.

@mahiatlinux

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 864ab2b93d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mahiatlinux mahiatlinux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reviewed and fixed, LGTM. CI results

@mahiatlinux
mahiatlinux merged commit 1fe27b1 into unslothai:main Aug 27, 2026
31 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants