Skip to content

refactor(ai): share Anthropic and Google protocol handling - #139935

Merged
steipete merged 4 commits into
mainfrom
codex/reduce-provider-transports-01a0750a
Sep 6, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/reduce-provider-transports-01a0750a

Conversation

@steipete

@steipete steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Anthropic and Google maintained separate transcript conversion and streaming-response implementations for direct SDK callers and OpenClaw-managed transports. Fixing tool replay, thinking signatures, usage accounting, or terminal events required keeping those implementations aligned.

Why This Change Was Made

Each protocol now has one message projector and one stream reducer. Anthropic also shares generation/tool materialization. Direct and managed profiles preserve their existing differences in signed parts, seeded tool inputs, event timing, replay, image/empty-result handling, and errors. Networking, SDK injection, OAuth/ADC, guarded fetch, key rotation, retries, SSE framing, and trusted native-video admission remain with their existing owners.

The obsolete implementations are deleted. Across the touched production owners, authored code decreases from 5,654 to 4,783 lines: 871 production code lines removed (989 physical lines). Preservation coverage adds 72 test code lines. The roughly 5.2k-line diff is an ownership consolidation; it does not represent 5.2k net deletions. Existing assertion/max-lines baselines shrink to match removed code.

User Impact

No intended behavior change. Both standalone SDK consumers and managed plugin transports retain their existing request, event, cancellation, replay, and error contracts. Google exposes the required helpers through the existing transport SDK seam; there is no new package subpath, configuration, migration, or dependency change.

Evidence

  • 343 Anthropic and 286 Google focused tests passed on the combined implementation, including SDK loopback HTTP, native SSE framing/cancellation, signed thinking, compaction/replay, seeded malformed/encoded tool input, image/tool grouping, usage, and provider routing.

  • A 32-case direct/managed Google request/event corpus is byte-identical. Additional probes preserve public video normalization, prepared inline video, and managed trusted-slot identity. New Anthropic preservation cases pass the original implementation and fail a deliberately broken seed-discarding variant.

  • Five selected live cases passed on Blacksmith Testbox: Anthropic response/usage and thinking signature; two Google discovery/completion cases; managed Google understanding of a synthetic video. Ten unrelated cases were filtered. Testbox lifecycle run. The wrapper exited successfully and the owned lease was stopped.

  • Final source tree da3ac6e54a58de7f21cabfa9188b9be12b8a06fb exactly matches the live-tested tree. Independent P2 review found no runtime defect; its index-only unused-type-export finding was resolved by staging the already-reviewed cleanup.

  • The complete selected repository gate passed, including all four typecheck lanes, zero unused-export findings, SDK surfaces/boundaries, core/extensions/scripts lint, and runtime ownership guards.

  • The normal full build passed all 16 phases in 11m 11s, including 90 plugins, 53 native control-plane module loads, SDK export checks, and the Control UI build/performance budgets. The worktree is clean.

Use one owner for Messages transcript projection, tool and generation parameters, and streamed event reduction. Retain standalone and managed transport policies, exact event contracts, seeded tool inputs, refusal handling, compaction, cancellation, and usage.
Use one prepared-transcript projector and one stream reducer for direct Google SDK and managed transports. Preserve signed-part boundaries, event timing, usage and error contracts, native-video admission, route normalization, and plugin-owned authentication.
@clawsweeper

clawsweeper Bot commented Sep 6, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: google size: XL maintainer Maintainer-authored PR labels Sep 6, 2026
@steipete
steipete marked this pull request as ready for review September 6, 2026 08:26
@clawsweeper clawsweeper Bot added 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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 4:51 AM ET / 08:51 UTC.

ClawSweeper review

What this changes

Shares Anthropic and Google transcript conversion and response-stream handling between direct SDK callers and managed transports while preserving their existing behavior differences.

Merge readiness

✅ Ready for maintainer review

This remains a useful, maintainer-sponsored consolidation that current main does not contain. No blocking defect was found. The earlier compatibility caution describes a documented additive SDK contract, not an outstanding approval or repair requirement.

Priority: P3
Reviewed head: 6b5b01010c57c5050049ed6ad376fc96efaba622

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent consolidation with meaningful preservation coverage, reported real-provider proof, and no blocking finding.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The captured evidence reports five real Testbox passes exercising the shared Anthropic and Google paths, including usage, signatures, completion, and managed video; the reviewed tree matches the reported tested tree. Independent retrieval of the linked run was unavailable, which is a reviewer limitation rather than missing contributor proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The captured evidence reports five real Testbox passes exercising the shared Anthropic and Google paths, including usage, signatures, completion, and managed video; the reviewed tree matches the reported tested tree. Independent retrieval of the linked run was unavailable, which is a reviewer limitation rather than missing contributor proof.
Evidence reviewed 8 items Introduced scope and current-main comparison: The pinned introduction contains the protocol consolidation. Comparing the merge base with fetched main produced no changes in the four original production owners or SDK facade; main still contains the separate Google stream consumer and Anthropic transport projector.
Preserved Google adapter boundary: The managed caller still normalizes transcript routes, preserves trusted video placeholder identity, and selects the managed replay profile. Authentication, guarded fetch, key rotation, and SSE ownership remain in the plugin.
Shared reducers preserve distinct contracts: Read both new reducers and their original implementations. Google retains signed-part versus managed-delta handling, cancellation precedence, terminal checks, and usage accumulation; Anthropic retains profile-specific signature handling, deferred tool completion, refusal buffering, and seeded-input validation.
Findings None None.
Security None None.

How this fits together

Provider adapters turn conversation history into Anthropic or Google requests and translate streamed responses into assistant text, tool calls, and usage. The shared protocol code sits between those adapters and their existing network, authentication, and cancellation owners.

flowchart LR
  A[Conversation and tools] --> B[Direct or managed adapter]
  B --> C[Shared message projection]
  C --> D[Existing authenticated transport]
  D --> E[Provider response stream]
  E --> F[Shared stream reduction]
  F --> G[Assistant events and usage]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -989, Tests +74, Docs +1, Other -1. Total -915 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 10 2037 3026 -989
Tests 5 84 10 +74
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 2 4 5 -1
Total 18 2126 3041 -915

Review metrics

Metric Value Why it matters
Public SDK additions 4 functions and 1 type through an existing subpath The additive protocol contract is documented and serves both direct and managed production callers.

Technical review

Best possible solution:

Keep one protocol implementation per provider family, with explicit preservation profiles and network, credentials, and trusted-media admission retained by their existing owners.

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

Not applicable: this PR consolidates existing implementations rather than reporting a new failure; preservation tests and reported live runs cover the affected behavior.

Is this the best way to solve the issue?

Yes. Sharing projection and reduction while retaining explicit transport profiles removes competing implementations without moving authentication or network lifecycle ownership.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P3: This is a behavior-preserving maintenance refactor without an identified urgent user-facing defect.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The captured evidence reports five real Testbox passes exercising the shared Anthropic and Google paths, including usage, signatures, completion, and managed video; the reviewed tree matches the reported tested tree. Independent retrieval of the linked run was unavailable, which is a reviewer limitation rather than missing contributor proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured evidence reports five real Testbox passes exercising the shared Anthropic and Google paths, including usage, signatures, completion, and managed video; the reviewed tree matches the reported tested tree. Independent retrieval of the linked run was unavailable, which is a reviewer limitation rather than missing contributor proof.

Evidence

What I checked:

  • Introduced scope and current-main comparison: The pinned introduction contains the protocol consolidation. Comparing the merge base with fetched main produced no changes in the four original production owners or SDK facade; main still contains the separate Google stream consumer and Anthropic transport projector. (packages/ai/src/providers/google-shared.ts:757, e8503408bc14)
  • Preserved Google adapter boundary: The managed caller still normalizes transcript routes, preserves trusted video placeholder identity, and selects the managed replay profile. Authentication, guarded fetch, key rotation, and SSE ownership remain in the plugin. (extensions/google/transport-stream.ts:411, 6b5b01010c57)
  • Shared reducers preserve distinct contracts: Read both new reducers and their original implementations. Google retains signed-part versus managed-delta handling, cancellation precedence, terminal checks, and usage accumulation; Anthropic retains profile-specific signature handling, deferred tool completion, refusal buffering, and seeded-input validation. (packages/ai/src/transports/anthropic-stream-reducer.ts:55, 6b5b01010c57)
  • SDK contract is explicitly documented: Four Google functions and one chunk type are added through the existing transport SDK facade. The documentation specifies prepared transcripts, replay and stream profiles, caller-owned authentication/cancellation/video admission, and failure finalization. The maintainer-authored body explicitly describes this seam expansion; the prior review retained no actionable findings or published rank-up moves. Public docs: docs/plugins/sdk-provider-plugins.md. (docs/plugins/sdk-provider-plugins.md:666, 6b5b01010c57)
  • Focused preservation coverage: The added Anthropic table covers malformed seeds, encoded object seeds, and streamed arguments replacing malformed seeds through both production entrypoints. It checks terminal arguments and rejection before toolcall_end. Existing Google tests cover signed-part identity, duplicate call IDs, terminal failures, and cancellation precedence. Tests were inspected, not executed. (packages/ai/src/provider-transport-parity.test.ts:529, 6b5b01010c57)
  • Captured live proof and matching tree: The captured body, source revision 8d1b6c14afbc4b75f893a1016ba6127d1bbc4792cb322682321856dd03563114, reports five passing Testbox cases covering Anthropic responses/usage/signatures, Google completion, and managed synthetic-video understanding, linked at https://github.com/openclaw/openclaw/actions/runs/34019571833. HEAD's tree is da3ac6e54a58de7f21cabfa9188b9be12b8a06fb, matching the reported live-tested tree. The linked run could not be independently retrieved because network access failed; the captured evidence was not replaced. (6b5b01010c57)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vyctor H. Brzezowski: 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-09-06T08:42:45.960Z sha 6b5b010 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 6, 2026
@steipete
steipete merged commit 2dfd3c3 into main Sep 6, 2026
258 checks passed
@steipete
steipete deleted the codex/reduce-provider-transports-01a0750a branch September 6, 2026 08:59
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 7, 2026
…139935)

* refactor(ai): share Anthropic protocol projection and stream reduction

Use one owner for Messages transcript projection, tool and generation parameters, and streamed event reduction. Retain standalone and managed transport policies, exact event contracts, seeded tool inputs, refusal handling, compaction, cancellation, and usage.

* test(ai): preserve seeded Anthropic tool inputs across transports

* refactor(ai): share Google protocol projection and stream reduction

Use one prepared-transcript projector and one stream reducer for direct Google SDK and managed transports. Preserve signed-part boundaries, event timing, usage and error contracts, native-video admission, route normalization, and plugin-owned authentication.

* refactor(ai): keep Google projection types internal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: google maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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