Skip to content

fix(llm): gate OpenAI-compatible reasoning output - #89436

Merged
steipete merged 2 commits into
mainfrom
fix/89343-reasoning-output
Jun 2, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/89343-reasoning-output

Conversation

@steipete

@steipete steipete commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replaces fix(llm): prevent reasoning_content leak when reasoning is disabled #89343 because the contributor fork does not allow maintainer pushes.
  • Keeps OpenAI-compatible mirrored reasoning fields as strict reasoning-tag partition signals, but only emits thinking blocks when the effective reasoning request is enabled.
  • Covers both the legacy completions stream and the transport stream, including enabled OpenRouter/Qwen/Z.ai-style reasoning and disabled hidden-reasoning drops.

Verification

Behavior addressed: OpenAI-compatible providers that mirror hidden reasoning no longer leak disabled reasoning into visible output or thinking blocks, while enabled provider-native thinking still emits.
Real environment tested: local OpenClaw targeted unit/agent tests and type/format gates in a normal source checkout.
Exact steps or command run after this patch: node ./node_modules/.bin/oxfmt --check src/llm/providers/openai-completions.ts src/llm/providers/openai-completions.test.ts src/agents/openai-transport-stream.ts src/agents/openai-transport-stream.test.ts && git diff --check; node scripts/run-vitest.mjs src/llm/providers/openai-completions.test.ts src/agents/openai-transport-stream.test.ts; pnpm check:test-types; .agents/skills/autoreview/scripts/autoreview --mode local
Evidence after fix: provider tests passed 17/17; transport tests passed 237/237; test type gate passed; formatter/diff check passed; autoreview reported no accepted/actionable findings.
Observed result after fix: disabled mirrored reasoning is stripped without recovering hidden text, enabled reasoningEffort/OpenRouter/Qwen/Z.ai cases still emit thinking deltas, and transport buffering does not persist disabled thinking deltas after tool calls.
What was not tested: no live external provider call was run for this replacement PR.

Co-authored-by: zz327455573 [email protected]

zz327455573 and others added 2 commits June 2, 2026 04:50
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 agents Agent runtime and tooling size: M maintainer Maintainer-authored PR 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, 8:23 AM ET / 12:23 UTC.

Summary
The PR gates OpenAI-compatible mirrored reasoning output in the legacy completions parser and transport stream, with regression coverage for disabled hidden-reasoning drops and enabled provider-native thinking.

PR surface: Source +35, Tests +257. Total +292 across 4 files.

Reproducibility: yes. A synthetic OpenAI-compatible stream with content containing an unclosed reasoning tag followed by reasoning_content while reasoning is off exercises the leak path; I did not run it because this review is read-only, but the current parser and added regression tests make the path clear.

Review metrics: 1 noteworthy metric.

  • OpenAI-compatible parser coverage: 2 parser paths covered. The replacement now touches both the legacy provider parser and the boundary-aware transport parser that share the mirrored reasoning invariant.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🌊 off-meta tidepool
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

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

Rank-up moves:

  • [P2] Add redacted live affected-provider or gateway output before merge if maintainers want to satisfy the external API proof policy.

Risk before merge

  • [P1] No live affected-provider or gateway run is included, so the security-sensitive hidden-reasoning boundary is proven by local parser tests and loopback-style fixtures rather than by real OpenRouter/Qwen/Z.ai/MiMo traffic.
  • [P1] The PR carries the protected maintainer label, so cleanup automation should not close or land it without explicit maintainer handling.

Maintainer options:

  1. Add live hidden-reasoning proof before merge (recommended)
    Capture a redacted affected-provider or gateway run showing disabled mirrored reasoning is not emitted and enabled native thinking still streams.
  2. Accept targeted parser coverage as maintainer-owned proof
    Maintainers can choose to merge on the local regression tests and own the remaining live-provider proof gap after landing.
  3. Pause if provider behavior cannot be demonstrated
    If the affected response shapes cannot be reproduced against a real provider, hold the PR until the upstream behavior is clearer.

Next step before merge

  • [P1] A maintainer should decide whether the local regression proof is enough for this protected, security-sensitive provider parsing change or require live affected-provider proof first.

Security
Needs attention: The code diff did not show a concrete introduced security bug, but the hidden-reasoning boundary is security-sensitive and lacks live affected-provider proof.

Review details

Best possible solution:

Land the two-parser gating approach after maintainer review, ideally with one redacted live affected-provider or gateway proof showing disabled mirrored reasoning is dropped while enabled native thinking still emits.

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

Yes. A synthetic OpenAI-compatible stream with content containing an unclosed reasoning tag followed by reasoning_content while reasoning is off exercises the leak path; I did not run it because this review is read-only, but the current parser and added regression tests make the path clear.

Is this the best way to solve the issue?

Yes, with a proof caveat. The best code shape is to keep mirrored reasoning fields as strict partition signals and gate only emitted thinking output across both parser paths; the remaining gap is live affected-provider proof, not a different implementation layer.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P1: Hidden reasoning leakage affects a real agent/provider workflow and the fix is security-sensitive, but the blast radius is limited to OpenAI-compatible reasoning parsing.
  • add merge-risk: 🚨 security-boundary: Merging this PR changes the boundary between hidden reasoning fields and user-visible output, and green CI does not prove real provider response shapes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The PR is maintainer-labeled, so the external contributor real-behavior-proof gate is not applied; the body includes local parser/test proof but no live provider run.

Label justifications:

  • P1: Hidden reasoning leakage affects a real agent/provider workflow and the fix is security-sensitive, but the blast radius is limited to OpenAI-compatible reasoning parsing.
  • merge-risk: 🚨 security-boundary: Merging this PR changes the boundary between hidden reasoning fields and user-visible output, and green CI does not prove real provider response shapes.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The PR is maintainer-labeled, so the external contributor real-behavior-proof gate is not applied; the body includes local parser/test proof but no live provider run.
Evidence reviewed

PR surface:

Source +35, Tests +257. Total +292 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 39 4 +35
Tests 2 266 9 +257
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 305 13 +292

Security concerns:

  • [medium] Live hidden-reasoning proof is missing
    The PR changes whether mirrored reasoning fields become visible thinking output, and the body explicitly says no live external provider call was run, leaving provider response-shape proof for this security boundary to maintainer judgment.
    Confidence: 0.74

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/llm/providers/openai-completions.test.ts src/agents/openai-transport-stream.test.ts.
  • [P1] pnpm check:test-types.
  • [P1] node ./node_modules/.bin/oxfmt --check src/llm/providers/openai-completions.ts src/llm/providers/openai-completions.test.ts src/agents/openai-transport-stream.ts src/agents/openai-transport-stream.test.ts && git diff --check.
  • [P1] redacted live affected-provider or OpenClaw gateway run with reasoning disabled and enabled cases.

What I checked:

  • Repository policy read: Root AGENTS.md and scoped src/agents/AGENTS.md were read fully; the review applied the rules requiring whole-path PR review, scoped guidance, security-sensitive reasoning handling, and live external API proof awareness. (AGENTS.md:1, 6467ddd7edf1)
  • Current legacy parser behavior: Current main scans reasoning_content/reasoning/reasoning_text, marks the partitioner strict when mirrored reasoning appears, and then emits a thinking block from the mirrored field; the PR keeps detection and gates only the emission. (src/llm/providers/openai-completions.ts:367, 6467ddd7edf1)
  • Current transport parser behavior: Current main's transport stream extracts mirrored reasoning deltas, marks strict mode, and emits thinking deltas; the PR threads an emitReasoning option into this parser and drops thinking deltas when the effective reasoning request is disabled. (src/agents/openai-transport-stream.ts:2890, 6467ddd7edf1)
  • Reasoning request contract: The transport defaults OpenAI-compatible completions reasoning to high unless the caller explicitly passes off/none, and the existing helper treats off/none as disabled reasoning; the PR's gate follows that effective-state boundary. (src/agents/openai-transport-stream.ts:3420, 6467ddd7edf1)
  • Outgoing completions payload contract: Current main resolves OpenAI-compatible completion reasoning effort, maps provider-native Qwen/Together/OpenRouter parameters, and sends native reasoning controls from the same effective effort that the PR uses for emission gating. (src/agents/openai-transport-stream.ts:4111, 6467ddd7edf1)
  • PR diff coverage: The PR diff adds the legacy emission guard, an emitReasoning gate in processOpenAICompletionsStream, helper exposure for tests, and regression tests for disabled mirrored reasoning plus enabled Qwen/Z.ai/OpenRouter-style thinking. (src/agents/openai-transport-stream.ts:2588, 0d87f0dddccc)

Likely related people:

  • steipete: Recent public history shows multiple merged commits touching OpenAI-compatible reasoning, streamed reasoning tags, and model inference edge cases in the affected files; this PR is also on the maintainer-labeled replacement branch. (role: recent area contributor; confidence: high; commits: 9ead0ae9219e, b23ace1d04ca, cf315ddef69f; files: src/agents/openai-transport-stream.ts, src/llm/providers/openai-completions.ts)
  • MonkeyLeeT: Recent public history credits MonkeyLeeT with the OpenAI-compatible stop-finished tool-call fix that touched both affected parser/test surfaces and used the same focused validation files. (role: recent adjacent contributor; confidence: medium; commits: 6316648babc7; files: src/agents/openai-transport-stream.ts, src/llm/providers/openai-completions.ts)
  • vincentkoc: Local git blame in this checkout attributes the current reasoning-field parser lines in both affected files to Vincent Koc's commit, though the checkout history is shallow so this is a routing signal rather than full authorship proof. (role: current checkout blame owner; confidence: medium; commits: a682e6481382; files: src/agents/openai-transport-stream.ts, src/llm/providers/openai-completions.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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jun 2, 2026
@steipete

steipete commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready proof for head 0d87f0d:

  • Local formatter/diff: node ./node_modules/.bin/oxfmt --check src/llm/providers/openai-completions.ts src/llm/providers/openai-completions.test.ts src/agents/openai-transport-stream.ts src/agents/openai-transport-stream.test.ts && git diff --check
  • Local focused tests: node scripts/run-vitest.mjs src/llm/providers/openai-completions.test.ts src/agents/openai-transport-stream.test.ts (17 provider tests, 237 transport tests)
  • Local type gate: pnpm check:test-types
  • Local autoreview: .agents/skills/autoreview/scripts/autoreview --mode local reported no accepted/actionable findings
  • GitHub exact-head CI: all required/relevant checks green, including CI, Real behavior proof, CodeQL/Security High, OpenGrep, dependency guard, workflow sanity, Socket, and selected Critical Quality

This replaces #89343 because the contributor fork has maintainer edits disabled; contributor credit is preserved via Co-authored-by: zz327455573 <[email protected]>.

@steipete
steipete merged commit 06434d8 into main Jun 2, 2026
212 of 222 checks passed
@steipete
steipete deleted the fix/89343-reasoning-output branch June 2, 2026 12:24
@zz327455573

Copy link
Copy Markdown
Contributor

Thanks for recreating the fix and preserving the credit. Learned a lot from this process. Glad to see the issue resolved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants