refactor: hoist provider schema handling for Responses, Messages, and Chat Completions#288
Draft
zhongxuanwang-nv wants to merge 1 commit into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Enterprise Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
2fa6ba4 to
d60cc52
Compare
d60cc52 to
8055c45
Compare
… Chat Completions Consolidate provider schema handling for OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages behind a single codec-layer path so exporters and plugins consume normalized data instead of re-parsing raw provider JSON. - Add codec::resolve: ProviderSurface detection + fail-open normalize_request/normalize_response as the canonical detect-then-decode entry. - Add Event::normalized_llm_request/response annotation-first helpers and consume them in the OpenInference exporter (annotation -> OpenClaw replay -> codec detection), so un-annotated provider events emit structured attributes. - Extend OpenAIResponsesCodec to decode top-level and item-level output_text. - Dedupe the otel/openinference non-provider usage/cost fallback into observability::manual (currency policy parameterized). - ATIF reads normalized message text from annotations (raw fallback for multimodal); tool calls and metrics stay on the raw path to preserve provider extras. - adaptive delegates request-surface detection to codec::resolve. - Fix the misleading "global codec registry" docstring and document the annotation-vs-raw-fallback rule. Relates to RELAY-325. Signed-off-by: Zhongxuan Wang <daniewang@nvidia.com>
8055c45 to
43d96d2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Hoist provider schema handling for OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages into a single codec-layer path, so exporters and plugins consume normalized provider data instead of re-implementing provider parsing from raw JSON. (RELAY-325)
Opened as a draft for review. Local validation:
cargo fmt,cargo clippy --all-targets -D warnings, and the pre-commit hooks pass; targeted unit + integration tests are green (resolve, codec, observability::manual, otel, openinference, atif, types, adaptive request-surface, plus codec/pipeline integration). The full cross-language matrix is left to CI — no binding or public-API surfaces changed.Details
codec::resolve(new) — the canonical detect-then-decode entry point.ProviderSurface+detect_request_surface(priority order hoisted verbatim from adaptive's resolver) /detect_response_surface(strict; ambiguous or empty payloads →None, avoiding the codecs' permissive{}decode) + fail-opennormalize_request/normalize_response.Event::normalized_llm_request/response— annotation-firstCowhelpers over the detector;annotated_*()left unchanged.OpenAIResponsesCodec— response-only extension to decode top-leveloutput_textand item-leveloutput[].type == "output_text"(structuredoutputkeeps precedence). Requestinput_textdeliberately left out (strict request parse).observability::manual(new) — the otel/openinference non-provider usage/cost fallback de-duplicated into one module, with the USD-only vs emit-any-currency policy parameterized.otel.rsandopeninference.rseach shrink ~185 lines.provider_data) are preserved.resolve_request_surface_from_requestdelegates tocodec::resolve::detect_request_surface(function name,AcgError::Internalmessage, and priority order preserved).codec/traits.rs; added an annotation-vs-raw-fallback note toprovider-response-codecs.mdx.Where should the reviewer start?
crates/core/src/codec/resolve.rs(the new single path), thencrates/core/src/observability/atif.rs— the annotation-first / raw-fallback consumer is the trickiest equivalence surface (the raw parser is intentionally retained where the normalized form would be lossy: tool-call extras and multimodal content).Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)