Skip to content

fix(ai): fold case in OpenAI reasoning-effort matching (#102908) - #102958

Closed
ObliviateRickLin wants to merge 1 commit into
openclaw:mainfrom
ObliviateRickLin:fix/openai-reasoning-effort-case-102908
Closed

ObliviateRickLin wants to merge 1 commit into
openclaw:mainfrom
ObliviateRickLin:fix/openai-reasoning-effort-case-102908

Conversation

@ObliviateRickLin

@ObliviateRickLin ObliviateRickLin commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

normalizeOpenAIReasoningEffort (packages/ai/src/providers/openai-reasoning-effort.ts) passes effort names through unchanged, and readCompatReasoningEfforts keeps user-authored compat.supportedReasoningEfforts entries as written. So a mixed-case requested effort ("High") or a mixed-case compat entry ("Low") fails the lowercase .includes() matching in resolveOpenAIReasoningEffortForModel / supportsOpenAIReasoningEffort. The miss doesn't fail loudly — it silently falls through the support ladder and returns a different effort than the one the model actually supports (e.g. requested low against a declared ["Low","MEDIUM","High"] mis-ladders to another tier). Fixes #102908.

Why This Change Was Made

Fold case on both sides of the boundary, using the normalization helpers this package already imports: normalizeOpenAIReasoningEffort now lowercases (efforts are matched against lowercase lists and sent to the API lowercase), and compat lists use the existing normalizeStringEntriesLower sibling helper. Disabled semantics ("None"/"OFF") also work case-insensitively instead of falling through the ladder into an enabled effort. No new options or API surface; internal lowercase callers are byte-for-byte unaffected.

User Impact

Operators writing reasoningEffort/supportedReasoningEfforts values in config with any casing get the effort they asked for, instead of a silently substituted tier (which changes model behavior and cost).

Evidence

Live OpenAI-compatible request run (wire capture, full recipe in PR comment): real agent turn via pnpm openclaw agent --local --thinking high against a local OpenAI-compatible endpoint with user-authored mixed-case compat.supportedReasoningEfforts: ["Low","MEDIUM","High"]:

BEFORE (main):    POST /v1/chat/completions  → "reasoning_effort": "Low"    ← asked high, silently mis-laddered
AFTER  (this PR): POST /v1/chat/completions  → "reasoning_effort": "high"   ← correct tier and case

Two new regression tests fail on current main and pass with this PR:

main:    × matches mixed-case requested efforts     — expected 'low' to be 'high'   (mis-laddered)
         × folds case in compat-declared efforts    — ['Low','MEDIUM','High'] ≠ ['low','medium','high']
this PR: 12/12 pass

Consumer suites checked: openai-responses-shared.test.ts green; stream-wrappers/openai.test.ts has 2 pre-existing local failures (Codex attribution/user-agent, fail identically with main's reasoning-effort file — verified unrelated). oxfmt/oxlint clean.

normalizeOpenAIReasoningEffort passed effort names through unchanged, and
readCompatReasoningEfforts kept user-authored compat entries as written, so a
mixed-case requested effort ("High") or compat list entry ("Low") failed the
lowercase .includes() matching in resolveOpenAIReasoningEffortForModel /
supportsOpenAIReasoningEffort. A miss does not fail loudly — it silently falls
through the support ladder and returns a different effort than the one the model
actually supports.

Lowercase both sides at the boundary: normalizeOpenAIReasoningEffort now folds
case (efforts are matched and sent to the API lowercase), and compat lists use
normalizeStringEntriesLower. Disabled semantics ("None"/"OFF") keep working
case-insensitively as well.
@clawsweeper

clawsweeper Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded: the useful mixed-case reasoning-effort fix is now covered by the newer open PR with sufficient request-path proof, while this branch still has a provider-native compatibility bug.

Root-cause cluster
Relationship: superseded
Canonical: #102993
Summary: This PR and the newer open PR target the same mixed-case OpenAI reasoning-effort bug, but the newer PR preserves provider-native values and has positive proof, making it the safer canonical landing path.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Use #102993 as the landing path for #102908, because it fixes canonical effort casing without rewriting provider-native payload labels.

So I’m closing this here and keeping the remaining discussion on #102993 and #102908.

Review details

Best possible solution:

Use #102993 as the landing path for #102908, because it fixes canonical effort casing without rewriting provider-native payload labels.

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

Yes. Source inspection shows current main leaves mixed-case canonical efforts unchanged before exact supported-list matching, and the contributor added live before/after request output for the changed path; I did not execute tests in this read-only review.

Is this the best way to solve the issue?

No. The goal is valid, but this branch lowercases provider-native compat values; the better solution is the narrower open PR that folds canonical names while preserving configured API labels.

Security review:

Security review cleared: The diff only changes in-repo TypeScript normalization logic and focused tests; it adds no dependency, workflow, secret, package, or code-execution surface.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • steipete: Blame on the current reasoning-effort helper and resolver points to Peter Steinberger's commit that extracted this package-level OpenAI reasoning logic. (role: introduced current helper and recent area contributor; confidence: high; commits: f8dbd34ab8e8; files: packages/ai/src/providers/openai-reasoning-effort.ts, packages/ai/src/providers/openai-reasoning-effort.test.ts)
  • vincentkoc: History shows Vincent Koc added the OpenAI reasoning compatibility helper and the transport seam that consumes reasoningEffortMap. (role: adjacent reasoning-compat contributor; confidence: medium; commits: 5ddca5dd56e9, 4798e125f40c; files: src/agents/openai-reasoning-compat.ts, src/agents/openai-transport-stream.ts)

Codex review notes: model internal, reasoning high; reviewed against 745b8c315eaa.

@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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 9, 2026
@ObliviateRickLin

Copy link
Copy Markdown
Contributor Author

Live OpenAI-compatible request run (real setup, wire capture)

Stood up a real local OpenAI-compatible Chat Completions endpoint (the mixed-case scenario's home turf — self-hosted/vLLM-style deployments), configured OpenClaw against it, and drove a real agent turn through the built runtime CLI — once on main, once with this PR (root tsdown rebuild between runs).

Setup (fresh OPENCLAW_STATE_DIR, openclaw.json):

models.providers.openai: {
  baseUrl: "http://127.0.0.1:8090/v1", api: "openai-completions",
  request: { allowPrivateNetwork: true },
  models: [{ id: "test-effort-model", reasoning: true,
    compat: { supportsReasoningEffort: true,
              supportedReasoningEfforts: ["Low", "MEDIUM", "High"] } }]  // user-authored mixed case
}
agents.defaults.model.primary: "openai/test-effort-model"

Command (both runs):

OPENCLAW_STATE_DIR=… OPENAI_API_KEY=dummy pnpm openclaw agent --local --agent main \
  --message "ping" --thinking high --timeout 90

Both turns completed (run … ended with stopReason=stop). The endpoint logs each POST /v1/chat/completions body:

BEFORE — main:

{"url":"/v1/chat/completions","model":"test-effort-model","reasoning_effort":"Low","stream":true}

The operator asked for high; the mixed-case compat list fails .includes(), silently falls through the ladder, and the live request carries "Low" — wrong tier, wrong case, no error anywhere.

AFTER — this PR (same config, same command):

{"url":"/v1/chat/completions","model":"test-effort-model","reasoning_effort":"high","stream":true}

That is the user-visible bug and the fix on the wire: --thinking high now yields reasoning_effort: "high" against a config that declares efforts in mixed case. (Unit-level fails-on-main regression tests already in the PR; oxfmt/oxlint clean; tsgo 0 errors.)

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 9, 2026
@clawsweeper clawsweeper Bot closed this Jul 9, 2026
@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🦞✅
ClawSweeper autoclose is complete.

Reason: structured ClawSweeper close marker: close-required (sha=d7eee43717175eeb06fbb2f56b1419a0b8de95ae)

Closed:

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

Labels

merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS 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.

case-insensitive reasoning effort matching in resolveOpenAIReasoningEffortForModel

1 participant