Skip to content

[Bug]: In-turn reasoning dropped on multi-turn tool replay for non-400 openai models (gemma4/vLLM) — silent agentic-quality regression #91645

Closed

Description

@bfox55

Bug type

Behavior bug (incorrect output/state without crash)

Summary

For openai-completions reasoning models whose API does not require reasoning_content on assistant messages (e.g. gemma4 / Gemma-4-12B on vLLM), OpenClaw drops the model's in-turn reasoning when replaying multi-turn tool conversations. Since the provider doesn't 400 on the missing field (unlike DeepSeek/Moonshot/Xiaomi), the failure is silent: no error, just degraded multi-step tool behavior — tool-call arguments intermittently collapse to {}, and the model re-issues identical tool calls because it can't see its own prior reasoning.

This is distinct from the known API-compat issues (#70392, #81419, #91558, #89660, #91106): those inject an empty reasoning_content: "" to satisfy strict provider schemas and avoid a 400. Here the provider is fine without the field — what's missing for quality is the real in-turn reasoning text, so the model keeps continuity across tool calls.

Evidence (captured off the wire)

TCP tee between OpenClaw and vLLM; one multi-turn tool exchange via openclaw agent --local --thinking high. Deepest request OpenClaw sent (system, user, 3× assistant tool-call, 3× tool):

  • ✅ structured tool_calls preserved
  • ✅ tool-call / tool-result IDs match exactly
  • ❌ reasoning_content present on 0 / 3 in-turn assistant tool-call messages

The Gemma 4 chat template re-injects in-turn reasoning (reasoning/reasoning_content → <|channel>thought…<channel|>, gated to messages after the last user turn — it correctly keeps in-turn reasoning and drops completed-turn reasoning). OpenClaw sends nothing, so re-injection never fires. Across stored trajectories on this install: 13 exec calls with empty arguments (exec requires a command), plus repeated identical tool calls within sessions.

Suspected root cause

reasoningContent appears empty at replay for these models, so the existing populate path never runs:

if (reasoningContent.length > 0) assistantMsg.reasoning_content = reasoningContent.join("\n");
else if (allowReasoningContentReplay) /* inject empty placeholder */

requiresReasoningContentOnAssistantMessages only governs the else (empty-field API-compat shim) and so does not restore real reasoning. The gap looks upstream: in-turn reasoning isn't carried from the session store into reasoningContent for openai-format models that aren't on the DeepSeek/Xiaomi detect list. (Same populate code in 2026.6.1 and 2026.6.5-beta — not a regression.)

Proposed direction

Preserve real in-turn reasoning (reasoning generated since the last user message) on replayed assistant tool-call messages for openai reasoning models, independent of the empty-field API-compat path. This matches what the Gemma model card + chat template assume, and the community reports of the same symptom (Gemma-4-12B tool-calling PSA on r/LocalLLaMA; Qwen3.6 analogue: earendil-works/pi#3325 — "after 2-3 turns every tool call collapses to arguments: {}").

Steps to reproduce

  1. Configure a gemma4 model via api: openai-completions on vLLM, compat.thinkingFormat: "openai", reasoning: true.
  2. Run a multi-step agent task that needs 2+ sequential tool calls, --thinking high.
  3. Capture the request bodies OpenClaw sends to the model (LLM proxy / tee).
  4. Observe: in-turn assistant tool-call messages carry tool_calls but no reasoning_content; over several turns, arguments degrade / tool calls repeat.

Environment

  • OpenClaw 2026.6.1
  • Gemma-4-12B (NVFP4) via vLLM 0.22, api: openai-completions, compat.thinkingFormat: "openai", reasoning: true, --thinking high

Workaround

Make each tool action self-contained (a single call returns the final value — e.g. server-computed totals, or a gog | jq | date one-liner) so turns don't depend on cross-turn reasoning. Restores correctness for those flows but doesn't help genuinely multi-step reasoning.

Activity

  1. clawsweeper commented on Jun 9, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 9, 2026, 3:30 AM ET / 07:30 UTC.

    Summary
    Keep open: current main still has a Gemma 4 exclusion in the OpenAI-compatible replay sanitizer, so the reported in-turn reasoning_content preservation gap is not resolved by the existing empty-field compatibility flag or prior DeepSeek/Xiaomi fixes.

    Reproducibility: yes. with source-level confidence: current main still has the Gemma 4 replay trust exclusion and the issue includes live request-body captures. I did not independently rerun vLLM/Gemma in this read-only review.

    Next step
    The issue is concrete, but the fix needs maintainer judgment on the Gemma same-turn replay policy before an automated repair lane should change provider behavior.

    Review details

    Best possible solution:

    Keep the issue open for a maintainer-owned provider replay decision: preserve real same-turn Gemma/OpenAI-compatible reasoning only when the provider emitted replayable reasoning, while keeping completed-turn stripping where that remains intentional.

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

    Yes, with source-level confidence: current main still has the Gemma 4 replay trust exclusion and the issue includes live request-body captures. I did not independently rerun vLLM/Gemma in this read-only review.

    Is this the best way to solve the issue?

    Unclear: the requested same-turn exception is plausible, but it changes provider replay policy and should be reviewed by the provider/replay owner before implementation.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • No fresh live vLLM/Gemma tee was run during this read-only review; the keep-open decision relies on current source plus the reporter's supplied live captures.

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

    Label changes

    Label justifications:

    • P2: The issue affects multi-turn tool quality for a specific OpenAI-compatible local model/provider setup without making the core runtime unusable.
    • impact:session-state: The failure mode is loss of in-turn reasoning state during tool-call replay.
    • impact:auth-provider: The affected surface is provider/model compatibility and OpenAI-compatible reasoning replay behavior.
    Evidence reviewed

    Acceptance criteria:

    • Add focused coverage for Gemma/OpenAI-compatible same-turn assistant tool-call replay preserving non-empty reasoning_content.
    • Run a live or recorded vLLM/Gemma request-body proof showing non-empty in-turn reasoning_content and completed-turn stripping behavior.

    What I checked:

    • Current source: The OpenAI transport preserves reasoning_content only for explicit compat/deepseek/zai/replay-id paths, and shouldTrustReasoningContentReplayMetadata explicitly returns false for Gemma 4 model ids. (src/agents/openai-transport-stream.ts:3978, f57c3b55fdc4)
    • Current source: The serializer can emit real reasoning_content from non-empty thinking blocks, but the compatibility flag only adds an empty placeholder when no real field is present. (src/llm/providers/openai-completions.ts:996, f57c3b55fdc4)
    • Current source: dropReasoningFromHistory preserves reasoning for the active tool-call continuation after the latest user turn, matching the reporter's narrowed source trace that loss happens later in OpenAI-compatible sanitization. (src/agents/embedded-agent-runner/thinking.ts:444, f57c3b55fdc4)
    • Shipped behavior check: The latest release tag v2026.6.1 contains the same Gemma 4 exclusion in the OpenAI transport and only auto-detected DeepSeek for requiresReasoningContentOnAssistantMessages in the provider path. (src/agents/openai-transport-stream.ts:3991, 2e08f0f4221f)
    • Reporter live evidence: The follow-up comments report live vLLM/Gemma TCP-tee captures where v2026.6.1 sent 0/3 in-turn reasoning_content fields and v2026.6.5-beta.5 with the compat flag sent 8/8 empty fields, not real reasoning text.
    • History provenance: Current blame for the Gemma 4 replay sanitizer, active tool-turn reasoning preservation, and placeholder insertion points is commit 5097749. (src/agents/openai-transport-stream.ts:3978, 5097749de32c)

    Likely related people:

    • Dallin Romney: Current blame ties the relevant replay sanitizer, Gemma 4 exclusion, active tool-turn preservation, and OpenAI completions serialization to commit 5097749. (role: recent area contributor; confidence: high; commits: 5097749de32c; files: src/agents/openai-transport-stream.ts, src/agents/embedded-agent-runner/thinking.ts, src/llm/providers/openai-completions.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. added
    P2Normal backlog priority with limited blast radius.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.
    on Jun 9, 2026
  3. bfox55 commented on Jun 9, 2026

    @bfox55
    Author

    Followed up by testing whether the now-settable requiresReasoningContentOnAssistantMessages flag (schema exposed in 2026.6.5-beta via #89660) is sufficient. It is not — it injects the field but empty.

    Method: isolated sandbox install of 2026.6.5-beta.5 (separate prefix + HOME, production untouched), gemma4/vLLM model with compat.requiresReasoningContentOnAssistantMessages: true, routed through a TCP tee to capture the exact request bodies. Multi-step tool task, --thinking high.

    Result (deepest request, 8 in-turn assistant tool-call turns):

    2026.6.1 (no flag) 2026.6.5-beta.5 (flag=true)
    reasoning_content present 0 / 8 8 / 8
    reasoning_content non-empty (real text) 0 / 8 0 / 8 — all ""

    So the flag flips the field from absent to present-but-empty — which is exactly the API-compat behavior (avoid a strict-provider 400), and confirms it does not restore the model's real in-turn reasoning.

    The populate path itself is fine and identical across 6.1 and the beta:

    if (reasoningContent.length > 0) assistantMsg.reasoning_content = reasoningContent.join("\n");
    else if (allowReasoningContentReplay) /* empty placeholder */

    The gap is upstream: reasoningContent arrives empty at replay for openai-format models that aren't on the DeepSeek/Xiaomi detect list, so only the empty-placeholder branch ever runs. Fixing this for non-400 reasoning models (gemma4, etc.) needs the in-turn reasoning to actually be carried into reasoningContent — the empty-field flag alone won't do it.

  4. bfox55 commented on Jun 9, 2026

    @bfox55
    Author

    Thanks for the detailed triage — I can close the needs-live-repro gap. This report is from a live vLLM / Gemma-4-12B run, not source inspection, and the wire evidence lines up exactly with your source trace (which is more precise than my original "arrives empty upstream" framing — the field is preserved in dropReasoningFromHistory, then stripped by the Gemma-4 exclusion in shouldTrustReasoningContentReplayMetadata before serialization).

    Setup: Gemma-4-12B (NVFP4) on vLLM 0.22, api: openai-completions, compat.thinkingFormat: openai, reasoning: true. A TCP tee between OpenClaw and vLLM captured the exact request bodies during openclaw agent --local --thinking high on a multi-step tool task.

    Observed on the wire (deepest request, in-turn assistant tool-call turns):

    build reasoning_content present non-empty (real text)
    v2026.6.1 0 / 3 (absent) 0 / 3
    v2026.6.5-beta.5, requiresReasoningContentOnAssistantMessages: true 8 / 8 0 / 8 — all ""

    In both cases tool_calls are structured and tool-call/result IDs match exactly — only reasoning_content is missing/empty. The beta+flag result confirms the empty-field path is the API-compat placeholder, not a restore of real reasoning, consistent with the Gemma-4 shouldTrustReasoningContentReplayMetadata returning false.

    Expected vs actual:

    • Expected: in-turn assistant tool-call messages (after the last user turn) carry the model's real reasoning_content, so the Gemma 4 chat template can re-inject it as <|channel>thought…<channel|>.
    • Actual: the field is stripped (6.1) or empty (beta+flag); over several turns the model re-derives, tool arguments occasionally collapse to {}, and identical tool calls repeat.

    On the product decision: your proposed boundary — keep completed-turn Gemma reasoning stripped, add a narrow same-turn tool-call replay exception when the provider emitted a replayable reasoning field — matches what the Gemma 4 template already assumes (its re-injection is gated to messages after the last user turn). I'm happy to re-run the tee capture against a candidate fix to confirm reasoning_content lands non-empty on the in-turn path.

    @clawsweeper re-review

  5. clawsweeper commented on Jun 9, 2026

    @clawsweeper
    Contributor

    🦞🧹
    ClawSweeper re-review requested.

    I asked ClawSweeper to review this item again.
    Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
    Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

    Re-review progress:

  6. self-assigned this
    on Jun 10, 2026
  7. locked as resolved and limited conversation to collaborators on Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Normal backlog priority with limited blast radius.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions