Repository navigation
fix(agents): recover reasoning-only and bare tool-call settled-turn answers - #174376
Conversation
…nswers A settled tool turn that ends with a signed reasoning-only stop, an output limit that leaves no answer after transport markup removal, or a bare unterminated <tool_call> transport marker was classified as a delivered answer, silently losing the reply. Route non-visible stops after settled tools to the existing tool-disabled finalizer (never another tool-enabled attempt), treat a lone bare tool-call marker as non-visible text, and reserve the local Qwen finalizer pass for text by disabling thinking there. Ported from a digest-fenced live hotfix qualified on 2026.10.2 (reasoning-only and bare tool_call terminals diagnosed 2026-10-15); delivery-state guards omitted because main now routes delivered/pending replies to the finalizer by design.
|
🦞👀 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 PR routes non-visible settled-tool endings through existing tool-free finalization and hides bare unfinished tool-call markers while preserving Markdown examples. Example: A Qwen response ends at its output limit with only <tool_call> after one successful exec call.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a concrete missing-answer path that remains on current main; both earlier findings are resolved, and no actionable correctness defect remains. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe embedded runner classifies assistant output after tool settlement, checks delivery and outstanding work, and passes eligible missing answers to the existing tool-free finalizer before preparing terminal reply payloads. flowchart TD
A[Provider response and settled tools] --> B[Canonical visible text sanitizer]
B --> C[Current assistant classification]
C --> D[Settlement and delivery guards]
D --> E[Existing tool free finalizer]
E --> F[Terminal reply preparation]
F --> G[CLI or channel delivery]
Technical reviewBest possible solution: Land the focused repair through the existing finalization owner once the normal exact-head gates pass. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the bare-marker length-stop failure and projected-response recovery gap; the supplied CLI before/after captures independently demonstrate the bare-marker case, without this review executing target code. Is this the best way to solve the issue? The repair fits the existing shared sanitizer and tool-free finalization owners, preserves model selection and thinking preferences, and retains the guards against replay, outstanding work, duplicate delivery, and intentional silence. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d7509bb8c66f. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +5, Tests +134, Docs 0. Total +139 across 5 files. Added test files: 1. View PR surface stats
Review metrics
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 (2 earlier review cycles)Reviewed October 16, 2026, 8:06 PM ET / October 17, 2026, 00:06 UTC (Revision 3). |
Use the current response's visible text to admit settled-tool finalization for stop and length endings, including projected transcripts. Strip a lone unfinished tool-call marker in the canonical visible-text sanitizer. Keep the configured model and thinking preference in the existing tool-free finalizer. Preserve meaningful partial replies and settled-work safety guards.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…nswers (openclaw#174376) ## What Problem This Solves Fixes a missing final answer after settled tools when the model emits only reasoning or a bare unfinished `<tool_call>` marker, including output-limit endings and projected transcripts. ## User Impact OpenClaw can compose an answer from settled tool results without repeating completed tools. Meaningful partial answers, intentional silence, delivered replies, and outstanding-work safety guards retain their existing behavior. The configured model and requested thinking preference remain intact. ## Why This Change Was Made The existing settled-turn finalizer now tests for absence of visible text and accepts both `stop` and `length`, using the canonical current/completed assistant resolver. The shared visible-text sanitizer checks existing Markdown code regions before removing a standalone unfinished tool-call opener, preserving quoted, fenced, indented, and explanatory examples. The terminal-reply owner remains the single classifier; this does not add another recovery pass or provider-specific thinking override. Merged main into Arthur Drozdov's original branch, retaining his commits and the general repair. Thanks @arthur-drozdov. The earlier local-Qwen override and redundant classification sanitizer are removed; the existing provider owner keeps responsibility for thinking support. Production changes: +11/-6 (net +5); tests: +134/-0; documentation: +1/-1, relative to merged main `421b1d62236cf2912f71fb53ca12546bab5c477b`. The small production growth expresses the expanded stop condition and canonical bare-marker rule after removing a redundant settlement check. No model-facing prompt changes; token delta zero. ## Evidence - The final visible-text and recovery suites pass 100/100 tests (158.45s wall), including four-space/tab-indented code and delivery preservation. The earlier settlement evidence and finalization/harness suites also pass. The narrowed regression on unchanged main failed the three intended recovery cases and passed all 11 controls (316.80s); a direct owner probe reproduced both indentation deletions before the Markdown correction. - Core and fresh agents-other types, scoped lint, formatting, and `git diff --check` pass. An earlier incremental type-cache diagnostic disappeared on fresh exact-base and candidate graphs; no source workaround was added. - Full `pnpm build` passes on the final correction (491.33s), including all 155 SDK export checks and UI startup budgets. No prompt text changed. - Line-cap, assertion-safety, timeout-race, mock-export, config-doc and plugin-inventory checks pass. Max-lines reports three unchanged UI suppressions; the exact merged base reproduces the same failures (113.09s). This is inherited. - Independent Codex review: scoped-clean through P2, no actionable findings. - Six deterministic streamed-provider cases through the real CLI pass: reasoning-only `stop`, reasoning-only `length`, and bare-marker `length`, each with both `qwen` and `qwen-chat-template`. Every case returns the expected answer, records exactly one physical `exec` effect, and makes three requests with zero tools in the finalizer. All requests preserve the correct top-level or nested `enable_thinking: true`. Case wall times: 33.9–46.6s; agent times: 4.27–5.86s. - Native Ollama `qwen3:4b` and `qwen3:8b` both return `EFFECT_OK` after one successful `exec` effect and two `/api/chat` requests with `think: "medium"`. Wall/agent times: 108.195/70.205s and 56.179/24.291s respectively. Both use `num_ctx: 32768` and `num_predict: 4096`. The six-case matrix and native controls were recorded on `085de052e19`. After the Markdown guard correction, both bare-marker formats were rerun on `72674527bbc`: both pass with one effect and a zero-tool finalizer (wall/agent 29.555/5.278s and 40.560/3.929s). The 100-test final run also proves indented examples survive delivery. CLI command surface: `pnpm openclaw --profile reasoning-only-recovery agent --local --agent main --thinking medium --json`, with a fresh session, task-specific state/config/workspace, and a loopback request recorder. No operator Gateway, state, or service is used. Baseline distinction: ordinary full-transcript reasoning-only `stop` and `length` already recover on main. The new reasoning regression covers projected snapshots omitting the tool batch, including a completed response retained after the current snapshot slot is absent. The actual CLI before/after defect is the bare-marker output-limit reply: baseline makes two provider requests, records one real tool effect, skips the finalizer, and returns the marker plus a truncation notice. All CLI proof uses the real isolated `pnpm openclaw --profile reasoning-only-recovery agent --local` entry point on macOS. Deterministic provider requests cover both declared Qwen thinking formats. Native Ollama smoke uses qwen3:4b and qwen3:8b; these are control runs, not claims that a natural model deterministically reproduces the defect. No cross-platform proof or performance comparison is claimed. <details> <summary>Captured bare-marker CLI output and request/effect trace</summary> Extracts below come from actual isolated local-agent CLI output, recorded provider requests, and a file that each completed tool call appends to. The deterministic local provider emits one tool call, then a bare `<tool_call>` with a length stop. Paths, addresses, credentials, and run/session identifiers are omitted. ### Before repair ```json { "thinkingFormat": "qwen", "cliOutput": {"payloads": [{"text": "<tool_call>"}, {"text": "⚠️ Reply truncated at the model's output token limit. The text above is partial — ask to continue it."}], "terminalReply": {"disposition": "visible", "text": "<tool_call>"}, "toolSummary": {"calls": 1, "tools": ["exec"], "failures": 0}}, "physicalToolEffects": 1, "providerRequests": 2, "toolsPerRequest": [4, 4], "finalizerRequests": 0, "thinkingPerRequest": [{"enable_thinking": true}, {"enable_thinking": true}] } ``` ### After repair: qwen ```json { "thinkingFormat": "qwen", "cliOutput": {"payloads": [{"text": "Recovered bare-marker; one recorded effect."}], "terminalReply": {"disposition": "visible", "text": "Recovered bare-marker; one recorded effect."}, "toolSummary": {"calls": 1, "tools": ["exec"], "failures": 0}}, "physicalToolEffects": 1, "providerRequests": 3, "toolsPerRequest": [4, 4, 0], "finalizerRequests": 1, "thinkingPerRequest": [{"enable_thinking": true}, {"enable_thinking": true}, {"enable_thinking": true}] } ``` ### After repair: qwen-chat-template ```json { "thinkingFormat": "qwen-chat-template", "cliOutput": {"payloads": [{"text": "Recovered bare-marker; one recorded effect."}], "terminalReply": {"disposition": "visible", "text": "Recovered bare-marker; one recorded effect."}, "toolSummary": {"calls": 1, "tools": ["exec"], "failures": 0}}, "physicalToolEffects": 1, "providerRequests": 3, "toolsPerRequest": [4, 4, 0], "finalizerRequests": 1, "thinkingPerRequest": [{"chat_template_kwargs": {"enable_thinking": true}}, {"chat_template_kwargs": {"enable_thinking": true}}, {"chat_template_kwargs": {"enable_thinking": true}}] } ``` Both repaired runs returned the answer through the existing finalizer with zero tools. Each completed exactly one tool effect and retained the configured thinking format with thinking enabled. These captures use a deterministic provider; the separately reported native Qwen smoke runs exercised real models. </details> Co-authored-by: Arthur Drozdov <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
…aming (#175472) fix(text): stop re-parsing streamed Markdown for ordinary HTML/JSX markup While a long reply streamed, the tool-call XML filter parsed the whole growing Markdown text for every ordinary less-than sign, so long HTML/JSX answers burned a lot of Gateway CPU. The Markdown ownership check now runs only for text that could start a tool-call tag. Thanks @JasonBuildAI. Release adaptation: the stable filter predates main's streaming-prefix hold (#174376), isToolCallTagPrefix, isInsideSettledBlockCode, and the protection fast-path scanner. Ported the fix logic onto the stable loop instead: the Markdown ownership parse (findCodeRegions) now runs only for a complete tool-call tag candidate, and an unfinished trailing tag name (e.g. "<p") is rescanned on the next append without any parse, which covers the partial-boundary stall fixed on main by edbe9a2 (#180765). Both outcomes previously returned false, so the projection output is unchanged. Ported the #175472 and #180765 work-count and chunk-boundary parity tests (without main's streaming flag). 37e5e6c (#181397, stall after a real tool-call XML activates the filter) is a separate bug that depends on main-only ownership reuse (#175328) and diverged stream handlers; not included. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 2ad3797) Includes fix logic from commit edbe9a2
What Problem This Solves
Fixes a missing final answer after settled tools when the model emits only reasoning or a bare unfinished
<tool_call>marker, including output-limit endings and projected transcripts.User Impact
OpenClaw can compose an answer from settled tool results without repeating completed tools. Meaningful partial answers, intentional silence, delivered replies, and outstanding-work safety guards retain their existing behavior. The configured model and requested thinking preference remain intact.
Why This Change Was Made
The existing settled-turn finalizer now tests for absence of visible text and accepts both
stopandlength, using the canonical current/completed assistant resolver. The shared visible-text sanitizer checks existing Markdown code regions before removing a standalone unfinished tool-call opener, preserving quoted, fenced, indented, and explanatory examples. The terminal-reply owner remains the single classifier; this does not add another recovery pass or provider-specific thinking override.Merged main into Arthur Drozdov's original branch, retaining his commits and the general repair. Thanks @arthur-drozdov. The earlier local-Qwen override and redundant classification sanitizer are removed; the existing provider owner keeps responsibility for thinking support.
Production changes: +11/-6 (net +5); tests: +134/-0; documentation: +1/-1, relative to merged main
4453e5570f6a2cea77af7e111869c199cd0b42fc. The small production growth expresses the expanded stop condition and canonical bare-marker rule after removing a redundant settlement check. No model-facing prompt changes; token delta zero.Evidence
git diff --checkpass. An earlier incremental type-cache diagnostic disappeared on fresh exact-base and candidate graphs; no source workaround was added.pnpm buildpasses on the final correction (491.33s), including all 155 SDK export checks and UI startup budgets. No prompt text changed.stop, reasoning-onlylength, and bare-markerlength, each with bothqwenandqwen-chat-template. Every case returns the expected answer, records exactly one physicalexeceffect, and makes three requests with zero tools in the finalizer. All requests preserve the correct top-level or nestedenable_thinking: true. Case wall times: 33.9–46.6s; agent times: 4.27–5.86s.qwen3:4bandqwen3:8bboth returnEFFECT_OKafter one successfulexeceffect and two/api/chatrequests withthink: "medium". Wall/agent times: 108.195/70.205s and 56.179/24.291s respectively. Both usenum_ctx: 32768andnum_predict: 4096.The six-case matrix and native controls were recorded on
085de052e19. After the Markdown guard correction, both bare-marker formats were rerun on72674527bbc: both pass with one effect and a zero-tool finalizer (wall/agent 29.555/5.278s and 40.560/3.929s). The 100-test final run also proves indented examples survive delivery.CLI command surface:
pnpm openclaw --profile reasoning-only-recovery agent --local --agent main --thinking medium --json, with a fresh session, task-specific state/config/workspace, and a loopback request recorder. No operator Gateway, state, or service is used.Baseline distinction: ordinary full-transcript reasoning-only
stopandlengthalready recover on main. The new reasoning regression covers projected snapshots omitting the tool batch, including a completed response retained after the current snapshot slot is absent. The actual CLI before/after defect is the bare-marker output-limit reply: baseline makes two provider requests, records one real tool effect, skips the finalizer, and returns the marker plus a truncation notice.All CLI proof uses the real isolated
pnpm openclaw --profile reasoning-only-recovery agent --localentry point on macOS. Deterministic provider requests cover both declared Qwen thinking formats. Native Ollama smoke uses qwen3:4b and qwen3:8b; these are control runs, not claims that a natural model deterministically reproduces the defect. No cross-platform proof or performance comparison is claimed.Captured bare-marker CLI output and request/effect trace
Extracts below come from actual isolated local-agent CLI output, recorded provider requests, and a file that each completed tool call appends to. The deterministic local provider emits one tool call, then a bare
<tool_call>with a length stop. Paths, addresses, credentials, and run/session identifiers are omitted.Before repair
{ "thinkingFormat": "qwen", "cliOutput": {"payloads": [{"text": "<tool_call>"}, {"text": "⚠️ Reply truncated at the model's output token limit. The text above is partial — ask to continue it."}], "terminalReply": {"disposition": "visible", "text": "<tool_call>"}, "toolSummary": {"calls": 1, "tools": ["exec"], "failures": 0}}, "physicalToolEffects": 1, "providerRequests": 2, "toolsPerRequest": [4, 4], "finalizerRequests": 0, "thinkingPerRequest": [{"enable_thinking": true}, {"enable_thinking": true}] }After repair: qwen
{ "thinkingFormat": "qwen", "cliOutput": {"payloads": [{"text": "Recovered bare-marker; one recorded effect."}], "terminalReply": {"disposition": "visible", "text": "Recovered bare-marker; one recorded effect."}, "toolSummary": {"calls": 1, "tools": ["exec"], "failures": 0}}, "physicalToolEffects": 1, "providerRequests": 3, "toolsPerRequest": [4, 4, 0], "finalizerRequests": 1, "thinkingPerRequest": [{"enable_thinking": true}, {"enable_thinking": true}, {"enable_thinking": true}] }After repair: qwen-chat-template
{ "thinkingFormat": "qwen-chat-template", "cliOutput": {"payloads": [{"text": "Recovered bare-marker; one recorded effect."}], "terminalReply": {"disposition": "visible", "text": "Recovered bare-marker; one recorded effect."}, "toolSummary": {"calls": 1, "tools": ["exec"], "failures": 0}}, "physicalToolEffects": 1, "providerRequests": 3, "toolsPerRequest": [4, 4, 0], "finalizerRequests": 1, "thinkingPerRequest": [{"chat_template_kwargs": {"enable_thinking": true}}, {"chat_template_kwargs": {"enable_thinking": true}}, {"chat_template_kwargs": {"enable_thinking": true}}] }Both repaired runs returned the answer through the existing finalizer with zero tools. Each completed exactly one tool effect and retained the configured thinking format with thinking enabled. These captures use a deterministic provider; the separately reported native Qwen smoke runs exercised real models.