openclaw - ✅(Solved) Fix [Bug]: Gemma 4 models should be detected as reasoning models (Ollama think mode) [3 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#68728Fetched 2026-04-19 15:08:14
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
cross-referenced ×3referenced ×2

Fix Action

Fixed

PR fix notes

PR #68193: feat(ollama): detect Gemma 4 as reasoning model and check capabilities

Description (problem / solution / changelog)

Summary

  • Add gemma4 to the isReasoningModelHeuristic regex in all three provider locations (Ollama, self-hosted OpenAI-compat, HuggingFace) so Gemma 4 models are correctly detected as reasoning models and get think: true sent to Ollama by default
  • Enhance buildOllamaModelDefinition to also check the Ollama /api/show capabilities array for a "thinking" entry, future-proofing reasoning detection for models that report thinking support via capabilities rather than name patterns
  • Add unit tests covering gemma4 heuristic matching (positive and negative cases) and capabilities-based reasoning flag

Why this matters

Gemma 4 models (gemma4, gemma4:27b, gemma4:12b, gemma4:31b) support native thinking mode via Ollama's think parameter, but the existing heuristic (/r1|reasoning|think|reason/i) did not match "gemma4". This caused:

  1. Gemma 4 not being flagged as reasoning: true in the model definition
  2. Thinking mode not being enabled by default for Gemma 4
  3. Blank or misrouted responses in agent pipelines and benchmarks, since Gemma may put answer text in the reasoning field instead of content when thinking mode is not explicitly enabled

The message.reasoning fallback in the stream adapter (already upstream) catches the content, but without enabling thinking mode, the model behavior is suboptimal.

Changed files

FileChange
extensions/ollama/src/provider-models.tsAdd gemma4 to heuristic regex, check capabilities for "thinking"
extensions/ollama/src/provider-models.test.tsAdd tests for gemma4 detection and capabilities-based reasoning
src/plugins/provider-self-hosted-setup.tsAdd gemma4 to heuristic regex
extensions/huggingface/models.tsAdd gemma4 to heuristic includes

Code flow

flowchart TD
    A[Ollama model discovered] --> B{isReasoningModelHeuristic}
    B -->|matches r1/think/reason/gemma4| C[reasoning: true]
    B -->|no match| D{capabilities includes 'thinking'?}
    D -->|yes| C
    D -->|no| E[reasoning: false]
    C --> F[thinking mode enabled by default]
    F --> G["think: true sent to Ollama"]
    E --> H[thinking mode off by default]
sequenceDiagram
    participant User
    participant OpenClaw
    participant Ollama
    User->>OpenClaw: Chat with gemma4:27b
    OpenClaw->>OpenClaw: buildOllamaModelDefinition("gemma4:27b")
    OpenClaw->>OpenClaw: isReasoningModelHeuristic → true (matches gemma4)
    OpenClaw->>OpenClaw: Set reasoning: true → thinkingLevel: "on"
    OpenClaw->>Ollama: POST /api/chat {think: true, ...}
    Ollama->>OpenClaw: {thinking: "...", content: "answer"}
    OpenClaw->>User: Structured thinking + answer

Test plan

  • All 50 Ollama extension tests pass (provider-models, stream, index)
  • New isReasoningModelHeuristic tests verify gemma4 variants match (gemma4, gemma4:27b, gemma4:12b, gemma4:31b-q4_K_M, GEMMA4:27B)
  • New tests verify non-gemma4 models don't match (gemma:7b, gemma2:9b, gemma3:27b)
  • New tests verify capabilities-based reasoning detection
  • CI checks

🤖 Generated with Claude Code

Changed files

  • extensions/huggingface/models.ts (modified, +2/-1)
  • extensions/ollama/src/provider-models.test.ts (modified, +48/-0)
  • extensions/ollama/src/provider-models.ts (modified, +3/-2)
  • scripts/check-no-raw-channel-fetch.mjs (modified, +3/-3)
  • src/plugins/provider-self-hosted-setup.ts (modified, +1/-1)

PR #68740: Ollama/models: detect Gemma 4 and thinking capability as reasoning

Description (problem / solution / changelog)

Summary

  • Problem: gemma4 tags in Ollama (e.g. gemma4, gemma4:12b, gemma4:27b, gemma4:31b) were not detected as reasoning models, so the Ollama thinking-mode plumbing and reasoning-aware provider defaults silently fell back to non-reasoning behavior. Same gap hit any model whose /api/show reported capabilities: ["thinking", ...] when the id did not match the pre-existing heuristic.
  • Why it matters: gemma4 is the shipped default Ollama model (extensions/ollama/src/defaults.ts), so the miss lands on the most common OpenClaw + Ollama path for new users. Agent pipelines that branch on the reasoning flag (defaults, compat behavior, downstream benchmarks) can misroute thinking/reasoning emissions. Fixes #68728.
  • What changed: buildOllamaModelDefinition now marks a model as reasoning: true when /api/show capabilities include "thinking" OR when the id-based heuristic matches. The heuristic regex also picks up gemma4 as an explicit offline fallback, mirroring the deepseek-r1 pattern.
  • What did NOT change (scope boundary): No changes to OLLAMA_DEFAULT_MODEL, the /api/show request shape, context-window detection, vision detection, Ollama streaming, provider auth, Hugging Face catalog, self-hosted OpenAI-compat catalog, or any security/SSRF posture. Heuristic wording in src/plugins/provider-self-hosted-setup.ts and extensions/huggingface/models.ts is intentionally left alone: this PR is scoped to Ollama, which is where the actual user impact lives.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #68728
  • Related: the existing Google-provider docs note (docs/providers/google.md) already documents Gemma 4 as thinking-capable; this brings the Ollama path in line with that behavior.
  • This PR fixes a bug or regression

Root Cause (if applicable)

  • Root cause: extensions/ollama/src/provider-models.ts::buildOllamaModelDefinition derived reasoning purely from a model-id regex (/r1|reasoning|think|reason/i) that does not match gemma4. Even though capabilities from /api/show was already being fetched and threaded into buildOllamaModelDefinition, only the "vision" capability was consumed — a "thinking" capability was silently dropped.
  • Missing detection / guardrail: no regression test asserted the reasoning flag on the discovery path for thinking-capable tags; existing tests only checked contextWindow, vision, and basic shape.
  • Contributing context: gemma4 is the default Ollama model in this repo, so the miss is the common path, not an edge case.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
  • Target test or file: extensions/ollama/src/provider-models.test.ts.
  • Scenario the test should lock in: buildOllamaModelDefinition("gemma4"), gemma4:12b, and gemma4:27b set reasoning: true; a thinking-capable /api/show capability set also produces reasoning: true; non-reasoning models (llama3:8b, glm-5.1:cloud with ["completion", "tools"]) stay reasoning: false; vision+thinking combined still produces correct input + reasoning.
  • Why this is the smallest reliable guardrail: it directly exercises the function that the Ollama provider discovery and setup paths both call (extensions/ollama/provider-discovery.ts, extensions/ollama/src/setup.ts), at the exact seam where the capability-to-flag mapping lives. It does not require spinning up a real Ollama server or mocking the full discovery pipeline.
  • Existing test that already covers this: none — prior tests asserted contextWindow and vision branches, not reasoning.
  • If no new test is added, why not: N/A — tests are added.

User-visible / Behavior Changes

  • Fresh Ollama installs with gemma4 (the default) now see reasoning: true on the discovered model entry, so downstream behavior that already branches on the reasoning flag kicks in instead of the non-reasoning fallback.
  • Any Ollama model that reports capabilities: ["thinking", ...] via /api/show (present and future) is marked as reasoning regardless of its name.
  • No change for models that were already detected (e.g. deepseek-r1:*, qwq-named tags via existing reason substring match). No change for non-thinking models.

Diagram (if applicable)

N/A

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No
  • Runtime controls explicitly unchanged: SSRF policy on /api/show + /api/tags (buildOllamaBaseUrlSsrFPolicy, fetchWithSsrFGuard) untouched; OLLAMA_LOCAL_AUTH_MARKER semantics untouched; no trust/scope/auth-profile code touched; no tool-policy or approval surfaces touched; no prompt-text-based branching introduced. The reasoning flag is a capability hint for provider wiring, not a policy gate — it does not relax or add any runtime-enforced control.

Repro + Verification

Environment

  • OS: macOS (development host)
  • Runtime/container: Node 22 / pnpm
  • Model/provider: Ollama (local /api/tags + /api/show simulated via the mocked fetch in the ollama test lane)
  • Integration/channel (if any): N/A
  • Relevant config (redacted): default Ollama provider config, OLLAMA_DEFAULT_MODEL = "gemma4"

Steps

  1. pnpm test extensions/ollama/src/provider-models.test.ts
  2. pnpm test:extension ollama

Expected

  • New assertions pass: gemma4/gemma4:12b/gemma4:27breasoning: true; capability ["thinking", ...]reasoning: true; llama3:8b + capability ["completion","tools"]reasoning: false.
  • Existing buildOllamaModelDefinition / enrichOllamaModelsWithContext / vision / context-window assertions unchanged.

Actual

  • extensions/ollama/src/provider-models.test.ts: 11/11 pass (8 prior + 3 new cases).
  • pnpm test:extension ollama: 132/132 pass across 11 test files.

Evidence

  • Failing test/log before + passing after

Scoped tests run locally:

pnpm test extensions/ollama/src/provider-models.test.ts
  Test Files  1 passed (1)
       Tests  11 passed (11)

pnpm test:extension ollama
  Test Files  11 passed (11)
       Tests  132 passed (132)

Sanity checks also run locally:

  • pnpm format:check: clean.
  • ReadLints on touched files (extensions/ollama/src/provider-models.ts, extensions/ollama/src/provider-models.test.ts, docs/providers/ollama.md, CHANGELOG.md): no lint errors.
  • pnpm tsgo:extensions / pnpm lint: fail, but only inside extensions/qa-lab/src/providers/aimock/server.ts (Cannot find module '@copilotkit/aimock' and downstream any/no-redundant-type-constituents). Reproduced on a clean origin/main with this branch's changes stashed; unrelated to this PR and outside the touched surface. Per CONTRIBUTING.md, test/CI-only PRs chasing failures already red on main should not be opened, so I did not widen scope.

Human Verification (required)

  • Verified scenarios:
    • buildOllamaModelDefinition("gemma4"), gemma4:12b, gemma4:27breasoning: true.
    • Capability-only path: id that would otherwise be non-reasoning + capabilities: ["thinking", "completion"]reasoning: true.
    • Vision + thinking combined: input = ["text", "image"] and reasoning: true.
    • Negative path: llama3:8b and glm-5.1:cloud with ["completion", "tools"]reasoning: false.
    • Reviewed extensions/ollama/provider-discovery.ts and extensions/ollama/src/setup.ts call sites: both already pass capabilities through buildOllamaModelDefinition, so the new code path is covered on live discovery and on setup-time pulls without additional plumbing.
    • Reviewed extensions/ollama/api.ts: isReasoningModelHeuristic is part of the public ollama barrel, so the regex change is a superset of the old behavior and does not narrow any existing detection.
  • Edge cases checked: capability array undefined, empty array, array without "thinking", array with both "vision" and "thinking"; id regex does not accidentally match unrelated gemma* tags (only gemma4).
  • What I did not verify: a real live Ollama daemon running gemma4:12b (harness uses the in-repo mock for /api/show); no changes to live-test or Docker lanes.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes — a previously reasoning: false model becoming reasoning: true is a strict capability widening; the reasoning flag only adds behavior on top.
  • Config/env changes? No
  • Migration needed? No

Risks and Mitigations

  • Risk: a caller has a hard-coded assumption that gemma4's discovered entry has reasoning: false.
    • Mitigation: searched for hardcoded gemma4 + reasoning coupling in the repo; none found. Existing Ollama fixtures use deepseek-r1 / qwen3 / llama3 / kimi/glm for this axis, so the flip does not churn any snapshot/assertion.
  • Risk: false positives on model ids that happen to contain the substring gemma4.
    • Mitigation: gemma4 is a specific substring; no existing tag or fixture in-repo collides. If a future Google-hosted non-thinking gemma4-named variant ever shows up on Ollama, the capability path already takes priority and can still over-ride via explicit model config.

AI-assisted: Cursor agent; fully tested (scoped unit + ollama extension lane, plus the targeted tsgo/format/lint checks listed above).

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • docs/providers/ollama.md (modified, +3/-2)
  • extensions/ollama/src/provider-models.test.ts (modified, +30/-0)
  • extensions/ollama/src/provider-models.ts (modified, +3/-2)

PR #68762: fix: detect Gemma 4 models as reasoning models

Description (problem / solution / changelog)

Problem

Closes #68728

Gemma 4 models (e.g. gemma4:12b, gemma4:27b) support native thinking mode in Ollama, but isReasoningModelHeuristic() does not match gemma4 model IDs. The existing pattern /r1|reasoning|think|reason/i only catches models with those keywords in the ID.

This means Gemma 4 models are created without reasoning: true, preventing Ollama think mode from activating.

Fix

Add gemma[_-]?4 to the reasoning model heuristic pattern in all three locations where it is defined:

  1. extensions/ollama/src/provider-models.ts — Ollama provider
  2. extensions/huggingface/models.ts — HuggingFace provider
  3. src/plugins/provider-self-hosted-setup.ts — Generic self-hosted setup

The pattern gemma[_-]?4 matches common formats:

  • gemma4:12b, gemma4:27b (Ollama tags)
  • gemma-4-12b-it (HuggingFace model IDs)

Without false-positiveing on gemma2, gemma3, or gemma-2b.

Testing

# Before: false (not detected as reasoning)
isReasoningModelHeuristic("gemma4:12b")

# After: true (correctly detected)
isReasoningModelHeuristic("gemma4:12b")

Impact

  • 3 files changed, 4 insertions(+), 3 deletions(-)
  • Only affects model detection heuristic — no runtime logic changes

Changed files

  • extensions/huggingface/models.ts (modified, +2/-1)
  • extensions/ollama/src/provider-models.ts (modified, +1/-1)
  • src/plugins/provider-self-hosted-setup.ts (modified, +1/-1)
RAW_BUFFERClick to expand / collapse

Gemma 4 models (e.g. gemma4, gemma4:12b, gemma4:27b, gemma4:31b) support Ollama native thinking mode via the think parameter and may emit answer text in the thinking/reasoning fields.

OpenClaw currently infers whether a model is a “reasoning/thinking” model via isReasoningModelHeuristic, but upstream main does not match gemma4 (regex is /r1|reasoning|think|reason/i). This means Gemma 4 is not flagged as reasoning: true, and downstream defaults / compatibility behavior can be suboptimal (including blank or misrouted responses in some agent pipelines/benchmarks).

Proposed fix (already implemented + unit-tested): PR #68193 https://github.com/openclaw/openclaw/pull/68193

PR summary:

  • Add gemma4 to the heuristic in Ollama + HF + self-hosted setup.
  • Also detect thinking support via Ollama /api/show capabilities (future-proofing).
  • Add unit tests (gemma4 positive + negative cases).

If maintainers prefer, we can scope the fix to Ollama only, but HF + self-hosted are currently using the same heuristic pattern.

extent analysis

TL;DR

The proposed fix involves updating the isReasoningModelHeuristic to include gemma4 models, which can be achieved by merging PR #68193.

Guidance

  • Review PR #68193 to understand the changes and unit tests added for gemma4 models.
  • Consider the implications of scoping the fix to Ollama only versus applying it to HF and self-hosted setups as well.
  • Verify that the updated heuristic correctly identifies gemma4 models as reasoning models.
  • Test the changes with both positive and negative cases for gemma4 models to ensure compatibility and correctness.

Example

No code snippet is provided as the issue references a specific PR with implemented changes.

Notes

The fix may have different implications depending on the specific setup (Ollama, HF, or self-hosted), and maintainers should consider these factors when deciding how to proceed.

Recommendation

Apply the workaround by merging PR #68193, as it provides a well-tested solution that updates the heuristic to correctly identify gemma4 models and includes future-proofing via Ollama /api/show capabilities detection.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix [Bug]: Gemma 4 models should be detected as reasoning models (Ollama think mode) [3 pull requests, 1 participants]