Skip to content

refactor(ai): unify OpenAI completions compatibility - #114236

Merged
steipete merged 3 commits into
mainfrom
refactor/openai-completions-compat-authority
Jul 27, 2026
Merged

steipete merged 3 commits into
mainfrom
refactor/openai-completions-compat-authority

Conversation

@steipete

@steipete steipete commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

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 detectOpenAICompletionsCompat policy 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 Gateway max_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).
  • Real after-fix runtime proof on Blacksmith Testbox 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 successful OK result 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.
  • Production delta: 132 additions / 409 deletions, net -277 lines; the 313-line second matrix is gone.

@openclaw-barnacle openclaw-barnacle Bot added size: L maintainer Maintainer-authored PR labels Jul 27, 2026
@steipete
steipete marked this pull request as ready for review July 27, 2026 02:06
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 26, 2026, 10:55 PM ET / July 27, 2026, 02:55 UTC.

ClawSweeper review

What this changes

The 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 readiness

⚠️ Ready for maintainer review - 3 items remain

Keep 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
Reviewed head: eed4d9834aaece859838e51b20863d218a32c96b
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused refactor with concrete cross-path runtime proof and extensive targeted coverage; final confidence depends on refreshing against current main and preserving the endpoint-specific compatibility table.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The updated PR body provides after-fix, redacted live output from a loopback OpenAI-compatible HTTP/SSE server showing both the provider adapter and managed transport stream successfully with matching payload summaries; no secrets were exposed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The updated PR body provides after-fix, redacted live output from a loopback OpenAI-compatible HTTP/SSE server showing both the provider adapter and managed transport stream successfully with matching payload summaries; no secrets were exposed.
Evidence reviewed 5 items Unified compatibility authority: The PR removes the provider-local compatibility module and changes the provider adapter to import the resolver from the transport package, leaving request compatibility policy in one shared implementation.
Managed transport now resolves the full contract: The transport parameter builder replaces its reduced local compatibility projection with the shared resolver, so fields formerly omitted from the managed path can follow the same endpoint attribution policy.
Regression coverage covers the deleted matrix: The PR expands the provider compatibility test around endpoint attribution and imports the transport resolver directly, matching the stated intent to table-drive the prior matrix cases.
Findings None None.
Security None None.

How this fits together

OpenAI-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]
Loading

Decision needed

Question Recommendation
After a current-main refresh, should the maintainers accept the transport resolver as the canonical compatibility contract for existing OpenAI-compatible provider and managed-transport users? Approve the consolidated resolver: Merge after rebasing if maintainers agree the regression table captures every retained endpoint contract and the intentional heuristic differences are the desired product behavior.

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

  • Resolve merge risk (P1) - The PR is mergeable but behind current main; refresh the base before landing so the final review covers the actual three-way merge result.
  • Resolve merge risk (P1) - The consolidation changes endpoint-derived OpenAI-compatible payload behavior. The real proof demonstrates parity between the two local request paths, but credentialed OpenRouter/OpenAI probes were intentionally unavailable, so final review should preserve the table-driven endpoint contracts rather than infer them from a generic loopback endpoint.
Agent review details

Security

None.

PR surface

Source -279, Tests +418. Total +139 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 5 134 413 -279
Tests 1 432 14 +418
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 566 427 +139

Review metrics

Metric Value Why it matters
Compatibility authorities 2 request-policy paths unified into 1 resolver The merge replaces a provider-local matrix and a managed-transport projection with one endpoint-attributed contract, so any omitted exception can affect both paths at once.

Merge-risk options

Maintainer options:

  1. Refresh and validate endpoint contracts (recommended)
    Rebase onto current main and confirm the table-driven compatibility cases preserve each intentional provider and URL contract before merging.
  2. Accept the narrowed policy deliberately
    Merge with the documented resolver behavior if maintainers explicitly accept the stated shift away from broader provider-name heuristics.

Technical review

Best 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.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The updated PR body provides after-fix, redacted live output from a loopback OpenAI-compatible HTTP/SSE server showing both the provider adapter and managed transport stream successfully with matching payload summaries; no secrets were exposed.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The updated PR body provides after-fix, redacted live output from a loopback OpenAI-compatible HTTP/SSE server showing both the provider adapter and managed transport stream successfully with matching payload summaries; no secrets were exposed.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is focused compatibility hardening across OpenAI-compatible provider paths, with a limited but user-facing payload blast radius.
  • merge-risk: 🚨 compatibility: Replacing two request-compatibility authorities can change existing endpoint payload fields or defaults after upgrade.
  • merge-risk: 🚨 auth-provider: The resolver consumes provider and endpoint attribution that governs OpenAI-compatible provider request behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The updated PR body provides after-fix, redacted live output from a loopback OpenAI-compatible HTTP/SSE server showing both the provider adapter and managed transport stream successfully with matching payload summaries; no secrets were exposed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The updated PR body provides after-fix, redacted live output from a loopback OpenAI-compatible HTTP/SSE server showing both the provider adapter and managed transport stream successfully with matching payload summaries; no secrets were exposed.

Evidence

What I checked:

  • Unified compatibility authority: The PR removes the provider-local compatibility module and changes the provider adapter to import the resolver from the transport package, leaving request compatibility policy in one shared implementation. (packages/ai/src/providers/openai-completions.ts:18, eed4d9834aae)
  • Managed transport now resolves the full contract: The transport parameter builder replaces its reduced local compatibility projection with the shared resolver, so fields formerly omitted from the managed path can follow the same endpoint attribution policy. (packages/ai/src/transports/openai-transport-params.ts:12, eed4d9834aae)
  • Regression coverage covers the deleted matrix: The PR expands the provider compatibility test around endpoint attribution and imports the transport resolver directly, matching the stated intent to table-drive the prior matrix cases. (packages/ai/src/providers/openai-completions.compat.test.ts:1, eed4d9834aae)
  • After-fix real behavior proof: The PR body reports a Blacksmith Testbox loopback OpenAI-compatible HTTP/SSE server receiving one provider-adapter request and one managed-transport request; both streamed OK and produced the same redacted payload summary. (eed4d9834aae)
  • Current PR state: The supplied GitHub context reports this PR as open, mergeable, and behind main rather than merged or superseded; it was created on July 27, 2026 and does not meet any stale-PR close condition. (eed4d9834aae)

Likely related people:

  • steipete: The supplied PR history attributes all three commits in the resolver consolidation sequence to this contributor; the visible review context does not provide a separate current-main ownership trail for these exact files. (role: introduced the proposed compatibility consolidation; confidence: medium; commits: 667d727f71a5, 5aaaa883082e, eed4d9834aae; files: packages/ai/src/transports/openai-completions-compat.ts, packages/ai/src/providers/openai-completions.ts, packages/ai/src/transports/openai-transport-params.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase onto current main and have the final reviewer verify the endpoint-specific regression table against the intended canonical policy.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-07-27T02:10:24.707Z sha 5aaaa88 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-27T02:36:35.335Z sha eed4d98 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 27, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready verification for head eed4d9834aaece859838e51b20863d218a32c96b:

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.

@steipete
steipete merged commit 1759f4d into main Jul 27, 2026
158 of 166 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete
steipete deleted the refactor/openai-completions-compat-authority branch July 27, 2026 02:59
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 27, 2026
* refactor(ai): unify OpenAI completions compatibility

* refactor(ai): make cache compat resolution explicit

* fix(ai): keep ModelStudio token field canonical
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR 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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant