Skip to content

refactor(ai): share provider transport request orchestration - #162491

Merged
steipete merged 3 commits into
mainfrom
deslop/l271-arch-small-providers
Oct 1, 2026
Merged

steipete merged 3 commits into
mainfrom
deslop/l271-arch-small-providers

Conversation

@steipete

@steipete steipete commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Anthropic and OpenAI Completions keep parallel request orchestration in their public provider and managed transport routes, making shared policy fixes easy to apply inconsistently.

User Impact

No intended behavior change. Both public routes remain, including injected Anthropic SDK clients used by Vertex. Authentication, payload hooks, cache markers, compaction replay, refusal buffering, cancellation and event ordering retain their existing profiles.

Why This Change Was Made

Anthropic now assembles requests and applies post-hook request/beta contracts through its existing message owner. Completions now has one request, response acceptance, first-event deadline, error and disposal lifecycle, with a private adapter for direct-route block endings. Existing public transport exports remain explicit. Distinct SDK/fetch framing and provider-specific policies remain at their owners.

The measured reduction is 160 production lines across six files; tests are unchanged. The remaining differences preserve distinct public-route contracts.

Evidence

  • 765 tests passed across 30 selected suites: both provider/transport routes, Anthropic cache/context/binding/refusal/replay policies, Completions request and stream behavior, transport failures, and the Vertex injected-client adapter.
  • Independent Codex autoreview: scoped-clean through P2.
  • Changed checks passed across the selected ratchets, production and all 27 test-type shards, boundary guards, dead-export scans, formatting, and focused lint. The full run stopped at two lint findings; both were fixed and the exact focused lint stage passed afterward.
  • The initial hosted run found unused helper exports and a widened stream-mode discriminator. Both were corrected; 139 affected tests passed again after the final corrections.
  • Both pre-push cycle checks: Madge 0 cycles; runtime imports 0 cycles.
  • Attempted Blacksmith Testbox tbx_01m3tzt14pmrnx42kbjtkke840 (allocation run); source-capsule preparation did not reach remote execution after over 20 minutes. The owned invocation settled interrupted, the lease was stopped, and tests used the authorized serial local fallback at nice -n 15.
  • These are synthetic boundary tests, not live provider inference.
Coverage of production owners over 200 lines

Scope: candidate 8 Anthropic and OpenAI Completions provider/transport orchestration and their protocol owners. Baseline 3b8ed7c; production files over 200 lines, sorted by baseline size.

Lines Production file Coverage
702 packages/ai/src/transports/anthropic-payload-policy.ts READ: retain canonical cache, context-management and beta-header policy; both routes now use the same invocation sequence.
674 packages/ai/src/transports/openai-completions-stream.ts READ: retain protocol reducer and profile-specific terminal ordering; request lifecycle moved to one caller owner.
647 packages/ai/src/transports/anthropic-transport-stream.ts READ: remove duplicate parameter assembly and hook/header coordination; retain HTTP/SSE parser, bounded error bodies, auth and terminal behavior.
620 packages/ai/src/providers/anthropic.ts READ: share request assembly and hook/header coordination; retain public SDK client injection, provider defaults, auth and stream events.
606 packages/ai/src/transports/anthropic-stream-reducer.ts READ: already canonical protocol/replay/refusal reducer; direct and transport event-order profiles are real contracts.
594 packages/ai/src/transports/openai-completions-params.ts READ: already canonical assembly; preserve direct/managed compatibility and reasoning profiles.
448 packages/ai/src/transports/anthropic-messages.ts READ: becomes canonical request assembly and post-hook contract owner, reusing existing converters and policy owners.
366 packages/ai/src/providers/anthropic-model-contract.ts READ: retain model identity, prefill, sampling and replay contracts.
349 packages/ai/src/transports/openai-completions-compat.ts READ: retain canonical endpoint/default/override policy.
346 packages/ai/src/openai-completions-messages.ts READ: retain single transcript, cache-boundary and tool-image projection owner.
343 packages/ai/src/transports/openai-completions-dsml.ts READ: retain bounded incremental recovery and UTF-8 accounting.
329 packages/ai/src/transports/openai-completions-transport.ts READ: one request, acceptance, deadline, failure and disposal lifecycle; private direct event adapter preserves endings.
307 packages/ai/src/providers/openai-completions-tool-calls.ts READ: retain terminal argument validation, provisional stripping and legacy normalization owner.
296 packages/ai/src/transports/openai-completions-replay.ts READ: retain provider-specific reasoning/signature replay contracts.
279 packages/ai/src/providers/anthropic-tool-projection.ts READ: retain schema quarantine, name collision and forced-tool projection contract.
271 packages/ai/src/providers/openai-completions.ts READ: remove parallel lifecycle; preserve public stream/simple-option adapters.
255 packages/ai/src/providers/anthropic-usage.ts READ: retain billing versus context-window accounting and compaction iteration validation.
254 packages/ai/src/transports/anthropic-compaction-replay.ts READ: retain model/session-bound replay state and rejection suppression.

Also inspected registered entry points, public package/barrel exports, Vertex SDK injection, transport options, host and transcript transformations, refusal/fallback helpers and matching boundary tests. No SDK surface, schema, config or protocol change. Six production files changed: 160 net lines removed; no test changes.

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added 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 Oct 1, 2026
@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 4:24 AM ET / 08:24 UTC (Revision 2).

ClawSweeper review

What this changes

The PR shares Anthropic request preparation and OpenAI Chat Completions request lifecycles while retaining each public route’s existing defaults and stream behavior.

Merge readiness

✅ Ready for maintainer review

The refactor remains useful: current main still contains parallel request orchestration. No concrete introduced correctness or security defect was found, and the prior review has no outstanding findings.

Priority: P3
Reviewed head: 222ff7abdf5ee571754e5475433795a152d6ae28

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused consolidation preserves the inspected contracts and has substantial reported boundary validation, with no actionable defect found.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository MEMBER role exempts this maintainer-authored refactor from contributor live-proof requirements. Reported boundary tests cover the changed orchestration but are not claimed as live provider inference; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository MEMBER role exempts this maintainer-authored refactor from contributor live-proof requirements. Reported boundary tests cover the changed orchestration but are not claimed as live provider inference; no stored-data contract changes.
Evidence reviewed 9 items Pinned introduced change: Reviewed the merge-base-to-head delta, including all seven introduced paths. Endpoint drift and the stale test merge were not treated as PR changes. The assertion baseline changes only reduce existing counts.
Anthropic profile preservation: The shared request builder retains provider versus transport token defaults, transcript transformation, model-id normalization, empty-message fallback, eager tool streaming, and replay profiles. Post-hook contracts and beta headers retain their previous ordering.
Completions lifecycle preservation: Both routes call one lifecycle while retaining separate client policies, direct block-ending events, managed DONE detection, response-hook ordering, first-event cancellation, and error cleanup. The public transport barrel continues exporting its two existing transport exports explicitly.
Findings None None.
Security None None.

How this fits together

OpenClaw’s AI package converts conversation history, model settings, and caller hooks into provider requests. These provider adapters and managed transports return streaming assistant events to the agent runtime.

flowchart TD
  A[Conversation and model settings] --> B[Direct provider route]
  A --> C[Managed transport route]
  B --> D[Shared request orchestration]
  C --> D
  D --> E[Provider HTTP or SDK client]
  E --> F[Provider stream reducer]
  F --> G[Assistant events]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -160, Other 0. Total -160 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 6 509 669 -160
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 3 3 0
Total 7 512 672 -160

Review metrics

None.

Technical review

Best possible solution:

Keep one request lifecycle per provider family, with explicit route profiles preserving existing client, payload, cancellation, and event contracts.

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

Not applicable: this PR consolidates existing orchestration rather than reporting a failing user flow; no runtime reproduction was attempted.

Is this the best way to solve the issue?

Yes: sharing orchestration while retaining explicit route profiles removes competing lifecycle code without replacing the routes’ distinct contracts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 92457bebe2e1.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is an internal consolidation with no intended user-visible behavior change or demonstrated urgent regression.
  • 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: The supplied repository MEMBER role exempts this maintainer-authored refactor from contributor live-proof requirements. Reported boundary tests cover the changed orchestration but are not claimed as live provider inference; no stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head delta, including all seven introduced paths. Endpoint drift and the stale test merge were not treated as PR changes. The assertion baseline changes only reduce existing counts. (222ff7abdf5e)
  • Anthropic profile preservation: The shared request builder retains provider versus transport token defaults, transcript transformation, model-id normalization, empty-message fallback, eager tool streaming, and replay profiles. Post-hook contracts and beta headers retain their previous ordering. (packages/ai/src/transports/anthropic-messages.ts:471, 222ff7abdf5e)
  • Completions lifecycle preservation: Both routes call one lifecycle while retaining separate client policies, direct block-ending events, managed DONE detection, response-hook ordering, first-event cancellation, and error cleanup. The public transport barrel continues exporting its two existing transport exports explicitly. (packages/ai/src/transports/openai-completions-transport.ts:257, 222ff7abdf5e)
  • Current main still needs the consolidation: Fetched current main retains the standalone direct Completions request/client/error lifecycle. Its Anthropic message module also ends with the earlier tool converter rather than the new shared request orchestration. No implementation-close provenance was established. (packages/ai/src/providers/openai-completions.ts:52, 92457bebe2e1)
  • Existing boundary coverage: Inspected unchanged tests that exercise both public routes’ acceptance ordering, rejected callbacks, first-event deadlines, and caller cancellation. Request tests also use a real SDK against loopback HTTP. The captured PR body reports 765 passing selected tests and 139 passing tests after corrections; these runs were not independently executed during this read-only review. (packages/ai/src/transports/openai-completions-transport.response-hook.test.ts:115, 222ff7abdf5e)
  • Injected Anthropic client remains supported: The provider still consumes caller-injected clients and excludes its own fallback policy for those clients. The Vertex adapter supplies that client through the generic stream entry point; the refactor retains this route. (packages/ai/src/providers/anthropic.ts:158, 222ff7abdf5e)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • SunnyShu: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (1 earlier review cycle)
  • reviewed 2026-10-01T06:59:21.480Z sha 3328db1 :: needs maintainer review before merge. :: none

@steipete
steipete enabled auto-merge (squash) October 1, 2026 08:19
@steipete
steipete merged commit 87370ee into main Oct 1, 2026
113 of 115 checks passed
@steipete
steipete deleted the deslop/l271-arch-small-providers branch October 1, 2026 08:27
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…w#162491)

Share Anthropic request assembly and post-hook request contracts, and run direct and managed OpenAI Completions through one request lifecycle. Preserve public exports, SDK injection, authentication, caching, refusal buffering, cancellation and event ordering.

Remove 160 net production lines. Validated with provider/transport and Vertex boundary tests, changed checks, independent review and both import-cycle checks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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