Skip to content

refactor(ai): split completions transport into concept modules - #122122

Merged
steipete merged 4 commits into
mainfrom
steipete/ai-transport-split-0811
Aug 11, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/ai-transport-split-0811

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

openai-completions-transport.ts had grown to roughly 2,100 lines and combined client lifecycle, stream decoding, DeepSeek DSML recovery, outbound parameter shaping, and reasoning replay policy in one module. That made concept ownership, focused tests, and the max-lines ratchet harder to maintain.

Why This Change Was Made

This splits the transport behind its stable façade into concept-owned stream, DSML, params, replay, and Azure-host classification modules. The façade continues to export only createOpenAICompletionsTransportStreamFn and buildOpenAICompletionsParams; the package barrel is unchanged and all new leaf symbols remain package-private.

Completion-owned tests now live beside the package concepts while residual Responses coverage keeps its existing agent-test filenames and CI ownership. The follow-up cleanup consolidates tool-history detection in openai-completions-messages.ts, removes the test-global transport API and wrappers, and makes the Together parameter mutator void.

User Impact

No behavior or configuration changes are intended. OpenAI-compatible completions payload shaping, stream event ordering, DSML recovery, reasoning replay, usage accounting, Azure query/header handling, and public exports remain unchanged.

Evidence

  • Focused Vitest matrix: 591 tests passed across 32 files, including package concept suites, residual agent suites, legacy function-call coverage, usage parity, structured-content parity, and provider-transport parity.
  • pnpm build: passed, including package declarations, runtime postbuild, Plugin SDK export verification, and Control UI build.
  • node scripts/check-changed.mjs: passed all selected core, core-test, and tooling lanes locally after remote backends were unavailable (Blacksmith CLI absent; managed Crabbox broker login absent).
  • pnpm plugin-sdk:surface:check: passed (152 public subpaths verified).
  • pnpm lint:tmp:export-name-collisions: passed.
  • pnpm check:wrapper-shadowing: passed.
  • pnpm check:import-cycles: passed with 0 runtime value cycles.
  • pnpm check:max-lines-ratchet: passed with 955 grandfathered suppressions.
  • @openclaw/ai/transports export comparison: 77 before / 77 after; added 0, removed 0.
  • Final Codex autoreview: clean, no accepted/actionable findings.
  • LOC versus the branch merge base:
    • Production: +1,836 / -1,838 (net -2)
    • Tests and test support: +6,597 / -6,150 (net +447)
    • Tooling/generated: +0 / -5 (net -5)

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 11, 2026
@steipete
steipete marked this pull request as ready for review August 11, 2026 15:56
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Aug 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 11, 2026, 12:04 PM ET / 16:04 UTC.

ClawSweeper review

What this changes

The PR divides OpenAI-compatible chat-completions request shaping and streamed-response handling into focused internal modules while retaining the existing transport facade and exports.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. This is a useful, maintainer-owned refactor; inspection found the stable facade, routing, payload construction, replay, and stream decoding preserved rather than replaced.

Priority: P3
Reviewed head: cc8ada71280beaff7ee4206daaed0b3468dfdf11

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A clean, behavior-preserving extraction with focused boundary coverage; complete exact-head checks remain the material merge gate.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal refactor is exempt from the external-contributor proof gate; its body reports focused loopback transport validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal refactor is exempt from the external-contributor proof gate; its body reports focused loopback transport validation.
Evidence reviewed 6 items Current entry point: The managed-transport selector routes the openai-completions API to the unchanged public factory.
Facade and extracted owner boundary: The PR-head facade still creates the request, delegates decoding, and re-exports the parameter builder; extracted leaves stay internal.
Payload behavior preserved: The extracted builder retains the existing message conversion, replay, tool-history, provider-compatibility, and reasoning branches.
Findings None None.
Security None None.

How this fits together

The AI transport converts normalized agent context into OpenAI-compatible completion requests and turns streamed provider events into assistant text, reasoning, usage, and tool calls. The change reorganizes those internal stages without adding a new public transport API.

flowchart LR
A[Agent context and model] --> B[Completion parameters]
B --> C[Stable transport facade]
C --> D[OpenAI-compatible request]
D --> E[Stream and DSML decoding]
E --> F[Assistant output and tool calls]
Loading

Before merge

  • Resolve merge risk (P1) - This broad extraction carries compatibility risk for configured OpenAI-compatible providers if an unnoticed move diverges; exact-head checks should complete before landing.
  • Resolve merge risk (P1) - The read-only checkout has no installed OpenAI SDK source and network DNS failed, so direct dependency-type inspection was not possible; the PR preserves the existing SDK call shape.
  • Complete next step (P2) - No concrete repair is identified; this protected maintainer PR should remain in normal review until exact-head validation completes.
Agent review details

Security

None.

PR surface

Source +193, Tests +252, Other -5. Total +440 across 38 files.

View PR surface stats
Area Files Added Removed Net
Source 11 2238 2045 +193
Tests 26 6195 5943 +252
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 5 -5
Total 38 8433 7993 +440

Review metrics

Metric Value Why it matters
Production versus test delta production -2; tests and test support +447 The refactor is net-negative in production while moving regression coverage to its owning package concepts.

Stored data model

Persistent data-model change detected: persistent cache schema: config/max-lines-baseline.txt, persistent cache schema: packages/ai/src/transports/openai-completions-params.reasoning.test.ts, persistent cache schema: packages/ai/src/transports/openai-completions-params.ts, persistent cache schema: packages/ai/src/transports/openai-completions-transport.ts, serialized state: packages/ai/src/transports/openai-completions-stream.integration.test.ts, serialized state: packages/ai/src/transports/openai-completions-transport.requests.test.ts, and 1 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Wait for exact-head validation (recommended)
    Land after the remaining exact-head checks complete successfully, preserving confidence across OpenAI-compatible provider configurations.

Technical review

Best possible solution:

Retain the stable facade and internal concept split, then land only after exact-head validation confirms the moved provider payload and stream behavior.

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

Not applicable: this PR refactors an existing transport rather than reporting a user failure; loopback request and stream tests cover the affected boundary.

Is this the best way to solve the issue?

Yes. Splitting behind the unchanged facade follows the established Responses transport pattern and keeps public exports stable while giving stream, replay, and payload logic clear owners.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 32e3bd3797f0.

Labels

Label changes:

  • add P3: This is internal maintainability work with no intended user-visible feature or configuration change.
  • add merge-risk: 🚨 compatibility: The moved code shapes requests and decodes streams for existing OpenAI-compatible provider configurations.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal refactor is exempt from the external-contributor proof gate; its body reports focused loopback transport validation.

Label justifications:

  • P3: This is internal maintainability work with no intended user-visible feature or configuration change.
  • merge-risk: 🚨 compatibility: The moved code shapes requests and decodes streams for existing OpenAI-compatible provider configurations.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored internal refactor is exempt from the external-contributor proof gate; its body reports focused loopback transport validation.

Evidence

What I checked:

Likely related people:

  • steipete: Current-main blame attributes the transport factory and parameter builder to Peter Steinberger, and the PR-head commits are authored by steipete. (role: current feature owner and recent area contributor; confidence: high; commits: 3cfb344f9f27, 1bb4e21724a1, cc8ada71280b; files: packages/ai/src/transports/openai-completions-transport.ts, packages/ai/src/transports/openai-completions-params.ts)

Rank-up moves

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

  • Allow the remaining exact-head checks to finish successfully before landing.

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.

@steipete
steipete merged commit fe4cff7 into main Aug 11, 2026
119 checks passed
@steipete
steipete deleted the steipete/ai-transport-split-0811 branch August 11, 2026 16:47
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 12, 2026
…law#122122)

* refactor(ai): split completions transport into concept modules

* refactor(ai): delete duplicated transport helpers

* chore(lint): ratchet max-lines baseline after transport split

* test(scripts): update prefix expansion expectation
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: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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