Skip to content

fix(ollama): release failed discovery bodies - #109967

Merged
steipete merged 3 commits into
openclaw:mainfrom
RileyJJY:jjy/fix/ollama-provider-models-body
Jul 28, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
RileyJJY:jjy/fix/ollama-provider-models-body

Conversation

@RileyJJY

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Ollama model discovery could leave non-OK /api/tags or /api/show response bodies open while falling back to empty discovery results.

Why This Change Was Made

The discovery fallback behavior is unchanged: failed tag listing still returns an empty reachable model list, and failed show metadata still returns no metadata. Those fallback branches now cancel any response body before returning.

User Impact

Ollama users keep the same fail-soft model discovery behavior while OpenClaw releases failed discovery response streams promptly.

Evidence

  • Real call chain loopback: ./node_modules/.bin/tsx proof-ollama-provider-models.ts started a localhost Ollama-style HTTP server, exercised /api/tags and /api/show 503 fallback responses, and used 200 JSON negative-control responses to verify successful discovery still works.
  • node scripts/run-vitest.mjs extensions/ollama/src/provider-models.test.ts -- -t "cancels non-OK discovery response bodies|fails soft and stops reading"
  • node scripts/run-vitest.mjs extensions/ollama/src/provider-models.test.ts
$ ./node_modules/.bin/tsx proof-ollama-provider-models.ts
tags-fallback={"reachable":true,"models":[]}
tags-body-closed=true
show-fallback={}
show-body-closed=true
tags-success-count=1
show-success-context=32768
proof-ollama-provider-models.ts
import http from "node:http";
import {
  fetchOllamaModels,
  queryOllamaModelShowInfo,
} from "./extensions/ollama/src/provider-models.ts";

let tagsClosed = false;
let showClosed = false;
let mode: "tags-fail" | "show-fail" | "success" = "tags-fail";

const server = http.createServer((req, res) => {
  if (mode === "tags-fail" && req.url === "/api/tags") {
    res.writeHead(503, { "content-type": "text/plain" });
    res.write("tags unavailable");
    req.socket.on("close", () => {
      tagsClosed = true;
    });
    return;
  }
  if (mode === "show-fail" && req.url === "/api/show") {
    res.writeHead(503, { "content-type": "text/plain" });
    res.write("show unavailable");
    req.socket.on("close", () => {
      showClosed = true;
    });
    return;
  }
  if (mode === "success" && req.url === "/api/tags") {
    res.writeHead(200, { "content-type": "application/json" });
    res.end(JSON.stringify({ models: [{ name: "llama3:8b" }] }));
    return;
  }
  if (mode === "success" && req.url === "/api/show") {
    res.writeHead(200, { "content-type": "application/json" });
    res.end(JSON.stringify({ model_info: { "llama.context_length": 32768 } }));
    return;
  }
  res.writeHead(404, { "content-type": "text/plain" });
  res.end("unexpected");
});

await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
const address = server.address();
if (!address || typeof address === "string") {
  throw new Error("expected localhost TCP server address");
}
const baseUrl = `http://127.0.0.1:${address.port}`;

try {
  const tagsFallback = await fetchOllamaModels(baseUrl);
  await new Promise((resolve) => setTimeout(resolve, 0));
  console.log(`tags-fallback=${JSON.stringify(tagsFallback)}`);
  console.log(`tags-body-closed=${tagsClosed}`);

  mode = "show-fail";
  const showFallback = await queryOllamaModelShowInfo(baseUrl, "llama3:8b");
  await new Promise((resolve) => setTimeout(resolve, 0));
  console.log(`show-fallback=${JSON.stringify(showFallback)}`);
  console.log(`show-body-closed=${showClosed}`);

  mode = "success";
  const tagsSuccess = await fetchOllamaModels(baseUrl);
  const showSuccess = await queryOllamaModelShowInfo(baseUrl, "llama3:8b");
  console.log(`tags-success-count=${tagsSuccess.models.length}`);
  console.log(`show-success-context=${showSuccess.contextWindow}`);
} finally {
  await new Promise<void>((resolve, reject) =>
    server.close((error) => (error ? reject(error) : resolve())),
  );
}

AI-assisted: built with Codex

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. labels Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 27, 2026, 10:16 PM ET / July 28, 2026, 02:16 UTC.

ClawSweeper review

What this changes

The Ollama provider cancels non-successful model-discovery response streams before returning its existing empty metadata or model-list fallback values, with regression tests for stream cancellation and real socket closure.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

This PR remains necessary: current main still returns the existing fail-soft Ollama discovery fallbacks without cancelling non-OK /api/show or /api/tags bodies. The branch adds the missing cleanup while preserving those fallbacks, has focused regression coverage and convincing loopback proof, and has no supported correctness or security finding. It is cleanly mergeable but behind main, so refresh the merge result before landing.

Priority: P2
Reviewed head: cf5dee97451375db802bb1cf96212433baef3292

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving repair with real after-fix proof and targeted coverage; only merge-result refresh remains before landing.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body includes after-fix localhost HTTP-server output showing both failed discovery sockets close and successful 200 discovery still works; it contains no private endpoint or credential material.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body includes after-fix localhost HTTP-server output showing both failed discovery sockets close and successful 200 discovery still works; it contains no private endpoint or credential material.
Evidence reviewed 4 items Current-main behavior: Current main returns {} for a non-OK /api/show response and { reachable: true, models: [] } for a non-OK /api/tags response; neither branch consumes or cancels the response body, so the reported lifecycle gap remains present.
Focused implementation and tests: The PR adds awaited best-effort response.body?.cancel() calls only on the two non-OK fallback branches, plus stream-cancellation and real localhost socket-close coverage while retaining successful JSON discovery controls.
Real behavior proof: The PR body records a real localhost HTTP-server run covering 503 /api/tags and /api/show responses, observes both sockets close, and confirms successful 200 discovery responses still parse correctly.
Findings None None.
Security None None.

How this fits together

The bundled Ollama plugin probes /api/tags to discover models and /api/show to enrich each model with context and capabilities. Those results feed provider/model selection; when Ollama replies unsuccessfully, discovery intentionally remains fail-soft so setup and model selection can continue with empty results.

flowchart LR
  A[Ollama API] --> B[Tags and show requests]
  B --> C[Ollama discovery plugin]
  C --> D{HTTP response OK?}
  D -->|Yes| E[Parse model metadata]
  D -->|No| F[Cancel response body]
  E --> G[Provider model catalog]
  F --> H[Existing empty fallback]
  H --> G
Loading

Before merge

  • Resolve merge risk (P1) - The branch is behind current main. Refresh the merge result and rerun the focused Ollama discovery regression test on the landing head so the reviewed cleanup is preserved.
Agent review details

Security

None.

PR surface

Source +2, Tests +164. Total +166 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 0 +2
Tests 1 164 0 +164
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 166 0 +166

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Rebase or merge current main into this focused PR, retain the two non-OK body-cancellation branches and their regression coverage, then land the refreshed head.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Rebase or merge current main into this focused PR, retain the two non-OK body-cancellation branches and their regression coverage, then land the refreshed head.

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

Yes. The branch supplies a concrete localhost HTTP-server path that returns 503 bodies from both discovery endpoints and observes whether the client closes the underlying socket; current-main source also directly shows the two unconsumed non-OK branches.

Is this the best way to solve the issue?

Yes. Cancelling only the unconsumed failed response bodies at their two owner branches preserves the established fail-soft discovery contract and avoids adding configuration, fallback changes, or a competing transport layer.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded Ollama provider resource-lifecycle repair with limited blast radius and no evidence of an active service outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes after-fix localhost HTTP-server output showing both failed discovery sockets close and successful 200 discovery still works; it contains no private endpoint or credential material.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix localhost HTTP-server output showing both failed discovery sockets close and successful 200 discovery still works; it contains no private endpoint or credential material.

Evidence

What I checked:

  • Current-main behavior: Current main returns {} for a non-OK /api/show response and { reachable: true, models: [] } for a non-OK /api/tags response; neither branch consumes or cancels the response body, so the reported lifecycle gap remains present. (extensions/ollama/src/provider-models.ts:154, c3713317b86b)
  • Focused implementation and tests: The PR adds awaited best-effort response.body?.cancel() calls only on the two non-OK fallback branches, plus stream-cancellation and real localhost socket-close coverage while retaining successful JSON discovery controls. (extensions/ollama/src/provider-models.test.ts:456, cf5dee974513)
  • Real behavior proof: The PR body records a real localhost HTTP-server run covering 503 /api/tags and /api/show responses, observes both sockets close, and confirms successful 200 discovery responses still parse correctly. (cf5dee974513)
  • Merge state: GitHub reports the PR as mergeable but behind main; this is refresh work, not evidence that the three-way merge would remove newer main behavior. (cf5dee974513)

Likely related people:

  • steipete: Recent PR history shows steipete merged main into this branch and added the socket-closure proof commit, indicating direct involvement in validating the current Ollama discovery boundary. (role: recent area contributor and reviewer; confidence: medium; commits: 67c3dcd3dd41, cf5dee974513; files: extensions/ollama/src/provider-models.ts, extensions/ollama/src/provider-models.test.ts)

Rank-up moves

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

  • Refresh the branch against current main and rerun the focused Ollama discovery test on the resulting landing head.

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 (5 earlier review cycles)
  • reviewed 2026-07-17T12:11:21.171Z sha 2eae92726cd047f4581c3c6fa15ec93c9bc4dad4 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-17T23:41:31.308Z sha dc680181f8de5114e485fd85d70d1a007e48c143 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-20T06:53:20.045Z sha b9a38a1c5343e78afec81a334b9092b96bba7882 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-25T19:45:40.789Z sha e4fa311 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-28T01:18:02.340Z sha 67c3dcd :: needs maintainer review before merge. :: none

@RileyJJY
RileyJJY force-pushed the jjy/fix/ollama-provider-models-body branch 3 times, most recently from b9a38a1 to d22617f Compare July 23, 2026 00:20
@steipete
steipete merged commit 6de4b47 into openclaw:main Jul 28, 2026
88 of 90 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 28, 2026
* fix(ollama): release failed discovery bodies

* test(ollama): prove failed discovery sockets close

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: ollama P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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