Repository navigation
refactor(ai): share Anthropic and Google protocol handling - #139935
Conversation
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.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 4:51 AM ET / 08:51 UTC. ClawSweeper reviewWhat this changesShares 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 Review scores
Verification
How this fits togetherProvider 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -989, Tests +74, Docs +1, Other -1. Total -915 across 18 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
…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
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
da3ac6e54a58de7f21cabfa9188b9be12b8a06fbexactly 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.