Repository navigation
fix(openrouter): prevent Kimi tool-schema rejection without losing alternatives - #110138
fuller-stack-dev merged 14 commits into
Conversation
…d providers Models routed through OpenRouter inherit no tool schema normalization, so providers that reject anyOf/oneOf (Moonshot/Kimi, DeepSeek, Google) receive raw schemas and return 400. Route model prefixes to the matching tool compat family, mirroring ClawRouter's resolveToolFamily. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Codex review: blocked before merge. Reviewed September 16, 2026, 11:46 PM ET / September 17, 2026, 03:46 UTC (Revision 23). ClawSweeper reviewWhat this changesThe OpenRouter plugin adapts Kimi tool schemas while preserving valid argument alternatives and adds regression coverage for schema constraints and model aliases. Merge readiness⛔ Blocked before merge - 2 items remain This remains a useful, actively maintained fix that current main does not provide. Earlier alias and union-preservation concerns are resolved, and no blocking code defect was found. Priority: P1 Review scores
Verification
How this fits togetherOpenClaw passes tool definitions through the selected provider plugin before sending them to a model. This change adjusts schemas for Moonshot models reached through OpenRouter, allowing tool calls to proceed without discarding valid arguments. flowchart LR
A[Agent and MCP tools] --> B[Provider schema hook]
C[Selected OpenRouter model] --> B
B --> D{Moonshot family?}
D -->|Yes| E[Preserve constraints and distribute type]
D -->|No| F[Keep existing schemas]
E --> G[OpenRouter transport]
F --> G
G --> H[Tool calls and result replies]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +141, Tests +232. Total +373 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the constraint-preserving adaptation in the existing OpenRouter hook, preserve other provider routes, and complete the already-required integrated-head confirmation. Do we have a high-confidence way to reproduce the issue? Yes: the reported parent-type/untyped-anyOf shape follows a clear provider path without the required transformation on main, supported by historical rejection evidence. This read-only review did not execute a fresh failing request. Is this the best way to solve the issue? Yes: the existing provider hook is the appropriate boundary, and the conservative rewrite preserves acceptance rather than applying another provider's lossy reduction. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ee9c66631244. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (22 earlier review cycles; latest 8 shown)
|
…ection Canonical OpenRouter model IDs arrive as `openrouter/moonshotai/kimi-k3` with the provider prefix, which bypasses the prefix-based tool family routing. Use normalizeOpenRouterApiModelId to strip the prefix before family selection, matching how the rest of the extension handles model IDs. Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Add braces to if statements to satisfy eslint(curly) rule - Cast TSchema to Record in test assertions to fix TS2339 Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
@clawsweeper re-review Current head: 50 existing wrapper tests and 34 schema cases passed; the final integration adds four passing Slack approval/quiet-stream cases for an inherited CI prerequisite. Fresh complete-candidate isolated P0–P2 review is scoped-clean. The PR body now includes real proxied OpenRouter acceptance of both string/red and integer/blue values and tool-result round trips (four HTTP200 requests). All OpenRouter input hashes are unchanged at this head; its fresh exact-head confirmation and CI are running, and the body will record their results. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review Current head: The maintainer resolution is to preserve existing non-Moonshot behavior, not to introduce a new proxy tradeoff. Current-head CI and native preparation are running/pending. The prepared920 head completed actual OpenRouter two-alternative acceptance with fourHTTP200 responses and wrapper exit0, and its lease is stopped; that result remains historical. New final prepared-head acceptance will be recorded before native merge, with no waiver of that gate. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review Final prepared-head acceptance is now recorded directly in the PR body for unchanged The bounded redacted native receipt is inline in the PR body, so it can be inspected without accessing the restricted artifact-storage host. This is the new final-head execution, not reused920/nativeMoonshot evidence. Its lease is stopped and temporary clone absent. Source is unchanged; please refresh the remaining proof-only findings against the now-present evidence. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
Merged via squash.
|
…ternatives (openclaw#110138) * fix(openrouter): add model-aware tool schema normalization for proxied providers Models routed through OpenRouter inherit no tool schema normalization, so providers that reject anyOf/oneOf (Moonshot/Kimi, DeepSeek, Google) receive raw schemas and return 400. Route model prefixes to the matching tool compat family, mirroring ClawRouter's resolveToolFamily. Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix(openrouter): normalize canonical model IDs before tool family selection Canonical OpenRouter model IDs arrive as `openrouter/moonshotai/kimi-k3` with the provider prefix, which bypasses the prefix-based tool family routing. Use normalizeOpenRouterApiModelId to strip the prefix before family selection, matching how the rest of the extension handles model IDs. Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix(openrouter): add curly braces and fix test type errors - Add braces to if statements to satisfy eslint(curly) rule - Cast TSchema to Record in test assertions to fix TS2339 Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix(openrouter): preserve schema routing for model aliases * fix(slack): forward approval callbacks without growing dispatch * test(qwen): freeze the clock for request-shape assertions * refactor(openrouter): preserve schema branches with explicit iteration * fix(openrouter): keep proxy schema normalization Moonshot-local --------- Co-authored-by: Lennart Lopin <[email protected]> Co-authored-by: Claude Opus 4.6 <[email protected]> Co-authored-by: Jason (Json) <[email protected]>
What Problem This Solves
Fixes supported Kimi/Moonshot tool-schema rejection through OpenRouter without discarding valid tool argument alternatives.
User Impact
Kimi tools retain meaningful string/integer and nullable/literal alternatives. Canonical, qualified, and tilde-prefixed Moonshot model references work with the existing replay, thinking, and stream wrappers. No configuration migration is needed.
Why This Change Was Made
The provider-local normalizer distributes a parent type only where that preserves JSON Schema acceptance, retaining every branch and all other parent constraints. Unknown types, references, boolean branches, incompatible types, and nested unions remain unchanged. It traverses schema locations only, preserving annotation values and own
__proto__keys.Other OpenRouter model families retain their existing schemas and tool identity. The earlier proposal to apply native DeepSeek/Gemini reductions through the proxy was removed after review: that tradeoff lacked route-specific evidence. Shared DeepSeek and native Moonshot production policies are unchanged.
The original OpenRouter contribution and reproduction are by @novalis78 (Lennart Lopin); contributor ancestry is preserved. The constraint-preserving native Moonshot work in #113462 by @harjothkhara informed this repair, but native-provider evidence is not OpenRouter acceptance.
Evidence
6ebfe0c9a5c727393da6d54dae91a7badbc8bee4. The Qwen integration conflict is resolved to exact main; only three OpenRouter files remain. No Slack or Qwen delta.Current prepared-head runtime receipt
The registered OpenRouter plugin, current stream wrappers, and production OpenAI-completions transport called OpenRouter—not native Moonshot or a mocked endpoint. The wrapper verified the full source/tree; the probe checked eight pins, the transmitted schema, and both returned arguments against original and normalized schemas. Bounded synthetic receipts are inline so no external artifact-storage access is required. Subsequent lease-cleanup cancellation of the Actions session does not change the successful native command result.
{ "head": "6ebfe0c9a5c727393da6d54dae91a7badbc8bee4", "tree": "c00e0f15497d540bbb28ee2b8ec726ab366a014a", "normalizedSchemaSha256": "fb78ac1a7fcef430902ef4028f11c2e2e293edf21ca6e611e1ffe108357c2b2d", "proofScriptSha256": "ee6f61a2e35c6c46366a989ad0f2ed8585b96583565b3dc286b217ce4af364e8", "provider": "openrouter", "model": "moonshotai/kimi-k3", "endpoint": "https://openrouter.ai/api/v1", "outcomes": [ { "expected": { "value": "hello", "color": "red" }, "actual": { "value": "hello", "color": "red" }, "httpStatus": 200, "roundTripHttpStatus": 200, "wireToolsSha256": "5a5c20564747de67617dffc0e0b436c5a6cd692599bffea4b7df2937f34f2b50", "toolExecuted": true, "roundTrip": "stop" }, { "expected": { "value": 7, "color": "blue" }, "actual": { "value": 7, "color": "blue" }, "httpStatus": 200, "roundTripHttpStatus": 200, "wireToolsSha256": "5a5c20564747de67617dffc0e0b436c5a6cd692599bffea4b7df2937f34f2b50", "toolExecuted": true, "roundTrip": "stop" } ], "http200Count": 4, "nativeWrapperExit": 0, "nativeSourceAndTreeVerified": true, "finishedAt": "2026-09-17T03:58:01.906066+00:00" }The schema retains both constrained string/integer branches and the red/blue alternatives. Native Moonshot #113462 was an implementation lead only. The Slack prerequisites landed in #111148, and #150482 was closed as verified superseded. The contributor’s original unpatched Gateway rejection and ten-call older build reproduction establish the failure path; this current prepared-head receipt independently establishes proxy acceptance after the repair.