Repository navigation
refactor(ai): unify OpenAI completions compatibility - #114236
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 26, 2026, 10:55 PM ET / July 27, 2026, 02:55 UTC. ClawSweeper reviewWhat this changesThe branch deletes the provider-local OpenAI Chat Completions compatibility matrix and makes provider, managed-transport, and plugin normalization use the transport-owned compatibility resolver. Merge readinessKeep this PR open for normal maintainer merge review. The supplied diff removes a duplicate compatibility authority and routes the provider adapter, managed transport, and plugin normalization through one resolver; the prior proof gap is addressed by a redacted real loopback HTTP/SSE run that exercised both request paths. The remaining concern is upgrade-sensitive endpoint behavior, so the current base should be refreshed and the named endpoint contracts should receive final owner review before merge. Priority: P2 Review scores
Verification
How this fits togetherOpenAI-compatible provider adapters and managed transports each translate model and endpoint attribution into request payload fields. The shared resolver sits between that attribution and request construction, affecting streaming payload compatibility, provider defaults, and plugin model metadata. flowchart LR
A[Model and endpoint attribution] --> B[Shared compatibility resolver]
B --> C[Provider adapter]
B --> D[Managed transport]
B --> E[Plugin model normalization]
C --> F[OpenAI-compatible request]
D --> F
E --> F
F --> G[Streaming response]
Decision needed
Why: This is a compatibility-sensitive ownership decision: the code removes a second authority and intentionally narrows some former provider-name heuristics, which cannot be resolved by mechanical repair alone. Before merge
Agent review detailsSecurityNone. PR surfaceSource -279, Tests +418. Total +139 across 6 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Rebase onto current main, retain one transport-owned compatibility resolver, and merge only after the endpoint-specific regression table confirms the former provider behavior is represented intentionally in the canonical policy. Do we have a high-confidence way to reproduce the issue? Not applicable: this is a refactor PR rather than a report of a separately reproducible bug. The supplied real runtime proof does exercise both affected request-construction paths against a loopback OpenAI-compatible SSE server. Is this the best way to solve the issue? Yes, conditionally: consolidating duplicated endpoint compatibility policy is the narrower maintainable fix, provided the canonical resolver keeps every intentional endpoint-specific contract and the current-main merge result is reviewed. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 570eab59e7c7. LabelsLabel changes:
Label 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
History |
|
Land-ready verification for head
Proof gap: credentialed OpenRouter/OpenAI live probes were unavailable because this Testbox workflow exposes neither key. No secret values were read or printed. The isolated real-network proof exercises both production request paths and directly addresses the ClawSweeper rank-up moves without widening credential scope. |
|
Merged via squash.
|
* refactor(ai): unify OpenAI completions compatibility * refactor(ai): make cache compat resolution explicit * fix(ai): keep ModelStudio token field canonical
What Problem This Solves
OpenAI-compatible Chat Completions compatibility was resolved by two independent authorities: a provider-owned matrix and the transport endpoint-capability policy. The copies had drifted, so the same model could emit different payload fields depending on which runtime path constructed the request.
Why This Change Was Made
This makes the transport-owned
detectOpenAICompletionsCompatpolicy the single detector and adds one shared resolver for explicit model overrides. Both provider and managed-transport callers now consume that resolver, core normalization uses the same result, and the provider matrix is deleted with no compatibility re-export. Endpoint-specific contracts retained in the canonical path include Moonshot and Cloudflare AI Gatewaymax_tokens, Together reasoning format, OpenRouter cache-control/session affinity, and native JSON Schema support.The former matrix's provider/URL cases are table-driven in the regression test. Exact matches remain exact; intentional differences are documented as the existing endpoint-capability policy replacing broader provider-name heuristics for store, developer-role, reasoning-effort, and strict-mode decisions.
User Impact
Users and plugin authors get consistent OpenAI-compatible request behavior regardless of whether OpenClaw uses the provider adapter or managed transport. There is no new config, environment variable, protocol, or migration surface.
Release-note context: internal provider compatibility hardening; no user action is required.
AI-assisted: yes. The implementation was reviewed against the full caller/normalization paths and a structured Codex autoreview.
Evidence
node scripts/run-vitest.mjs packages/ai/src/transports/openai-transport-params.session-header.test.ts src/agents/openai-transport-stream.reasoning-and-cache.test.ts packages/ai/src/providers/openai-completions.compat.test.ts src/agents/openai-completions-compat.test.ts src/agents/model-compat.test.ts— 173 tests passed across three Vitest shards.node scripts/check-changed.mjs -- packages/ai/src/providers/openai-completions.compat.test.ts packages/ai/src/providers/openai-completions.ts packages/ai/src/transports/openai-completions-compat.ts packages/ai/src/transports/openai-transport-params.ts src/plugins/provider-model-compat.ts— all selected guards, formatting, core/core-test typechecks, lint, boundary checks, and import-cycle checks passed on Blacksmith Testbox (tbx_01kygkvf94sgdbxmswpb3v2k1r; run https://github.com/openclaw/openclaw/actions/runs/30230465132).tbx_01kygqkj1fzhhc4rhdd0zcbrh7(run https://github.com/openclaw/openclaw/actions/runs/30233073603): a real loopback OpenAI-compatible HTTP/SSE server received one request from the provider adapter and one from the managed transport. Both streamed a successfulOKresult and produced the same redacted payload summary:instructionRole=system,maxCompletionTokens=128,hasStore=false,hasStreamOptions=true. Credentialed OpenRouter/OpenAI probes were unavailable because those keys are not exposed to this Testbox workflow; no secret values were read or printed.$HOME/.claude/skills/autoreview/scripts/autoreview --mode branch --base origin/main— clean, no accepted/actionable findings.git diff --check— clean.