Skip to content

fix(ollama): keep pre-tool narration out of channel replies - #156389

Merged
steipete merged 14 commits into
openclaw:mainfrom
Olli0103:fix/ollama-pretool-commentary-133922
Oct 9, 2026
Merged

steipete merged 14 commits into
openclaw:mainfrom
Olli0103:fix/ollama-pretool-commentary-133922

Conversation

@Olli0103

@Olli0103 Olli0103 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #133922: native Ollama can send narration before a tool call as separate durable channel replies, in addition to the final answer.

User Impact

Native Ollama now follows the existing Chat Completions pending-phase contract: durable blocks wait until the text phase is known, including with blockStreamingBreak: "text_end". Tool narration stays out of durable replies; ordinary final answers and length-limited partial output remain deliverable. Independent live previews can still update when supported and enabled. The streaming and Ollama docs describe this shared behavior.

Why This Change Was Made

The Ollama producer assigns the existing v1 textSignature commentary phase only when the completed response resolves to toolUse. The subscriber uses one pending-phase predicate for Ollama and the existing transports, preserving Anthropic's text-end behavior and Completions' reasoning handling. Ollama does not gain textPhaseRequiresTerminal; stop and length text stays unphased.

This refresh merges main c9c09fb11b08bdfbb71751e6e6b9dccfe316fab0 while preserving the contributor's commits, shrinks the native tagger to its single-text-block contract, consolidates identity coverage into the existing transport tests, and removes unrelated cron diagnostics. Thanks @Olli0103 for the original implementation and evidence; contributor credit is retained in the commits.

Final delta against merged main Added Removed Net
Production 43 13 +30
Tests 257 5 +252
Docs 19 0 +19

Production growth is reduced from +70 to +30 lines. The remaining growth implements the native signature adapter and shared phase decision; no public SDK/config/schema expansion is needed.

Evidence

Candidate: 24e2502f7b9894bb7ef7114be21aa01d0add5a88.

  • Regression controls: against pinned main's affected production modules, the subscriber test fails when narration reaches onBlockReply, and the native transport test fails because textSignature is absent. Baseline runs: 1 failed / 2 passed in 596.89s wall, and 1 failed / 36 passed in 195.65s wall. The cold subscriber run included 247.5s preparing shared worker artifacts.
  • Candidate focused proof: 60 tests across four transport/subscriber/phase/item files passed in 108.32s wall. Final standalone costs: extensions/ollama/src/stream.test.ts, 37 passed in 23.01s wall; src/agents/embedded-agent-subscribe.subscribe-embedded-agent-session.withholds-ollama-pretool-narration.test.ts, 3 passed in 14.54s wall. These cover distinct narrated rounds, unsigned text_end, exactly-once final delivery, and text-before-reasoning at both stop and length. The companion extensions/ollama/src/stream-runtime.test.ts also passes: 78 tests, 16.82s wall after the CI expectation correction below.
  • Checks: core and extension production/test types, touched-file type-aware lint, formatting, and selected remaining guards passed; the inherited dead-export failure below remains. The first aggregate run caught two missing diagnostic labels in the test-only expectDefined calls. Those are fixed; extension test types passed in 5.96s, and both changed test files were rerun. Both docs pass MDX validation. Runtime build: OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build qaRuntime, 117.63s wall. A broader declaration build was stopped; no full package/release build is claimed.
  • Review: fresh independent Codex review of the final committed patch is P0–P2 scoped-clean, with no actionable findings.
  • Historical CI investigation: the nine lazy-forwarder collision reports are fixed by main's f010fc0b579071d151e8f4e4084a40ac0b219057. The two Gateway startup failures were before Ollama execution: shared-state admission in server.sessions.abort-authorization.test.ts, and the 90s catalog startup timeout. Both files now pass locally: 9 tests, 132.36s wall. This standalone replay does not establish a root-cause fix for the historical failures or reproduce their complete shard order.
  • Inherited check failure: the dead-export scan reports the same four symbols on the recorded main-production baseline and candidate: bindCliQuestionAnswerAuthority, prepareSessionEventTargetForHost, readSessionEntryCreationTransition, and RESTART_CONTINUATION_CONTEXT_PREFIX. Their owning files are outside this patch. The baseline scan also failed (80.19s); this failure is retained, not reported green.
  • CI follow-up: run 37889227572 on the preceding head found one stale Kimi buffered-text expectation: terminal text now correctly carries textSignature. The failure reproduced locally (1 failed / 77 passed, 28.75s wall). Its strict content expectation now includes that metadata, while text/tool/event-order checks remain intact. A direct terminal assertion replaces the manual throw guard, retaining the last-event invariant with zero file growth. Final file tests, extension test types, lint, and line-cap checks pass. The original CI extension shard had 403 passed / 1 failed across 24 files, 49.14s. The separate auto-response job failed on a GitHub HTTP 500/socket error; no workflow rerun was requested.
  • CI: CI is attached to the exact updated head: preflight is running and the aggregate gate is pending. Dependency review reports success (no dependency changes require review). Per-file CI wall times are unavailable; updated-head CI cost remains pending. No manual workflow dispatch or rerun was used.

Live native Ollama and real Gateway, observed through QA channel

The real CLI/Gateway used native /api/chat at 127.0.0.1:11434, isolated state/workspace, Gateway port 19156, and QA bus port 29156. The server reported Ollama 0.40.1 at verification. QA channel is the synthetic delivery boundary. Stored messages were read through sessions.get; tool-call IDs were correlated with successful results. Deleted previews are counted separately from retained durable messages.

The qualifying comparison used identical config and prompt, qwen3:4b, block streaming on, text_end, and 4000-character min/max blocks:

Tell me in one short sentence that you are about to read the file, then use read to read NARRATION_PROBE.txt. After reading it, reply with only the file contents.

  • Before 04: 10,888 characters of unphased pre-tool text; three successful reads; three durable narration chunks plus one exact NARRATION_FINAL_133922 reply.
  • After 03: 6,176 characters of pre-tool text carrying a v1 commentary signature; four successful reads; zero durable narration messages and exactly one NARRATION_FINAL_133922 reply. One transient preview was deleted.
  • Control: OLLAMA_CONTROL_OK arrived exactly once, without tools.
  • Length: llama3.2:latest with num_predict: 32 ended with stopReason: "length" and 32 output tokens. Its unphased partial text arrived once, followed by the standard truncation warning. The model emitted an incomplete tool-shaped string instead of the requested counting text; no tool executed.

Live runtime source was 65ca775f5d8d059d8aa73921fd441bc53619ce30; subsequent changes are test-only diagnostic labels and the Kimi metadata expectation. Production bytes are identical.

All trials are reported below; invalid stimuli are not counted as narration proof. Models did not consistently follow the requested formatting or single-read intent.

Trial Model Seconds Observation
Before 01 qwen3:4b 80.037 One successful read; verbose preamble leaked; seven retained messages, including one exact fixture reply.
Before 02 llama3.2:latest 118.872 61 mixed read/skills_read calls; 25 successful results, 35 failures, then context overflow and abort. Invalid completed-answer stimulus.
Before 03 qwen3:4b 39.035 Added /no_think cue; no tool call. Invalid narration stimulus.
Before 04 qwen3:4b 39.891 Original prompt; three narration chunks and one exact final.
After 01 qwen3:4b 57.199 No tool call. Ordinary text delivered; invalid narration stimulus.
After 02 qwen3:4b 67.682 No tool call. Ordinary text delivered; invalid narration stimulus.
After 03 qwen3:4b 28.845 Commentary withheld; four successful reads; exact final once.
Control qwen3:4b 19.386 Exact tool-free reply once.
Length llama3.2:latest 10.882 Visible length-limited partial once plus warning; model task compliance failed.

The earlier Telegram Test Server evidence remains historical evidence at its recorded revision.

Live commands used

The fixture environment set OPENCLAW_STATE_DIR, OPENCLAW_CONFIG_PATH, and TMPDIR under /private/tmp/oc-lm-ollama-narration, with private QA enabled. The probe posted the quoted prompt to /v1/inbound/message, waited for its processing acknowledgment, then captured /v1/state including preview deletions.

source /private/tmp/oc-lm-ollama-narration/proof-env.sh
pnpm openclaw qa ui --embedded-gateway disabled --host 127.0.0.1 --port 29156
pnpm openclaw gateway run --port 19156 --bind loopback --raw-stream \
  --raw-stream-path /private/tmp/oc-lm-ollama-narration/raw-after.jsonl
node /private/tmp/oc-lm-ollama-narration/probe.mjs ollama-after-03
pnpm openclaw gateway call sessions.get --port 19156 --json \
  --params '{"key":"agent:main:qa-channel:direct:dm:ollama-after-03","limit":100}'

The bus and Gateway ran in separate foreground processes. Both were stopped after proof; ports were verified free.

@clawsweeper

clawsweeper Bot commented Sep 23, 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: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. 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 Sep 23, 2026
@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The branch classifies native Ollama tool narration as commentary and waits for message completion before sending durable reply blocks.

Example: Ask Ollama to read NARRATION_PROBE.txt and return its contents

  • Before: The live baseline sends three narration chunks plus NARRATION_FINAL_133922.
  • After: The live candidate sends no durable narration and delivers NARRATION_FINAL_133922 exactly once.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful, focused repair with real runtime evidence, resolved prior feedback, and no remaining actionable finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The real CLI/Gateway and native Ollama comparison exercises the changed producer and subscriber through the QA channel, showing zero durable narration and one exact final reply after the fix. Production bytes match this head; historical Telegram Test Server traces corroborate channel delivery. Existing unsigned transcripts and the optional v1 signature remain compatible without migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Native Ollama sends planning narration as separate chat messages before the final answer.
Reason: This restores the established commentary suppression contract for an affected native transport. The area contributor's repair records the buffering choice, and the reporter withdrew the unrelated NO_REPLY symptom.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main and the latest release still have the reported gap. The previous finding is resolved, and no remaining actionable defect was found.

Priority: P2
Reviewed head: 24e2502f7b9894bb7ef7114be21aa01d0add5a88

Before merge

None.

Findings

None.

Provenance

  • extensions/ollama/src/stream.runtime.ts: native assistant text construction: original intent not found (unknown: The supplied history identifies the provider-runtime move and later lazy runtime split, but searches across stream.runtime.ts, stream.ts, and ollama-stream.ts encountered unavailable older blobs before establishing the original unsigned-text introduction.)
Agent review details

How this fits together

The Ollama plugin converts native model responses into assistant messages and tool calls. The agent subscriber separates commentary and previews from durable replies sent to chat channels.

flowchart TD
  A[Native Ollama response] --> B[Ollama message adapter]
  B --> C{Completed tool use?}
  C -->|Yes| D[Text marked commentary]
  C -->|No| E[Ordinary or length-limited answer]
  D --> F[Agent reply subscriber]
  E --> F
  F --> G[Live commentary and previews]
  F --> H[Durable final channel reply]
Loading

Technical review

Best possible solution:

Use the existing commentary contract at the Ollama producer and shared subscriber, preserving ordinary answers, truncated output, and independent previews.

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

Yes, from source and recorded live comparison: unsigned native Ollama text preceding tool calls reaches durable replies on the baseline. This review did not execute a reproduction.

Is this the best way to solve the issue?

Yes. Repairing producer classification and reusing the pending-phase subscriber addresses the established contract without introducing a competing final-only configuration path.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current main still needs the repair: Current main constructs unsigned visible text before adding native tool calls; its pending-phase predicate still covers Anthropic and Chat Completions without Ollama. (extensions/ollama/src/stream.runtime.ts:663, a2a9ff2d32c7)
  • Latest release also lacks commentary tagging: The v2026.9.9 native message builder adds a plain text block without a phase signature. (extensions/ollama/src/stream.runtime.ts:728, bcfc88812a35)
  • Producer and subscriber repair: Only completed tool-use text receives the existing v1 commentary signature, with a unique identity; the shared subscriber predicate withholds unsigned Ollama text while retaining the existing Anthropic and Completions conditions. (extensions/ollama/src/stream-commentary.ts:15, 24e2502f7b98)
  • Previous finding resolved: The Kimi buffered-tool-response expectation now accepts the added signature while retaining exact visible text, tool arguments, sanitizer checks, event order, and the terminal-event assertion. Separate native transport coverage validates the signature phase and distinct identities. (extensions/ollama/src/stream-runtime.test.ts:1122, 24e2502f7b98)
  • Current production behavior exercised live: The captured PR body reports real CLI/Gateway execution with Ollama 0.40.1 and qwen3:4b through native /api/chat and the QA channel: the baseline retained three narration chunks, while the candidate retained zero and delivered NARRATION_FINAL_133922 once. Tool-free and length-limited controls remained deliverable. The proof ran at 65ca775; comparison confirms all four changed production files are identical on the reviewed head. (65ca775f5d8d)
  • Historical Telegram proof and media limitations: fix(ollama): keep pre-tool narration out of channel replies #156389 (comment) records real Telegram Test Server observations at the older revision: two successful dependent reads, zero durable narration, FINAL EMBER-A9E5D9C9B745 once, and the tool-free control 5 once. The strict checker failed on equivalent absolute path spelling. The downloaded GIF was opened locally, but its displayed initial frame alone does not establish the sequence. The manifest records an MP4 download HTTP 504 and another video's ffprobe ENOENT; the textual transport evidence remains independently usable. (61be9f0a036d)

PR surface

Source +30, Tests +252, Docs +19. Total +301 across 9 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 4 43 13 +30
Tests 3 257 5 +252
Docs 2 19 0 +19
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 319 18 +301

Review metrics

Metric Value Why it matters
Production versus test growth production +30 net lines; tests +252 net lines The production growth is bounded to the native signature adapter and shared phase predicate; the tests cover distinct transport identity and durable-delivery boundaries.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #133922
Summary: This PR is the explicit candidate repair for the canonical native Ollama narration report; the broader final-only feature request remains a separate product question.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Extra narration messages impair native Ollama conversations while ordinary final delivery generally remains available.
  • merge-risk: 🚨 compatibility: Native Ollama durable blocks now wait for message completion even with text_end; the area contributor explicitly retained and documented this timing tradeoff.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The change suppresses user-visible Telegram narration messages; the recorded Test Server evidence exercises that behavior.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (31 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-26T03:15:32.009Z sha c33eb82fbe6f40f73733c4c00d9138c817cea6d3 :: blocked before merge. :: none
  • reviewed 2026-09-26T22:33:22.659Z sha bc120af4ae6daaa770469ec8ed667000c0a26423 :: blocked before merge. :: none
  • reviewed 2026-09-26T23:22:35.043Z sha 29ae468e2d4f57f0af9fa127f38eb1573a91aad2 :: blocked before merge. :: none
  • reviewed 2026-09-27T00:36:29.272Z sha 61be9f0 :: blocked before merge. :: none
  • reviewed 2026-09-27T13:32:45.946Z sha 61be9f0 :: blocked before merge. :: none
  • reviewed 2026-09-28T16:41:18.935Z sha 55f8c99 :: blocked before merge. :: none
  • reviewed 2026-10-08T08:33:47.242Z sha 55f8c99 :: blocked before merge. :: none
  • reviewed 2026-10-09T05:45:12.166Z sha 5ccfde6 :: needs changes before merge. :: [P2] Update the native tool-text expectation for commentary signatures

Reviewed October 9, 2026, 2:05 AM ET / 06:05 UTC (Revision 32).

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M and removed size: S labels Sep 23, 2026
@Olli0103

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — both review findings are addressed on head 8eeb4ffe9b: unique commentary identities (commentary-<index>-<entropy>, mirroring the shared phase helper) with a two-tool-round test, and the native-Ollama pending-phase guard in the subscriber so early unsigned text is withheld from durable block replies. All four gates pass; the PR body carries the updated evidence and the one ask that needs repository access (the Mantis capture for real native-Ollama proof).

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. label Sep 23, 2026
@Olli0103

Copy link
Copy Markdown
Contributor Author

Both review findings are fixed on 8eeb4ffe9b — unique per-segment commentary identities plus the native-Ollama pending-phase guard — all four gates green, and the PR body carries the updated evidence.

The one open item is real-behaviour proof, which needs repository access this contributor does not have. Could a maintainer trigger the capture? The exact request:

@openclaw-mantis verify a native Ollama web UI chat with two narrated tool rounds, capture whether both distinct commentary segments remain visible once before and after reconnect, and return redacted screenshots and diagnostic logs.

We also have a local native Ollama (0.34.3, llama3.2:3b) and a source build available, so if a maintainer would rather we capture the evidence ourselves under a specified procedure, say so and we will.

@Olli0103

Copy link
Copy Markdown
Contributor Author

Real-model evidence is in — no mocks on this path.

Environment: Ollama 0.34.3 local, qwen2.5:7b (non-reasoning), native /api/chat (not /v1), sampler temperature 0 / seed 133922, head bc73c6c8b7. The live model response is fed through the branch's real buildAssistantMessage.

RAW model text      : "Let me check NOTES.md.\n"
RAW model tool_calls: [{"id":"call_j677g5sj","function":{"index":0,"name":"read","arguments":{"path":"NOTES.md"}}}]
BUILT stopReason    : toolUse
  block[0] type=text     text="Let me check NOTES.md.\n"
          textSignature={"v":1,"id":"commentary-0-cab28e3005af4f1a8331aaf6","phase":"commentary"}
  block[1] type=toolCall name=read args={"path":"NOTES.md"}

Tool-free answer stays a real reply:

RAW model text      : "FINAL-ANSWER-OK"
BUILT stopReason    : stop
  block[0] type=text     text="FINAL-ANSWER-OK" textSignature=undefined

So pre-tool narration from a live native-Ollama response is classified commentary and kept out of the reply lane, while a plain answer remains untagged. The one hop still unproven here is a live chat-channel turn (no Test Server credentials in this environment) — the Mantis capture request in the PR body covers that if a maintainer wants it.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 23, 2026
@Olli0103

Copy link
Copy Markdown
Contributor Author

Live Telegram turn captured on a contributor host with the real model and the branch code (no mocks, not repository infrastructure).

Setup: isolated Gateway, Telegram channel, ollama/qwen2.5:7b over native /api/chat, block streaming on (blockStreamingDefault: "on", blockStreamingBreak: "text_end", channels.telegram.streaming.mode: "block"), tools restricted to read. Chat id and sender redacted.

16:39:41 telegram inbound: <redacted chat> (direct, 310 chars)
16:39:44 [telegram] embedded run agent start: runId=dcc6e076-…
16:41:04 [telegram] embedded run tool start: … tool=read toolCallId=call_wi9nieq2
16:41:04 [telegram] embedded run tool start: … tool=read toolCallId=call_7t78nf1d
16:41:04 [telegram] embedded run tool end:   … tool=read toolCallId=call_wi9nieq2
16:41:04 [telegram] embedded run tool end:   … tool=read toolCallId=call_7t78nf1d
16:41:08 [telegram] embedded run agent end:  runId=dcc6e076-… isError=false
16:41:09 [diagnostic] message dispatch completed: channel=telegram source=replyResolver outcome=completed

Assistant messages for the turn (--raw-stream):

1. "Sure, let's start with the first file. NOTES.md."                                       + read(NOTES.md)  → not delivered
2. "The first line of NOTES.md is: … The first line of SECRET.md is: …"                      + read(SECRET.md)
3. "NO_REPLY"

Result on the channel side: exactly one message for the turn, delivered at turn end, carrying the two file lines. The round-1 narration sentence never shows up as a message of its own — checked from the human side, not just the logs.

Two honest notes: the model's terminal message was the NO_REPLY sentinel rather than a fresh answer, so this particular turn took delivery's silence-avoidance path — the transport-level evidence in the body (commentary tag on the narration, plain answer left untagged) shows the primary path. And this is still a contributor host, not a leased Test Server; the Mantis request in the body remains the repository-infrastructure capture.

@Olli0103

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@Olli0103

Copy link
Copy Markdown
Contributor Author

Ordinary final-answer delivery captured — the item the last review asked for.

Same isolated setup: Telegram channel, ollama/qwen2.5:7b over native /api/chat, block streaming on, tools restricted to read. Chat id/sender redacted.

17:12:41 telegram inbound: <redacted chat> (direct, 358 chars)
17:13:58 [auto-reply/agent-turn-timing] milestone=tool_execution_started

Assistant messages for that turn (--raw-stream):

1. "Sure, let's proceed step-by-step. One moment, I'll read the first line of `NOTES.md` for you."   + read(NOTES.md)  → not delivered
2. "One step further, I'll read the first line of `SECRET.md`. Here it is:"                              + read(SECRET.md) → not delivered
3. "The first line of `NOTES.md` is: … And the first line of `SECRET.md` is: … Is there anything else you need from these files?"  → delivered, once
4. "NO_REPLY"                                                                                              (internal)

Result: the DM contains exactly one message for the turn (delivered 17:14) — the ordinary final answer. Both narration messages were withheld, and the answer arrived through the normal path rather than the silence-avoidance fallback shown previously.

One transparency note: delivery of that hop is confirmed from the channel side; the isolated instance did not emit its usual outbound send ok line for it, so the log excerpt stops at the run milestone rather than showing the send. Still a contributor host, not a leased Test Server — the Mantis request in the body remains the repository-infrastructure capture.

@Olli0103

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@Olli0103

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review — body carries both remaining asks now: the ordinary final-answer Telegram delivery trace and the per-file test wall times.

@clawsweeper

clawsweeper Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@Olli0103

Copy link
Copy Markdown
Contributor Author

P3 test-policy finding fixed on d981684bbc: both final-delivery cases now retain the subscription and await subscription.waitForPendingEvents() before asserting, instead of vi.waitFor timer polling.

pnpm test src/agents/embedded-agent-subscribe.subscribe-embedded-agent-session.withholds-ollama-pretool-narration.test.ts \
          src/agents/embedded-agent-subscribe.handlers.messages.update-commentary.test.ts \
          src/agents/embedded-agent-subscribe.handlers.messages.lifecycle.test.ts --maxWorkers=1
→ Test Files 3 passed (3) | Tests 31 passed (31)

git diff --check → clean

No other vi.waitFor remains in the files this PR adds or touches.

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 23, 2026
@roboclaw-bot
roboclaw-bot force-pushed the fix/ollama-pretool-commentary-133922 branch from 29ae468 to 61be9f0 Compare September 27, 2026 00:29
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

Please reevaluate the leased Telegram Test Server proof requirement on exact head 61be9f0a036d0579be1887918278b1708e3cc1f7 using the updated evidence comment and PR body. New source-bound native/TDLib evidence shows 35 distinct narrated tool rounds, 34 successful reads plus one validation error, zero separate durable narration replies, and ordinary correct-phrase final plus tool-free 5 each delivered once. Strict two-call/exact-wording compliance failed; the other two bounded trials were invalid/insufficient, and four residual test prompts still need matching-account pool-owner cleanup. All credential/compute/runtime resources are released.

Please explicitly assess those qualifications rather than treating the scenario exit code as a strict pass. Existing exact-head CI is green. Durable-block timing/owner judgment remains open. Review only: no fix, rebase, merge, auto-merge, or waiver is requested.

@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@roboclaw-bot

roboclaw-bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Qwen3.5:35b-a3b — fresh live Telegram comparison, September 28, 13:25–13:35 UTC

Strict A FAIL (unchanged literal-path check); actual dependent-read/core-delivery behavior PASS; exact final-format check PASS; control B PASS. The model used absolute paths to the correct fixture files, while the unchanged checker requires literal relative arguments. That failure has not been normalized away or waived. Full current results.

Live Telegram Test Server TDLib observer—not Telegram Desktop. This is a contemporaneous capture of actual TDLib and native Ollama observations, not an official Telegram GUI or reconstructed chat. It starts before A, shows both narrated dependent reads and the real replies, and retains the approximately 98-second post-B quiet period.

  • A: two successful reads; native, persisted and Telegram final all exactly FINAL EMBER-A9E5D9C9B745, once, with no extra durable narration or duplicates.
  • B: exactly 5, once, no tools. Four real native /api/chat requests total; zero mock requests.
  • Model qwen3.5:35b-a3b, Q4_K_M, Ollama 0.34.4, CPU-only; unchanged source 61be9f0a036d0579be1887918278b1708e3cc1f7. One A/B attempt, no model rotation or prompt/assertion changes.
  • Raw capture: 598.167 s, 1600×1000. Inspected MP4: 110.417 s, 1600×1072; GIF: 110.500 s, 1280×858. Event contexts play at 1×, waiting at 16×; every raw interval is retained, including model-computation waits. A sub-frame waiting gap stays at 1× with its neighboring event context.
  • All four created messages were deleted and verified absent under the same healthy lease. Credential released and scratch erased; all consumers joined; AWS runtime confirmed released/no host.
live-telegram-tdlib-observer.mp4

The GIF shows the same recording:

35B-A3B GIF — actual live observer

Qwen3.5 35B-A3B actual live Telegram TDLib observer

The first local derivative render was rejected for an empty sub-frame segment/concat timestamp defect. Only the derivative renderer was repaired; the raw capture and live test were not rerun. The published versions passed full decode, duration/frame consistency, event/end-frame inspection, and privacy review. A single run does not establish general model superiority or erase the prior 9B failures.

Earlier capture history — unchanged

Previous 9B capture and historical Desktop evidence, preserved in full

Live Telegram Test Server capture — September 28 capture repair

Live Telegram Test Server TDLib observer—not Telegram Desktop. This is a contemporaneous recording of actual current-run TDLib observations and native Ollama/tool events, from before A was sent through both replies and the 112.7-second post-B quiet period. It is not reconstructed chat, an official Telegram GUI appearance proof, or the historical post-run Desktop clip below.

Capture PASS; core commentary/durable-delivery behavior PASS; strict A FAIL; B PASS. Exactly 2 successful dependent reads, with real nonempty narration before each and distinct v1 commentary IDs; 0 separate durable Telegram narration messages, no duplicates, and exactly one A final. The model returned EMBER-C2FEFD89CE65, not the required FINAL EMBER-C2FEFD89CE65: the missing prefix is present in native output, persisted history and Telegram. This is distinct from the previous run’s colon mismatch. B returned 5 once, with 0 tools. Four real native streaming requests, all HTTP 200; 0 mock requests. No retry-for-green or relaxed expected literal.

The framing repair used a fresh owned Xvfb display and verified the full 1600×1000 window at (0,0), including overflow calibration and a clean-ready visual inspection before the credential lease or traffic. The polished video retains every interval of the 594.667-second raw timeline: waiting intervals are explicitly captioned 16×, event contexts 1×. Raw capture and private traces are not published. MP4: 111.58s, 1600×1072; GIF: 111.67s, 1280×858.

Live observer video

live-telegram-tdlib-observer.mp4
GIF of the same live observer recording

Live Telegram Test Server TDLib observer—not Telegram Desktop; two dependent reads, strict A missing-prefix failure, and B reply 5; waits 16×, event contexts 1×

Source remains 61be9f0, tree 6c2548ec213cf40dcf9436316f25afa160c222ef. All four current-run Telegram messages were deleted and absence verified under the same healthy lease; consumers joined before release, credential scratch is zero, and compute termination is confirmed. Authoritative proof and runtime details. No new source change, CI run, review approval, timing waiver or merge claim.


Historical evidence — entire previous comment: operator-supplied post-run Telegram Desktop recording, not this live Test Server capture

Telegram Desktop recording — separate from the Web UI video

This is the operator-supplied, actual Telegram Desktop recording from the production-DM test reported at head 61be9f0. It is not the earlier Control Web UI capture.

Scope: the 12-second clip was recorded after both turns completed. It shows persisted Telegram conversation state, not the live send/typing/tool interval, and not the leased Telegram Test Server run. The header and older unrelated conversation were cropped for privacy; chat contents and playback speed were not changed. The caption makes that boundary explicit.

Visible results: one tool-turn final containing the correct verification phrase plus extra model prose, then one ordinary “The answer is 5.” reply. The supplied report records four calls (three successful, one invalid), not the requested exact two-call sequence. The video alone does not prove tool execution or message timing.

The separate leased Telegram Test Server E2E trace documents the real native-Ollama/TDLib run and was accepted in review revision 28. No GUI recording was captured for that Test Server run. The older Web UI video remains separately labeled and pinned to its own revision.

GIF of the same Telegram post-run recording

Actual Telegram Desktop after the production-DM test; not a live-turn or Test Server recording

Telegram video

telegram-postrun-production-dm.mp4

Preserve the current cron fixture simplification and shared cleanup owner while retaining the lazy diagnostic watchdog and native Ollama pending-phase behavior.

Co-authored-by: Solvely-Colin <[email protected]>
@roboclaw-bot roboclaw-bot changed the title fix(ollama): tag native pre-tool narration as commentary fix(ollama): keep pre-tool narration out of channel replies Sep 28, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Oct 8, 2026
steipete and others added 3 commits October 8, 2026 20:35
Keep native Ollama tool narration out of durable replies using the existing pending-phase owner. Preserve ordinary and length-limited final answers, consolidate regressions, and remove unrelated cron diagnostics.

Co-authored-by: Olli0103 <[email protected]>
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 9, 2026
@steipete steipete self-assigned this Oct 9, 2026
@steipete
steipete merged commit 4fc18ea into openclaw:main Oct 9, 2026
130 checks passed
@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…#156389)

* test(ollama): prove native pre-tool narration is delivered as a final answer (openclaw#133922)

The native Ollama stream attaches no phase to visible text that precedes a
tool call in the same assistant message. OpenClaw therefore classifies that
pre-tool narration as the final answer and delivers it to the channel as its
own message (issue openclaw#133922, non-reasoning model behind the Ollama provider).

This regression pins the missing contract: a tool-use assistant message must
tag its visible text as commentary, which keeps it out of the reply lane. It
fails on the current base; the guard test keeps a tool-free answer untagged.

Co-authored-by: Solvely-Colin <[email protected]>

* fix(ollama): tag native pre-tool narration as commentary

Native Ollama returns narration text and tool calls in the same assistant
message. The native stream attached no phase to that visible text, so it was
classified as the final answer and delivered to the channel as its own message.

Tag unphased visible text as commentary (textSignature v1) when the message
resolves to a tool use, mirroring the Chat Completions and Anthropic transports.
A tool-free answer stays untagged and still reaches the channel as the final
reply, and a token-limit stop remains an ordinary partial answer.

Fixes openclaw#133922

Co-authored-by: Olli0103 <[email protected]>
Co-authored-by: Solvely-Colin <[email protected]>

* fix(ollama): unique commentary ids and withhold pre-tool narration

Mirror the shared pre-tool phase mechanism more closely after review:

- Give each tagged commentary segment per-response entropy
  (commentary-<index>-<random>), matching
  packages/ai/src/utils/assistant-text-phase.ts. A response-local index alone
  aliased every tool response to commentary-0, so the Control UI overwrote an
  already-shown segment when reconciling by run id + item id.
- Add the native-Ollama pending-phase guard
  (isOllamaAssistantMessage + isPhasePendingOllamaText) so unsigned
  text_end/early deltas are withheld from durable block replies until the tool
  boundary decides, matching the Anthropic / Responses / Chat Completions
  guards. Ordinary final answers and length-limited output still deliver.

Fixes openclaw#133922

Co-authored-by: Olli0103 <[email protected]>
Co-authored-by: Solvely-Colin <[email protected]>

* fix(agents): document the ollama transport assertion for the SAFETY ratchet

The new isOllamaAssistantMessage predicate adds a structural cast to
embedded-agent-subscribe.handlers.messages.stream.ts, which already sits at its
grandfathered per-file assertion cap. Annotate the invariant above the
assertion so the assertion-safety ratchet stays green; the ratchet only
exempts a SAFETY comment on the same line as the operator or on the
immediately preceding standalone line.

Fixes openclaw#133922

Co-authored-by: Olli0103 <[email protected]>
Co-authored-by: Solvely-Colin <[email protected]>

* test(ollama): await subscriber completion instead of polling

Addresses the ClawSweeper [P3] finding on openclaw#156389: the two final-delivery
cases used vi.waitFor timer polling, contrary to the repo test policy.
Retain the subscription and await waitForPendingEvents() before asserting.

Co-authored-by: Solvely-Colin <[email protected]>

* test(ollama): cover native commentary delivery boundaries

Exercise unsigned text_end before tool events, preserve native terminal ordering across two rounds, and assert exactly-once final delivery after awaiting subscriber settlement.

Co-authored-by: Solvely-Colin <[email protected]>

* docs(ollama): explain deferred durable reply blocks

Document the native Ollama text_end timing exception, its effect on long tool-free answers, and the independent preview stream. Preserve the existing narration classification and final/length behavior.

Co-authored-by: Solvely-Colin <[email protected]>

* test(cron): diagnose real-heartbeat watchdog timeouts

Record bounded phase and heartbeat settlement observations when the existing watchdog expires. Add deterministic diagnostic coverage without changing production behavior or extending timeouts.

Co-authored-by: Solvely-Colin <[email protected]>

* refactor(ollama): isolate response text phase tagging

Keep visible text creation and its terminal commentary classification in an extension-owned sibling without growing the stream runtime. Preserve signatures, ordinary and length-stop answers, and existing public boundaries.

Co-authored-by: Solvely-Colin <[email protected]>

* fix(ollama): share pending text phase delivery

Keep native Ollama tool narration out of durable replies using the existing pending-phase owner. Preserve ordinary and length-limited final answers, consolidate regressions, and remove unrelated cron diagnostics.

Co-authored-by: Olli0103 <[email protected]>

* test(ollama): label narration assertions

* test(ollama): expect commentary in buffered tool replies

---------

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: ollama merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

[Bug]: Telegram DM - intermediate assistant text between tool calls delivered as visible messages (2026.8.1)

3 participants