Skip to content

improve(ollama): cover literal fenced command replies - #166561

Merged
steipete merged 7 commits into
openclaw:mainfrom
67-luck:67-luck/ollama-fenced-tool-call-diagnostic
Oct 14, 2026
Merged

steipete merged 7 commits into
openclaw:mainfrom
67-luck:67-luck/ollama-fenced-tool-call-diagnostic

Conversation

@67-luck

@67-luck 67-luck commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Related: #165787

What Problem This Solves

Protects Ollama's existing behavior of returning fenced command-looking prose as literal assistant text, including the reported PowerShell exec(...) shape.

User Impact

There is no runtime behavior change. Fenced Markdown remains visible text and is never converted into executable tool calls. This test does not fix or close the unresolved Windows/Qwen execution report in #165787.

Why This Change Was Made

The earlier fatal diagnostic and prompt-keyword heuristics were removed. This PR now only tests the native Ollama stream boundary: tool availability must not turn a fenced example into a call or provider error. The test uses typed messages/schema, a synthetic path, exact visible content, and normal completion. It continues @67-luck's work and preserves their commits.

Production changes: 0 lines. No configuration, prompt, dependency-version, or migration changes.

Evidence

macOS main baseline through pnpm openclaw ... agent, an isolated Gateway, and a native Ollama fixture returned the fenced response literally, with successfulToolNames: [], terminal disposition visible, and no marker created (8.93s). A separately structured native exec call ran (10.19s); real Ollama qwen3:8b returned the requested control text (14.91s). This did not reproduce the reporter's NO_REPLY symptom and is not Windows or Telegram validation.

Focused native-stream and real-HTTP transport suites: 49 tests passed in 235.60s including shared fixture preparation. The new PowerShell case asserts the complete text event sequence, exact literal content, normal stop, and no error/tool events. Scoped test types passed in 13.74s. This is preservation coverage for existing behavior, not a newly fixed production defect.

The final diff is +29 test lines and zero production lines. Formatting, whitespace checks, and all seven required baseline ratchets passed. Codex autoreview of cebf9f70be4f3a79a121c639a2b7c3ad8453959e: no actionable P0–P2 findings.

Scoped type-aware lint passed (764.01s, dominated by plugin SDK declaration preparation). The first attempt hit that preparation step's 300s deadline; the retry used the tool's supported extended preparation budget. No test timeout, rule, or assertion was relaxed.

Exact-head CI run 38509620221 passed, including openclaw/ci-gate. ClawSweeper reviewed cebf9f70be4f3a79a121c639a2b7c3ad8453959e with no code findings; its remaining hold requested current-head Gateway evidence.

Reviewed-head macOS Gateway proof is now complete. Built with pnpm build qaRuntime (938.34s wall), then started an isolated pnpm openclaw --profile text-normalize-166561 gateway run and exercised /v1/chat/completions through the normal agent path and native Ollama adapter:

Control Result Wall time
Native response containing the complete PowerShell fence, with exec available HTTP 200; exact literal content; normal stop; no command marker created 23.31s
Separately structured native exec call HTTP 200; normal stop; freshly cleared marker recreated with expected contents 4.69s
Real Ollama qwen3:8b inference, with fixture mode disabled HTTP 200; normalization-live-ok 23.64s

The fence/structured cases are deterministic provider-boundary controls through the built Gateway; the Qwen case is live local inference. These establish macOS Gateway behavior, not Windows, Telegram, or the reporter's original model-output cause. ClawSweeper's last reviewed-head comment predates these new proof results and contains no code finding.

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Adds an Ollama stream test confirming that fenced PowerShell command text remains a normal, literal assistant reply.

Example: Ollama returns a PowerShell fence containing exec(command="echo hello") while exec is available.

  • Before: The response remains literal assistant text, without executing the command.
  • After: The behavior is unchanged and explicitly protected by the added test.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused, correct preservation coverage with matching reviewed-head Gateway results and successful exact-head CI.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The updated body records reviewed-head macOS Gateway results through /v1/chat/completions and the native Ollama adapter: literal PowerShell fence, normal stop, no execution marker, and a structured-exec control that creates the marker; this resolves the previous head-attribution gap within the retained test-only scope.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Test only · Worth it: Yes
User problem: Command-looking fenced replies must remain visible assistant text without becoming provider failures or executable calls.
Reason: The narrow test protects the reported syntax and follows the written maintainer decision without claiming to resolve the linked execution report.

Merge readiness

✅ Ready for maintainer review

This PR provides useful preservation coverage consistent with the maintainer’s fenced-Markdown decision; no actionable code findings remain.

Priority: P3
Reviewed head: cebf9f70be4f3a79a121c639a2b7c3ad8453959e

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Ollama plugin converts native provider responses into assistant stream events; shared compatibility handling protects Markdown while recognizing supported textual tool-call formats.

flowchart LR
  A[Agent request and tools] --> B[Ollama plugin]
  B --> C[Native Ollama response]
  C --> D[Stream compatibility handling]
  D --> E[Literal assistant text]
  D --> F[Structured tool events]
Loading

Technical review

Best possible solution:

Retain the focused preservation test while investigating the unresolved Windows/Qwen execution failure separately.

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

This PR preserves existing behavior rather than fixing a reproduced defect; the supplied Gateway controls establish literal fenced output but do not reproduce the original Windows NO_REPLY symptom.

Is this the best way to solve the issue?

The focused native-stream test protects the reported PowerShell shape without introducing intent heuristics, fatal diagnostics, or executable interpretation of Markdown.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against eda41b03a1a0.

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Verified introduced change: The pinned introduction diff adds only the TypeBox import and a preservation test asserting exact fenced content, normal completion, and an event sequence without errors or tool calls. (extensions/ollama/src/stream.test.ts:494, cebf9f70be4f)
  • Existing production contract: Current main composes the native stream with shared plain-text compatibility handling, whose Markdown protected ranges preserve fenced content; existing real-HTTP coverage exercises fenced bracketed calls. (extensions/ollama/src/stream.runtime.ts:913, eda41b03a1a0)
  • Recorded maintainer decision: obviyus’s investigation explicitly rejects executing fenced Markdown and records working structured execution: improve(ollama): cover literal fenced command replies #166561 (comment).
  • Updated reviewed-head Gateway evidence: The complete current body records macOS Gateway requests through /v1/chat/completions on the reviewed head: literal fence returned with HTTP 200 and normal stop, no command marker, successful structured-exec control, and live Qwen control output normalization-live-ok. (cebf9f70be4f)
  • Exact-head CI: CI run 38509620221 completed successfully for the reviewed SHA, and the paginated check-run read confirms openclaw/ci-gate succeeded. (cebf9f70be4f)
  • Related work addresses a different failure: fix(ollama): tool calls fail with Tool Search enabled #167933 merged a tool-name collision repair; its body and the linked issue discussion explicitly distinguish that failure from fenced PowerShell output and leave the Windows report unresolved. (8899f3b8dae5)

PR surface

Tests +29. Total +29 across 1 file. Added test files: 0.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P3: This is focused test coverage preserving existing behavior, with no runtime change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (7 earlier review cycles)
  • reviewed 2026-10-07T10:58:09.248Z sha 48010f2 :: needs real behavior proof before merge. :: [P2] Preserve literal fenced tool-call examples | [P2] Keep token-limit completion authoritative
  • reviewed 2026-10-07T11:57:23.497Z sha 447440d :: needs real behavior proof before merge. :: [P1] Preserve literal fenced tool-call examples | [P2] Keep token-limit completion authoritative
  • reviewed 2026-10-09T09:24:34.085Z sha b2addd2 :: needs real behavior proof before merge. :: [P1] [P1] Preserve literal replies without guessing intent from keywords
  • reviewed 2026-10-13T01:46:39.242Z sha eb7e2da :: needs real behavior proof before merge. :: [P2] Align the remaining test with the removed diagnostic
  • reviewed 2026-10-13T01:55:23.967Z sha a045320 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T02:02:14.880Z sha a045320 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-14T04:12:59.447Z sha cebf9f7 :: needs real behavior proof before merge. :: none

Reviewed October 14, 2026, 12:31 AM ET / 04:31 UTC (Revision 8).

@obviyus

obviyus commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

Maintainer investigation: this PR cannot be treated as a tool-execution fix for #165787.

I built current main 424b6b1b5af1a6a4e8921093ca2909ccf741beeb in an isolated Node 24 Docker container, started its Gateway, configured the native Ollama provider against a local HTTP mock, and drove actual openclaw agent turns through that Gateway with tools.profile: full.

Observed results:

Native Ollama response Gateway agent result
Complete PowerShell fence containing exec(command="echo hello", title="Echo command", workdir="<isolated workspace>") Literal fenced text returned; successfulToolNames: []; terminal disposition visible
Same response, fresh-session retry Same result
Ordinary text Normal text reply. returned unchanged
Structured message.tool_calls invoking exec with echo hello Command executed; successfulToolNames: ["exec"]; subsequent reply Tool ran: hello returned

Thus the non-execution of fenced text is observable, but the reported NO_REPLY outcome does not reproduce in these two current-main turns. This fixture exercises the reported output shape, not a live Windows/Qwen model; it does not establish why the reporter's model produced that shape.

Decision: do not convert fenced Markdown into executable tool calls in this PR. That changes the existing protected-Markdown contract: the transport regression at extensions/ollama/src/stream-plain-text-tool-call.transport.test.ts:162-178 deliberately preserves tool-looking fenced examples. Structured native tool execution already works in the same built Gateway and configuration.

At head 447440d97d8754e3ef30d8a6b9c1b84b13955e4e, fenced-tool-call-diagnostic.ts:8-10 also explicitly declares diagnostic-only behavior, and stream.runtime.ts:1174-1180 throws rather than executing anything. The outstanding literal-example and length-terminal findings remain unresolved; the candidate was not changed or presented as passing runtime proof.

The remaining design question is whether and where to expose a non-fatal unsupported-output diagnostic while preserving requested literal examples and authoritative length completions. A fatal syntax-only detector cannot distinguish those examples from failed invocation intent. Resolving that diagnostic product contract is separate from repairing a demonstrated native adapter defect; no evidence here justifies changing fenced-text execution semantics.

@67-luck

67-luck commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Updated in b2addd2: fenced diagnostics now skip authoritative done_reason=length terminals and preserve explicit literal/example requests, while still reporting likely unintended fenced tool calls. @clawsweeper re-review

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 9, 2026
@67-luck

67-luck commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

修订已推送:eb7e2da5。移除了基于 prompt 关键词的意图猜测和致命 fenced-tool-call 诊断,删除相关诊断模块;保留文本原样返回与 done_reason=length 的终止处理。这样不会把用户要求原样展示的 fenced 内容误报为 provider failure。请重新评审。

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Oct 13, 2026
@67-luck

67-luck commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

CI 暴露了旧测试仍期待 fatal diagnostic;已在 a045320 更新回归测试,改为断言 fenced PowerShell 文本原样作为 assistant text 返回、stop reason 为 stop,且不产生 error。

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. and removed P2 Normal backlog priority with limited blast radius. labels Oct 13, 2026
@steipete steipete changed the title fix(ollama): surface fenced text tool-call failures improve(ollama): cover literal fenced command replies Oct 14, 2026
@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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 14, 2026
@steipete
steipete merged commit 84658f9 into openclaw:main Oct 14, 2026
117 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

vincentkoc added a commit that referenced this pull request Oct 14, 2026
* commit '98116a50c5e3191283f12ee210aa774273f2b8fc': (4815 commits)
  chore(ui): refresh control ui locales (#171839)
  fix(gateway): server tests time out when a parallel shard starts cold (#171289)
  fix(agentsapi): allow shared compaction tuning in hosted sessions (#171813)
  test(live): prepare runtime config for admitted fixtures
  test(update): stub state-read retry in restart module fixture
  fix(test): pnpm test fails on small cloud containers (#171732)
  fix(code-mode): recover safely from invalid wait IDs (#128886)
  test(update): load acquisition owner in restart regression
  perf(gateway): avoid full row warmup for project and catalog pickers (#171714)
  fix(telegram): voice mentions are ignored in groups when audio scope rules match on chat type (#163746)
  fix(workboard): only promote todo cards to ready (#171743)
  perf(sqlite): avoid repeated admission registry publication (#171788)
  perf: skip unused size accounting for sole session actors (#171777)
  improve(ollama): cover literal fenced command replies (#166561)
  refactor(talk): admit cross-store voice writes once (#171721)
  fix(gateway): recover a Gateway stuck in startup instead of blocking every start (#171678)
  fix(muse): offer Muse Code sign-in from Provider Access (#171790)
  perf: avoid full device lists during silent pairing (#171703)
  docs(cloud): one coherent zero-setup cloud environments guide (#171767)
  fix(test): include cloud move in sidebar action inventory
  ...
vincentkoc added a commit that referenced this pull request Oct 14, 2026
* commit '98116a50c5e3191283f12ee210aa774273f2b8fc': (185 commits)
  chore(ui): refresh control ui locales (#171839)
  fix(gateway): server tests time out when a parallel shard starts cold (#171289)
  fix(agentsapi): allow shared compaction tuning in hosted sessions (#171813)
  test(live): prepare runtime config for admitted fixtures
  test(update): stub state-read retry in restart module fixture
  fix(test): pnpm test fails on small cloud containers (#171732)
  fix(code-mode): recover safely from invalid wait IDs (#128886)
  test(update): load acquisition owner in restart regression
  perf(gateway): avoid full row warmup for project and catalog pickers (#171714)
  fix(telegram): voice mentions are ignored in groups when audio scope rules match on chat type (#163746)
  fix(workboard): only promote todo cards to ready (#171743)
  perf(sqlite): avoid repeated admission registry publication (#171788)
  perf: skip unused size accounting for sole session actors (#171777)
  improve(ollama): cover literal fenced command replies (#166561)
  refactor(talk): admit cross-store voice writes once (#171721)
  fix(gateway): recover a Gateway stuck in startup instead of blocking every start (#171678)
  fix(muse): offer Muse Code sign-in from Provider Access (#171790)
  perf: avoid full device lists during silent pairing (#171703)
  docs(cloud): one coherent zero-setup cloud environments guide (#171767)
  fix(test): include cloud move in sidebar action inventory
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 15, 2026
* fix(ollama): diagnose fenced text tool calls

* style(ollama): apply repository formatting

* fix(ollama): preserve literal fenced replies and length stops

* fix(ollama): preserve fenced text replies

* test(ollama): preserve fenced text replies

* test(ollama): keep fenced command replies literal

---------

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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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.

3 participants