Skip to content

fix(ollama): promote plain text tool calls - #87675

Merged
steipete merged 1 commit into
mainfrom
codex/ollama-plaintext-tool-compat
May 28, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/ollama-plaintext-tool-compat

Conversation

@vincentkoc

@vincentkoc vincentkoc commented May 28, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Wrap Ollama native streams with the shared plain-text tool-call compatibility wrapper.
  • Promote bracketed and Harmony-style tool-call text from small/local Ollama models into structured toolCall events when matching tools are available.
  • Add Ollama stream regressions for bracketed [tool] ... [END_TOOL_REQUEST] and commentary to=tool forms.

Verification

  • node scripts/run-vitest.mjs extensions/ollama/src/stream.test.ts src/plugin-sdk/provider-stream.test.ts src/plugin-sdk/tool-payload.test.ts - passed, 3 files / 29 tests on 5c1386e
  • ./node_modules/.bin/oxfmt --check --threads=1 extensions/ollama/src/stream.ts extensions/ollama/src/stream.test.ts - passed
  • ./node_modules/.bin/oxlint extensions/ollama/src/stream.ts extensions/ollama/src/stream.test.ts - passed
  • git diff --check - passed
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main - clean, no accepted/actionable findings
  • Previous AWS Crabbox corepack pnpm check:changed on the same patch shape: run run_63007c8cd66f, lease cbx_9c760afc22c6, slug violet-barnacle; it failed during typecheck extensions on existing current-main errors outside this branch. Current SHA was rebased afterward; fresh broad gate is queued behind the active AWS lane.

Real behavior proof

Behavior addressed: Ollama models that emit tool requests as plain assistant text can now be recovered into structured tool calls through the shared provider compatibility path.

Real environment tested: Local linked OpenClaw worktree after rebase, plus previous AWS Crabbox Linux changed gate for the same patch shape.

Exact steps or command run after this patch: The Vitest, format, lint, diff, autoreview, and previous Crabbox commands listed above.

Evidence after fix: Focused Ollama/plugin-sdk tests passed and cover both bracketed and Harmony-style plain-text tool-call promotion.

Observed result after fix: Matching plain-text tool-call payloads are emitted as toolCall events and stream completion is marked toolUse.

What was not tested: Full live Windows/Ollama UI reproduction; current rebased SHA has not yet had a fresh broad Crabbox/Testbox check:changed because another AWS gate is already active.

@clawsweeper

clawsweeper Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed May 28, 2026, 2:11 PM ET / 18:11 UTC.

Summary
The PR wraps native Ollama streams with the shared plain-text tool-call compatibility wrapper, adds Ollama regressions for bracketed and Harmony-style tool-call text, and carries a small embedded-runner timeout typing change.

PR surface: Source +9, Tests +107. Total +116 across 3 files.

Reproducibility: yes. Source inspection shows current main emits native Ollama text through the raw stream path without the plain-text wrapper, and the PR tests plus maintainer live proof exercise the missing promotion path.

Review metrics: 2 noteworthy metrics.

  • Message-delivery boundary: 1 provider stream path changed. Native Ollama output that previously reached users as text can now be reclassified as toolCall events when it matches a registered tool.
  • Conflict-bearing non-Ollama touch: 1 agent helper file touched. The extra embedded-runner timeout edit overlaps current main and is the concrete surface that needs refresh before merge.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Rebase or otherwise refresh the head so GitHub no longer reports the PR as dirty.
  • [P2] Record a successful current-head changed gate or maintainer-equivalent broad validation if required before landing.

Risk before merge

  • [P1] GitHub currently reports the PR head as dirty and not rebaseable, so the branch needs a human refresh before it can land.
  • [P1] The behavior intentionally suppresses standalone Ollama text that parses as a registered tool call and emits toolCall events instead, so maintainers should explicitly accept that message-delivery boundary.
  • [P1] Focused tests and live Ollama proof are present, but a successful broad current-head changed gate is not visible for this head.

Maintainer options:

  1. Refresh And Accept Scoped Promotion (recommended)
    Resolve the dirty merge state, then land the shared wrapper if maintainers agree that registered-tool-shaped Ollama text should become structured tool calls.
  2. Tighten Parser Boundary First
    If false-positive visible-text suppression is a concern, narrow the accepted plain-text shapes and add passthrough coverage before merge.
  3. Pause For Broader Gate
    If the maintainer team wants broad current-head validation before this message-delivery change, wait for a successful changed gate after the rebase.

Next step before merge

  • Manual review is the right lane because the remaining blockers are a dirty maintainer-labeled PR head, message-delivery boundary acceptance, and final validation policy.

Security
Cleared: No concrete security or supply-chain concern was found; the diff touches provider stream logic, colocated tests, and a type-only helper signature with no dependency, CI, credential, install, or permission changes.

Review details

Best possible solution:

Refresh the branch against current main, keep the shared-wrapper approach, and land only after maintainers accept the Ollama text-to-tool promotion boundary and record the desired current-head validation.

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

Yes. Source inspection shows current main emits native Ollama text through the raw stream path without the plain-text wrapper, and the PR tests plus maintainer live proof exercise the missing promotion path.

Is this the best way to solve the issue?

Yes, after branch refresh and maintainer acceptance. Reusing createPlainTextToolCallCompatWrapper is the narrowest maintainable fix and matches the LM Studio precedent, but the parser boundary is message-delivery-sensitive.

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against a8991e02d831.

Label changes

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. A maintainer comment provides after-fix live output from a real local Ollama 0.24.0 server showing promoted toolCall events and toolUse completion.

Label justifications:

  • P2: This is a normal provider bug fix with limited blast radius to native Ollama stream/tool-call handling.
  • merge-risk: 🚨 message-delivery: The PR intentionally changes delivery of matching Ollama assistant text from visible text into structured toolCall events.
  • 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 (live_output): A maintainer comment provides after-fix live output from a real local Ollama 0.24.0 server showing promoted toolCall events and toolUse completion.
  • proof: sufficient: Contributor real behavior proof is sufficient. A maintainer comment provides after-fix live output from a real local Ollama 0.24.0 server showing promoted toolCall events and toolUse completion.
Evidence reviewed

PR surface:

Source +9, Tests +107. Total +116 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 14 5 +9
Tests 1 108 1 +107
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 122 6 +116

What I checked:

  • Root repository policy read: The root AGENTS.md was read in full; its ClawSweeper review policy and plugin/provider message-delivery risk guidance affected this review. (AGENTS.md:1, a8991e02d831)
  • Scoped extension and SDK policy read: Scoped guidance says provider plugins should reuse existing shared SDK stream-wrapper helpers before adding provider-local compat logic; that supports the PR's shared-wrapper shape. (extensions/AGENTS.md:30, a8991e02d831)
  • Current main lacks Ollama plain-text promotion: On current main, createOllamaStreamFn is the raw native Ollama stream implementation and imports only Moonshot/payload helpers from provider-stream-shared, so standalone bracketed/Harmony tool text follows the visible text path unless Ollama returns native tool_calls. (extensions/ollama/src/stream.ts:1083, a8991e02d831)
  • PR applies shared wrapper to Ollama: At PR head 09931522e9f905e60d98afa003ffc266e108ad92, createOllamaStreamFn wraps createRawOllamaStreamFn with createPlainTextToolCallCompatWrapper. (extensions/ollama/src/stream.ts:1413, 09931522e9f9)
  • Shared wrapper behavior inspected: The shared wrapper only activates when context tools exist, buffers possible plain-text tool-call text, promotes matching parsed done messages to toolCall content and toolUse, and otherwise flushes text unchanged. (src/plugin-sdk/provider-stream-shared.ts:305, a8991e02d831)
  • Sibling provider precedent: LM Studio already wraps its local-model stream path with createPlainTextToolCallCompatWrapper, so Ollama using the same shared helper is consistent with the existing provider-family pattern. (extensions/lmstudio/src/stream.ts:181, a8991e02d831)

Likely related people:

  • steipete: Local blame ties the current Ollama stream implementation, shared plain-text wrapper, and embedded timeout helper to commits authored by Peter Steinberger in this checkout, and the live verification comment was posted by steipete. (role: recent area contributor and verifier; confidence: medium; commits: 982e2cf0efb2, df4475d232d5, 21db3ff11c4; files: extensions/ollama/src/stream.ts, src/plugin-sdk/provider-stream-shared.ts, src/agents/embedded-agent-runner/run/attempt.abort-settle-timeout.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added 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 May 28, 2026
@vincentkoc
vincentkoc force-pushed the codex/ollama-plaintext-tool-compat branch from dd7663a to 5c1386e Compare May 28, 2026 16:38
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. label May 28, 2026
@steipete
steipete force-pushed the codex/ollama-plaintext-tool-compat branch from 5c1386e to 7f1fbe7 Compare May 28, 2026 17:53
@steipete
steipete marked this pull request as ready for review May 28, 2026 18:00
@steipete

Copy link
Copy Markdown
Contributor

Maintainer verification for current head 7f1fbe701e952b568e7cdb783f69a207eb33efd9:

Behavior addressed: Ollama native streams now reuse the shared plain-text tool-call compatibility wrapper, so standalone bracketed/Harmony tool-call text can be promoted into structured toolCall events when matching tools are available.

Real environment tested: local OpenClaw source checkout against a real local Ollama server, ollama 0.24.0, model llama3.2:latest, base URL http://127.0.0.1:11434.

Exact steps or command run after this patch:

  • Rebased PR branch on current origin/main and force-pushed 7f1fbe701e952b568e7cdb783f69a207eb33efd9.
  • Ran a direct node --import tsx script importing extensions/ollama/src/stream.ts, calling createOllamaStreamFn against http://127.0.0.1:11434, with a read tool in context and a prompt requiring a bracketed [read] JSON [END_TOOL_REQUEST] block.
  • ./node_modules/.bin/oxfmt --check --threads=1 extensions/ollama/src/stream.ts extensions/ollama/src/stream.test.ts
  • ./node_modules/.bin/oxlint extensions/ollama/src/stream.ts extensions/ollama/src/stream.test.ts
  • git diff --check
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main
  • node scripts/crabbox-wrapper.mjs run --provider blacksmith-testbox --blacksmith-org openclaw --blacksmith-workflow .github/workflows/ci-check-testbox.yml --blacksmith-job check --blacksmith-ref main --idle-timeout 90m --ttl 240m --timing-json --shell -- "node scripts/run-vitest.mjs extensions/ollama/src/stream.test.ts src/plugin-sdk/provider-stream.test.ts src/plugin-sdk/tool-payload.test.ts"

Evidence after fix:

Observed result after fix: matching plain-text Ollama tool-call output is suppressed as visible assistant text and delivered as structured toolCall stream events, with final completion marked toolUse.

What was not tested: full UI/manual Windows Ollama flow. Broad Testbox check:changed was attempted on tbx_01ksqvjtdxqdmvwzztgv043etq / swift-crab and failed before this PR's tests on an unrelated current-main type error in src/agents/embedded-agent-runner/run/attempt.abort-settle-timeout.ts from df4475d; this PR diff only touches extensions/ollama/src/stream.ts and extensions/ollama/src/stream.test.ts.

@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label May 28, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 28, 2026
@steipete

Copy link
Copy Markdown
Contributor

Maintainer verification for final head 09931522e95d48ec8cfd91dcb66c46923ba4b8b1:

Behavior addressed: Ollama native streams now reuse the shared plain-text tool-call compatibility wrapper, so standalone bracketed/Harmony tool-call text can be promoted into structured toolCall events when matching tools are available.

Real environment tested: local OpenClaw source checkout against a real local Ollama server, ollama 0.24.0, model llama3.2:latest, base URL http://127.0.0.1:11434. Broad checks and focused tests also ran in Blacksmith Testbox through Crabbox.

Exact steps or command run after this patch:

  • Rebased PR branch on current origin/main, then pushed final head 09931522e95d48ec8cfd91dcb66c46923ba4b8b1.
  • Ran a direct node --import tsx script importing extensions/ollama/src/stream.ts, calling createOllamaStreamFn against http://127.0.0.1:11434, with a read tool in context and a prompt requiring a bracketed [read] JSON [END_TOOL_REQUEST] block.
  • ./node_modules/.bin/oxfmt --check --threads=1 src/agents/embedded-agent-runner/run/attempt.abort-settle-timeout.ts extensions/ollama/src/stream.ts extensions/ollama/src/stream.test.ts
  • ./node_modules/.bin/oxlint src/agents/embedded-agent-runner/run/attempt.abort-settle-timeout.ts extensions/ollama/src/stream.ts extensions/ollama/src/stream.test.ts
  • git diff --check
  • node scripts/run-tsgo.mjs -p tsconfig.extensions.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/extensions.tsbuildinfo
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main
  • node scripts/crabbox-wrapper.mjs run --provider blacksmith-testbox --blacksmith-org openclaw --blacksmith-workflow .github/workflows/ci-check-testbox.yml --blacksmith-job check --blacksmith-ref main --idle-timeout 90m --ttl 240m --timing-json --shell -- "node scripts/run-vitest.mjs extensions/ollama/src/stream.test.ts src/plugin-sdk/provider-stream.test.ts src/plugin-sdk/tool-payload.test.ts src/agents/embedded-agent-runner/run/attempt.abort-settle-timeout.test.ts"
  • node scripts/crabbox-wrapper.mjs run --provider blacksmith-testbox --blacksmith-org openclaw --blacksmith-workflow .github/workflows/ci-check-testbox.yml --blacksmith-job check --blacksmith-ref main --idle-timeout 90m --ttl 240m --timing-json --shell -- "pnpm check:changed"

Evidence after fix:

Observed result after fix: matching plain-text Ollama tool-call output is suppressed as visible assistant text and delivered as structured toolCall stream events, with final completion marked toolUse. The current-main env type blocker from df4475d is fixed by allowing the injected env shape to be partial, matching existing tests and runtime behavior.

What was not tested: full UI/manual Windows Ollama flow. Local Vitest could not run on this Mac because Vite/Rolldown failed during project config loading before test execution; the same focused tests passed in Testbox.

@steipete
steipete force-pushed the codex/ollama-plaintext-tool-compat branch from 0993152 to 44e2425 Compare May 28, 2026 18:14
@openclaw-barnacle openclaw-barnacle Bot removed the agents Agent runtime and tooling label May 28, 2026
@steipete

Copy link
Copy Markdown
Contributor

Final maintainer verification for head 44e242589b52d09aa5bb99ed5fc5cde034da0ca7:

Behavior addressed: Ollama native streams now reuse the shared plain-text tool-call compatibility wrapper, so standalone bracketed/Harmony tool-call text can be promoted into structured toolCall events when matching tools are available.

Real environment tested: local OpenClaw source checkout against a real local Ollama server, ollama 0.24.0, model llama3.2:latest, base URL http://127.0.0.1:11434. Focused tests and changed gate ran in Blacksmith Testbox through Crabbox.

Exact steps or command run after this patch:

  • Rebased on current origin/main and force-pushed final head 44e242589b52d09aa5bb99ed5fc5cde034da0ca7.
  • Ran a direct node --import tsx script importing extensions/ollama/src/stream.ts, calling createOllamaStreamFn against http://127.0.0.1:11434, with a read tool in context and a prompt requiring a bracketed [read] JSON [END_TOOL_REQUEST] block.
  • ./node_modules/.bin/oxfmt --check --threads=1 extensions/ollama/src/stream.ts extensions/ollama/src/stream.test.ts
  • ./node_modules/.bin/oxlint extensions/ollama/src/stream.ts extensions/ollama/src/stream.test.ts
  • git diff --check
  • .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main
  • node scripts/crabbox-wrapper.mjs run --provider blacksmith-testbox --blacksmith-org openclaw --blacksmith-workflow .github/workflows/ci-check-testbox.yml --blacksmith-job check --blacksmith-ref main --idle-timeout 90m --ttl 240m --timing-json --shell -- "node scripts/run-vitest.mjs extensions/ollama/src/stream.test.ts src/plugin-sdk/provider-stream.test.ts src/plugin-sdk/tool-payload.test.ts"
  • node scripts/crabbox-wrapper.mjs run --provider blacksmith-testbox --blacksmith-org openclaw --blacksmith-workflow .github/workflows/ci-check-testbox.yml --blacksmith-job check --blacksmith-ref main --idle-timeout 90m --ttl 240m --timing-json --shell -- "pnpm check:changed"

Evidence after fix:

Observed result after fix: matching plain-text Ollama tool-call output is suppressed as visible assistant text and delivered as structured toolCall stream events, with final completion marked toolUse.

What was not tested: full UI/manual Windows Ollama flow. Local Vitest could not run on this Mac because Vite/Rolldown failed during project config loading before test execution; the same focused tests passed in Testbox.

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: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. 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