Skip to content

fix(llm): prevent reasoning_content leak when reasoning is disabled - #89343

Closed
zz327455573 wants to merge 1 commit into
openclaw:mainfrom
zz327455573:fix-mimo-thinking-leak
Closed

zz327455573 wants to merge 1 commit into
openclaw:mainfrom
zz327455573:fix-mimo-thinking-leak

Conversation

@zz327455573

@zz327455573 zz327455573 commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Type of Change
​[x] Bugfix (non-breaking change which fixes an issue)
​Issue / Problem Description
​When using reasoning: false with specific models, reasoning_content is still returned in streaming deltas. The previous generic parser bypassed the entire loop, which unintentionally broke the markStrict() security boundaries.
​Behavior
​Leaked CoT (Chain of Thought) data in chunk deltas despite model.reasoning being explicitly disabled.
​Environment
​OpenClaw gateway proxy
​Upstream models supporting reasoning (e.g., OpenRouter/Qwen3)
​Real Behavior Proof
​Before Fix (Leaked Data):data: {"id":"chatcmpl-123","object":"chat.completion.chunk","choices":[{"delta":{"reasoning_content":"leaked_internal_thinking_text","content":null}}]}
After Fix (Clean Output):data: {"id":"chatcmpl-124","object":"chat.completion.chunk","choices":[{"delta":{"content":"Standard response without thinking leakage"}}]}
Fix Implementation Details
​src/llm/providers/openai-completions.ts: Restored the main loop and markStrict() triggering logic to preserve the security boundary. Added gating logic exclusively inside appendThinkingDelta output.
​src/agents/openai-transport-stream.ts: Implemented parallel output gating control on the transport stream layer using model.reasoning ?? true to prevent false positives during unit tests and block reasoning content appropriately.

Some models (e.g., MiMo V2.5 Pro) return reasoning_content in streaming
deltas even when reasoning is explicitly disabled. The generic
openai-completions provider was extracting and processing these fields
unconditionally, causing internal thinking to leak into the final output.

Added a reasoningEnabled guard before iterating through reasoningFields.
When reasoning is off, the fields are ignored and stripped from the
normal content flow.
@openclaw-barnacle openclaw-barnacle Bot added size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 2, 2026
@clawsweeper

clawsweeper Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 2, 2026, 6:55 AM ET / 10:55 UTC.

Summary
The PR adds a model.reasoning and options.reasoningEffort guard around OpenAI-compatible streaming reasoning-field detection in src/llm/providers/openai-completions.ts.

PR surface: Source +3. Total +3 across 1 file.

Reproducibility: yes. for the PR regression by source inspection: the existing late-mirrored-reasoning test would stop calling markStrict() with the patch and can recover private <think> content as visible text. The original external-provider report still lacks real provider or gateway proof.

Review metrics: 1 noteworthy metric.

  • Reasoning parser coverage: 1 changed, 1 sibling unchanged. The PR changes the legacy OpenAI completions parser while the boundary-aware OpenAI completions transport remains a user-facing gateway path for the same reasoning fields.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🧂 unranked krab
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Revise the parser so reasoning fields still trigger strict partitioning while disabled reasoning output is dropped.
  • [P1] Apply the same effective reasoning gate to the boundary-aware openai-completions transport or prove that path cannot handle the affected gateway traffic.
  • [P1] Update the PR body with redacted real affected-provider or OpenClaw gateway after-fix output, with secrets, IPs, phone numbers, and private endpoints removed.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR body contains synthetic SSE examples, not redacted after-fix output from a real affected provider or OpenClaw gateway run; the contributor should update the PR body with redacted terminal/live output, logs, or an artifact and ask for @clawsweeper re-review if it does not rerun automatically.

Risk before merge

  • [P1] The guard skips markStrict() whenever reasoning output is disabled, so split <think> content paired with later reasoning fields can be recovered as visible text.
  • [P1] The gateway and boundary-aware OpenAI completions transport still parses reasoning deltas without a matching effective-reasoning gate, so the affected proxy path described in the PR body is not covered.
  • [P1] The PR body shows synthetic SSE snippets rather than redacted after-fix output from a real affected provider or OpenClaw gateway run.

Maintainer options:

  1. Fix detection and transport before merge (recommended)
    Keep reasoning-field detection active for strict partitioning while dropping disabled thinking output, and apply the same effective-state rule to the boundary-aware OpenAI completions transport.
  2. Accept a narrow legacy-only mitigation
    Maintainers could intentionally accept that this only changes the legacy provider parser, but then the gateway proxy risk called out by the PR body remains owned separately.
  3. Pause until real provider proof exists
    If the affected provider behavior cannot be demonstrated, hold the PR until redacted gateway or provider output shows the before and after path.

Next step before merge

  • [P1] Contributor revision and redacted real affected-provider or gateway proof are needed; automation should not repair around missing external setup proof for this external PR.

Security
Needs attention: The diff is security-sensitive because it changes hidden reasoning handling, and the current guard can reintroduce visible reasoning leakage while leaving the gateway transport path uncovered.

Review findings

  • [P1] Keep strict detection when dropping reasoning output — src/llm/providers/openai-completions.ts:369-371
  • [P1] Cover the boundary-aware transport parser — src/llm/providers/openai-completions.ts:369
Review details

Best possible solution:

Keep mirrored reasoning fields as a sanitization signal, gate only emitted thinking output using the effective request state, cover both legacy and boundary-aware transport parsers, and require redacted real provider or gateway proof before merge.

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

Yes for the PR regression by source inspection: the existing late-mirrored-reasoning test would stop calling markStrict() with the patch and can recover private <think> content as visible text. The original external-provider report still lacks real provider or gateway proof.

Is this the best way to solve the issue?

No. The patch is a plausible mitigation, but the best fix should keep reasoning-field detection for sanitization, gate only output emission, and cover the boundary-aware transport path used by the gateway.

Full review comments:

  • [P1] Keep strict detection when dropping reasoning output — src/llm/providers/openai-completions.ts:369-371
    Wrapping the reasoning-field scan in if (reasoningEnabled) means a stream that sends <think>private reasoning before a later reasoning_content chunk no longer calls markStrict(). The existing regression test for late mirrored reasoning relies on that marker; with this patch the buffered private text can be recovered as visible output instead of being suppressed. Continue detecting mirrored reasoning for strict routing, and gate only the emitted thinking block.
    Confidence: 0.91
  • [P1] Cover the boundary-aware transport parser — src/llm/providers/openai-completions.ts:369
    The PR body says the leak is in the OpenClaw gateway proxy, but current embedded/gateway OpenAI-compatible streams can route through createOpenAICompletionsTransportStreamFn(), whose parser still extracts reasoning_content, reasoning, and reasoning_text without an effective reasoning-off gate. A legacy-provider-only guard leaves the named gateway path unprotected.
    Confidence: 0.87

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P1: The PR attempts to fix hidden reasoning leakage in an agent/gateway workflow but can reintroduce a security-boundary leak and misses the named gateway path.
  • merge-risk: 🚨 security-boundary: Merging the guard as written can let hidden reasoning-tag content become visible when mirrored reasoning arrives after an unclosed tag.
  • merge-risk: 🚨 compatibility: The change alters OpenAI-compatible reasoning parsing behavior without covering the sibling transport path or preserving existing strict-routing tests.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body contains synthetic SSE examples, not redacted after-fix output from a real affected provider or OpenClaw gateway run; the contributor should update the PR body with redacted terminal/live output, logs, or an artifact and ask for @clawsweeper re-review if it does not rerun automatically.
Evidence reviewed

PR surface:

Source +3. Total +3 across 1 file.

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

Security concerns:

  • [high] Strict reasoning sanitization can be bypassed — src/llm/providers/openai-completions.ts:369
    The added guard prevents the parser from seeing mirrored reasoning fields when output is disabled, so split reasoning-tag content can be recovered into visible text instead of being treated as hidden reasoning.
    Confidence: 0.91

What I checked:

  • Changed guard would skip strict reasoning detection: Current main always scans reasoning_content, reasoning, and reasoning_text, then calls reasoningTagTextPartitioner.markStrict() when a mirrored reasoning field is present; the PR patch wraps that scan behind Boolean(model.reasoning && options?.reasoningEffort). (src/llm/providers/openai-completions.ts:362, eb417bc672e6)
  • Existing regression test depends on late mirrored reasoning marking strict mode: The existing test does not recover unclosed reasoning tags when mirrored reasoning arrives later streams <think>private reasoning first and reasoning_content later, expecting no visible text and a thinking block; the PR's guard would leave foundReasoningField null and can recover the buffered private text as visible output. (src/llm/providers/openai-completions.test.ts:329, eb417bc672e6)
  • Boundary-aware gateway transport is a sibling affected path: OpenAI-compatible models route through createOpenAICompletionsTransportStreamFn() for boundary-aware transport, and that transport's parser still extracts reasoning deltas from the same fields without the PR's gate. (src/agents/provider-transport-stream.ts:80, eb417bc672e6)
  • Transport parser extracts the same reasoning fields: getCompletionsReasoningDeltas() reads reasoning_details, then reasoning_content, reasoning, and reasoning_text; the PR body names the OpenClaw gateway proxy, but the current patch does not touch this path. (src/agents/openai-transport-stream.ts:3261, eb417bc672e6)
  • Docs make thinking-off behavior user-visible: The thinking docs describe /think off and provider-specific disabled reasoning payload behavior, so changes to reasoning output and strict sanitization are user-visible and compatibility-sensitive. Public docs: docs/tools/thinking.md. (docs/tools/thinking.md:32, eb417bc672e6)
  • History provenance for current reasoning parser: Blame attributes the current reasoning-field scan and transport reasoning parser in this checkout to commit 4df832412e4924a9c2452bc126481aa123d02b0f, giving a routing signal for the relevant code path. (src/llm/providers/openai-completions.ts:362, 4df832412e49)

Likely related people:

  • vincentkoc: Git blame in this checkout attributes both the current OpenAI-compatible reasoning-field scan and the sibling transport reasoning parser to Vincent Koc's commit, so this is the best routing signal available from local history. (role: recent area contributor; confidence: medium; commits: 4df832412e49; files: src/llm/providers/openai-completions.ts, src/agents/openai-transport-stream.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

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.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jun 2, 2026
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Jun 2, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jun 2, 2026
@zz327455573
zz327455573 force-pushed the fix-mimo-thinking-leak branch 4 times, most recently from 6764bee to e78b1b7 Compare June 2, 2026 08:53
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. labels Jun 2, 2026
@zz327455573
zz327455573 force-pushed the fix-mimo-thinking-leak branch 2 times, most recently from ad298c2 to d65a96a Compare June 2, 2026 10:48
@openclaw-barnacle openclaw-barnacle Bot removed the agents Agent runtime and tooling label Jun 2, 2026
@steipete steipete self-assigned this Jun 2, 2026
@zz327455573 zz327455573 closed this Jun 2, 2026
steipete added a commit that referenced this pull request Jun 2, 2026
Replaces #89343 because the contributor fork did not allow maintainer edits.

Co-authored-by: zz327455573 <[email protected]>
@steipete

steipete commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Thanks for the report and initial patch. I could not push fixups to this branch because maintainer edits are disabled, so I recreated the fix in #89436, preserved contributor credit, and landed it on main as 06434d8.

The landed fix keeps mirrored reasoning fields as strict sanitization signals, drops disabled hidden reasoning from both legacy and transport OpenAI-compatible streams, and preserves enabled provider-native thinking paths. For future PRs, enabling "Allow edits by maintainers" lets us patch the original branch directly.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 3, 2026
Replaces openclaw#89343 because the contributor fork did not allow maintainer edits.

Co-authored-by: zz327455573 <[email protected]>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Replaces openclaw#89343 because the contributor fork did not allow maintainer edits.

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

Labels

merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants