Skip to content

fix(ollama): retain advertised context and tools when model inspection is unavailable - #130000

Merged
steipete merged 2 commits into
mainfrom
codex/qa-ollama-tags-context-metadata-20260826
Aug 26, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/qa-ollama-tags-context-metadata-20260826

Conversation

@steipete

@steipete steipete commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users configuring a tools-capable local Ollama model would receive no recommended default, an incorrect 128,000-token context window, or disabled tools when Ollama already advertised the correct capabilities and context in /api/tags but /api/show failed or omitted those fields.

Why This Change Was Made

Ollama's upstream list response already contains both capabilities and details.context_length; its actual list producer and upstream regression test independently confirm both facts.

Merge those authoritative list facts once in the Ollama plugin's model-metadata owner and reuse that owner for provider discovery and interactive setup. Explicit /api/show metadata remains higher authority, including an explicit empty capability array; failed inspection without advertised capabilities remains conservative, and the existing public list-response shape, authentication behavior, config surface, and storage stay unchanged. Production code shrinks by two lines (+20/-22).

User Impact

Operators can complete Ollama setup with the correct installed default, accurate native context window, and working tools even when optional per-model inspection is temporarily unavailable or incomplete. Existing older Ollama responses and explicit unsupported-model capability lists retain their previous behavior.

Evidence

  • Fail-first against unchanged production: three owner-boundary regressions failed; a model advertising details.context_length: 32768 and capabilities: ["completion", "tools"] instead configured contextWindow: 128000, disabled tools after failed inspection, and left interactive setup without a default model.
  • Fixed behavior is covered through the real interactive setup entry point and a genuine ephemeral TCP HTTP server exercising OpenClaw's real guarded /api/tags and failing /api/show requests; sibling cases cover missing show fields, stronger show metadata, explicit empty capabilities, and legacy responses.
  • node scripts/run-vitest.mjs extensions/ollama/src/provider-models.test.ts extensions/ollama/src/provider-models.ssrf.test.ts extensions/ollama/src/provider-models.preflight-timeout.test.ts extensions/ollama/src/setup-model-selection.test.ts extensions/ollama/src/setup.test.ts extensions/ollama/src/setup.cancellation.test.ts extensions/ollama/src/setup-pull.test.ts extensions/ollama/src/setup-body-release.test.ts extensions/ollama/src/discovery-shared.test.ts extensions/ollama/src/provider-base-url.test.ts extensions/ollama/provider-discovery.test.ts extensions/ollama/provider-discovery.import-guard.test.ts extensions/ollama/provider-policy-api.test.ts extensions/ollama/index.test.ts — 14 files, 355 tests passed.
  • Focused changed-file oxlint, formatting, and integrated P1 autoreview all passed.
  • Hosted CI on the first head also caught a test-fixture typing mistake (jsonResponse requires its HTTP status as a number); that fixture is corrected on the current head, and the complete 355-test suite, focused lint, and whole-branch P1 review were rerun successfully.
  • The previous hosted build-artifacts failure was an unrelated Control UI startup CSS budget overflow (46,092 B versus 46,080 B) inherited from the moving main merge-ref. The canonical fix landed separately in fix(ui): remove unused startup styles to restore css budget #130027; this branch was mechanically rebased onto that repaired commit, with git range-diff confirming both Ollama commits remained patch-identical, followed by a fresh 355-test run, focused lint, and clean whole-branch P1 review.
  • Local whole-repository extension typechecking also encounters unrelated existing dependency/type mismatches in other plugins; hosted CI isolated the Ollama fixture mismatch and it was corrected as described above. Running Ollama's own server test offline was unavailable because its Go dependencies are not cached; the exact upstream source, producer, and test are linked above. No authenticated live Ollama service was used.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 26, 2026 08:16
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 5:19 AM ET / 09:19 UTC.

ClawSweeper review

What this changes

The PR retains context-window and tool-capability metadata from Ollama’s model-list response when optional per-model inspection fails or omits those values.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

This is a coherent owner-boundary repair for a defect still present on current main; it should remain open for normal maintainer review while exact-head CI completes.

Priority: P2
Reviewed head: 296227fdfe929bd3a269ed5028159ae186faa06b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A small, coherent patch with focused owner-boundary coverage; exact-head CI and live upstream confirmation remain the only material confidence reducers.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body records an ephemeral HTTP-server regression harness, while a live Ollama-server run would be stronger evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body records an ephemeral HTTP-server regression harness, while a live Ollama-server run would be stronger evidence.
Evidence reviewed 6 items Current-main defect: Current main merges inspection results with Object.assign, so an absent or failed inspection value overwrites metadata already obtained from the model list before provider definitions are built.
Canonical metadata merge: The PR centralizes precedence: explicit inspection values win, while absent inspection context/capabilities retain advertised list values.
Both product entry paths use the repair: Provider discovery uses the shared merger during enrichment, and interactive setup uses it for both a successful incomplete inspection and a failed inspection.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/ollama/src/provider-models.test.ts extensions/ollama/src/setup-model-selection.test.ts

Result: FAIL (failed) — step 1 run node scripts/run-vitest.mjs extensions/ollama/src/provider-models.test.ts extensions/ollama/src/setup-model-selection.test.ts: previous terminal command was still running after 30 seconds: "node scripts/run-vitest.mjs extensions/ollama/src/provider-models.test.ts extensions/ollama/src/setup-model-selection.test.ts"

[test] starting test/vitest/vitest.extension-providers.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130000-PnPrP5/target

 ✓  extension-providers  extensions/ollama/src/provider-models.test.ts (44 tests) 225ms
 ✓  extension-providers  extensions/ollama/src/setup-model-selection.test.ts (12 tests) 6144ms
     ✓ selects the smallest explicitly non-thinking model during interactive setup  5999ms

 Test Files  2 passed (2)
      Tests  56 passed (56)
   Start at  09:20:19
   Duration  11.24s (transform 12.16s, setup 2.54s, import 7.32s, tests 6.37s, environment 0ms)

[test] passed 1 Vitest shard in 17.67s

Assertions:

  • FAIL expect_output: provider-models.test.ts
  • FAIL expect_output: setup-model-selection.test.ts

How this fits together

The Ollama plugin lists installed local models, optionally enriches each model through per-model inspection, then supplies the resulting definitions to provider discovery and interactive setup. Those definitions determine the recommended model, context limit, and tool availability.

flowchart LR
  A[Ollama model list] --> B[Model metadata owner]
  C[Per-model inspection] --> B
  B --> D[Metadata precedence]
  D --> E[Provider discovery]
  D --> F[Interactive setup]
  E --> G[Model definition]
  F --> G
  G --> H[Context and tool behavior]
Loading

Before merge

  • Resolve merge risk (P1) - This intentionally changes provider/setup behavior when /api/show is incomplete or unavailable; exact-head CI should finish before merge, and a live Ollama response remains stronger upstream-contract proof than the supplied local HTTP harness.
  • Complete next step (P2) - This maintainer-labeled PR has no actionable review defect; it needs exact-head CI completion and ordinary maintainer merge handling.
Agent review details

Security

None.

PR surface

Source -2, Tests +142. Total +140 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 20 22 -2
Tests 2 147 5 +142
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 167 27 +140

Review metrics

Metric Value Why it matters
Production versus test LOC production -2, tests +142 The repair consolidates precedence in one shared owner while adding focused coverage for discovery and setup.

Stored data model

Persistent data-model change detected: vector/embedding metadata: extensions/ollama/src/provider-models.test.ts, vector/embedding metadata: extensions/ollama/src/setup-model-selection.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete exact-head validation (recommended)
    Wait for the current head’s required CI, then merge with the explicit-inspection precedence and legacy-response regressions intact.

Technical review

Best possible solution:

Merge the shared metadata-precedence repair once exact-head CI is green, preserving explicit inspection values—including an explicit empty capability list—over advertised list metadata.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main’s two Object.assign paths overwrite advertised list metadata with absent inspection fields; the PR’s focused tests encode failed and incomplete inspection sequences through provider discovery and setup.

Is this the best way to solve the issue?

Yes. One metadata-owner merger covers both callers, preserves conservative behavior when no list capability exists, and keeps explicit inspection metadata authoritative.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 771d5e5393dd.

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: The PR changes model context and tool defaults for existing setups when optional inspection fails or omits metadata.

Label justifications:

  • P2: The defect affects local Ollama setup and model discovery but is bounded to one bundled provider.
  • merge-risk: 🚨 compatibility: The PR changes model context and tool defaults for existing setups when optional inspection fails or omits metadata.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body records an ephemeral HTTP-server regression harness, while a live Ollama-server run would be stronger evidence.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Blame identifies the same recent Ollama discovery work as the source of both affected merge paths. (role: feature introducer and recent area contributor; confidence: high; commits: 0dfd87ebe781, 296227fdfe92; files: extensions/ollama/src/provider-models.ts, extensions/ollama/src/setup-model-selection.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let exact-head CI complete successfully.
  • When an Ollama server is available, add a redacted run showing advertised list metadata survives a failed or incomplete inspection.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-26T08:40:02.084Z sha b4ea0efd23470dbf2c6da86cd95e6aadf4b2bc92 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/qa-ollama-tags-context-metadata-20260826 branch from b4ea0ef to 296227f Compare August 26, 2026 09:13
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Aug 26, 2026
@Yigtwxx

Yigtwxx commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Measured this at 296227fdfe929bd3a269ed5028159ae186faa06b by running the two changed owners against a real loopback HTTP server standing in for Ollama, then re-running the identical probe with only extensions/ollama/src/provider-models.ts and setup-model-selection.ts reverted to main. No vitest, no fetch stub. The single faked value is the Node-embedded SQLite version string, because local Node 22.20 trips the WAL guard on an unrelated import path.

/api/tags returns rows shaped like upstream api.ListModelResponse; /api/show answers 200 {} — the "inspection succeeded and returned nothing useful" case this PR targets.

The core repair reproduces, and it is worth more than the body claims

list row (details.context_length) main this branch
phi4-mini:3.8b (8192) contextWindow: 128000 contextWindow: 8192
deepseek-r1:8b (131072) contextWindow: 128000 contextWindow: 131072

main did not merely report a wrong-but-harmless number; it advertised 15x a small model's real window, which is the direction that actually breaks a run. The body undersells this by framing it as "an incorrect 128,000-token context window".

Three things the current tests do not pin, all downstream of list capabilities now surviving.

1. Rows whose list capabilities omit completion disappear from discovery

provider-models.ts:335-337:

const canComplete = model.capabilities?.includes("completion");
if (!canComplete && (opts?.requireCompletionCapability || model.capabilities)) {
  continue;
}

The second disjunct means "capabilities are present, so trust them". Before this PR a successful-but-empty /api/show erased capabilities, the disjunct was falsy, and the row survived. Now the list value is retained and the gate fires.

Upstream adds completion only inside readModelListGGUF (server/model_list_cache.go L615-L617), and that read is skipped entirely for remote rows (L346: cfg.RemoteHost == "" && cfg.RemoteModel == "" && modelPath != ""). A remote_host row therefore arrives carrying template-derived capabilities and no completion.

Same three rows through both branches:

row main this branch
gpt-oss:120b-cloud, remote_host set, capabilities: ["tools","thinking"] present dropped

Unless the cloud manifest's cfg.Capabilities always carries completion, this removes cloud models from discovery in exactly the degraded-inspection case the PR is about. Treating an absent completion as "unknown, keep" and excluding only on an explicit embedding would keep the intent without the new exclusion.

2. isReasoningModelHeuristic is now effectively unreachable on the discovery path

provider-models.ts:378-380:

capabilities === undefined
  ? isReasoningModelHeuristic(modelId)
  : capabilities.includes("thinking")

The heuristic now runs only when the field is entirely absent — pre-capabilities Ollama. Every modern list row carries capabilities, so any row whose capabilities lack thinking resolves reasoning: false with no name fallback. Upstream adds thinking only inside if tmpl != nil (L367-L387) and never for remote rows, so "has capabilities, no thinking" is a reachable shape rather than a hypothetical.

deepseek-r1:8b with capabilities: ["completion","tools"] and an empty /api/show: reasoning: true on main, reasoning: false on this branch. The body covers context and tools precedence but is silent on reasoning, and the live test keeps its deepseek-r1 row capability-free — the one shape that still reaches the heuristic.

3. The same ?? selects an app-guided default that violates the selector's own policy

setup-model-selection.ts:116 repeats the pattern:

reasoning: model.capabilities?.includes("thinking") ?? isReasoningModelHeuristic(model.name),

?? falls back only on undefined, so a present-but-incomplete capability list silences the heuristic here too, while selectAppGuidedOllamaModelId prefers non-reasoning models before picking the smallest.

Two tool-capable rows, both above the 16_384 floor, /api/show empty, this branch:

deepseek-r1:1.5b (1.1 GB) list capabilities app-guided default
["completion","tools"] deepseek-r1:1.5b
["completion","tools","thinking"] (control arm) llama3.1:8b (4.7 GB)

main selects nothing at all in this setup, so this is not a regression — it is the newly reachable default-selection path landing on a reasoning model precisely because the heuristic no longer runs. The control arm confirms the flip is the reasoning flag and not the harness.

Suggested shape

For 2 and 3, keep the name heuristic as an || rather than a fallback whenever the capability list came from the list response instead of an explicit inspection. That is the same rule this PR already applies to contextWindow: the list is authoritative for what it asserts, not for what it omits. showInspectionFailed already distinguishes those provenances, and mergeOllamaModelShowInfo is the natural place to record whether capabilities came from /api/show or /api/tags.

@steipete
steipete merged commit 3e9edd9 into main Aug 26, 2026
101 checks passed
@steipete
steipete deleted the codex/qa-ollama-tags-context-metadata-20260826 branch August 26, 2026 16:30
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
…n is unavailable (openclaw#130000)

* fix(ollama): preserve model metadata from discovery

* test(ollama): use numeric status in discovery fixture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: ollama maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants