Repository navigation
fix(ollama): keep pre-tool narration out of channel replies - #156389
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThe 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
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Provenance
Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +30, Tests +252, Docs +19. Total +301 across 9 files. Added test files: 1. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (31 earlier review cycles; latest 8 shown)
Reviewed October 9, 2026, 2:05 AM ET / 06:05 UTC (Revision 32). |
|
@clawsweeper re-review — both review findings are addressed on head |
|
🦞👀 Re-review progress:
|
|
Both review findings are fixed on 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: We also have a local native Ollama (0.34.3, |
|
Real-model evidence is in — no mocks on this path. Environment: Ollama 0.34.3 local, Tool-free answer stays a real reply: 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. |
|
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, Assistant messages for the turn ( 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 |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Ordinary final-answer delivery captured — the item the last review asked for. Same isolated setup: Telegram channel, Assistant messages for that turn ( 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 |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review — body carries both remaining asks now: the ordinary final-answer Telegram delivery trace and the per-file test wall times. |
|
🦞👀 Re-review progress:
|
|
P3 test-policy finding fixed on No other |
29ae468 to
61be9f0
Compare
|
@clawsweeper re-review Please reevaluate the leased Telegram Test Server proof requirement on exact head 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. |
|
🦞👀 Re-review progress:
|
Qwen3.5:35b-a3b — fresh live Telegram comparison, September 28, 13:25–13:35 UTCStrict 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.
live-telegram-tdlib-observer.mp4The GIF shows the same recording: 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 — unchangedPrevious 9B capture and historical Desktop evidence, preserved in fullLive Telegram Test Server capture — September 28 capture repairLive 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 videolive-telegram-tdlib-observer.mp4Source 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 captureTelegram Desktop recording — separate from the Web UI videoThis 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. Telegram videotelegram-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]>
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]>
|
Merged via squash.
|
…#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]>



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
textSignaturecommentary phase only when the completed response resolves totoolUse. 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 gaintextPhaseRequiresTerminal;stopandlengthtext stays unphased.This refresh merges main
c9c09fb11b08bdfbb71751e6e6b9dccfe316fab0while 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.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.onBlockReply, and the native transport test fails becausetextSignatureis 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.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, unsignedtext_end, exactly-once final delivery, and text-before-reasoning at bothstopandlength. The companionextensions/ollama/src/stream-runtime.test.tsalso passes: 78 tests, 16.82s wall after the CI expectation correction below.expectDefinedcalls. 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.f010fc0b579071d151e8f4e4084a40ac0b219057. The two Gateway startup failures were before Ollama execution: shared-state admission inserver.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.bindCliQuestionAnswerAuthority,prepareSessionEventTargetForHost,readSessionEntryCreationTransition, andRESTART_CONTINUATION_CONTEXT_PREFIX. Their owning files are outside this patch. The baseline scan also failed (80.19s); this failure is retained, not reported green.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.Live native Ollama and real Gateway, observed through QA channel
The real CLI/Gateway used native
/api/chatat127.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 throughsessions.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:NARRATION_FINAL_133922reply.NARRATION_FINAL_133922reply. One transient preview was deleted.OLLAMA_CONTROL_OKarrived exactly once, without tools.llama3.2:latestwithnum_predict: 32ended withstopReason: "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.
read/skills_readcalls; 25 successful results, 35 failures, then context overflow and abort. Invalid completed-answer stimulus./no_thinkcue; no tool call. Invalid narration stimulus.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, andTMPDIRunder/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/stateincluding preview deletions.The bus and Gateway ran in separate foreground processes. Both were stopped after proof; ports were verified free.