fix(ai-aliyun-content-moderation): report final results without usage - #13922
Merged
nic-6443 merged 10 commits intoSep 9, 2026
Merged
Conversation
AlinsRan
approved these changes
Sep 9, 2026
shreemaan-abhishek
approved these changes
Sep 9, 2026
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.
Streaming responses without
usagecould skip response moderation or end without a client-visible result.Record whether the provider supplied usage and finalize assembled text at protocol completion or clean EOF. In
final_packetmode, retain the existing data-event loop and adddeny_messagealongsiderisk_level, preserving content and usage. The usage flag only controls whether to insert an additional Chat or Anthropic result before the terminator; Responses retains its existing completed-event carrier. Allowed results use an empty denial message. Injected events include zero usage. Chat uses an empty usage chunk (choices: []): denial text is returned only in the top-leveldeny_messagefield, without adding model output or changing finish reasons.The final-packet filter returns before decoding until assembled text is available; error detection reuses the provider parser's existing result. Native SSE dispatch reuses the parser's complete-frame byte boundaries, preserving comments and blank lines without a second plugin buffer. Incomplete tails and errors must not synthesize successful termination. A client completion marker prevents converted streams from receiving a second terminator during their final empty flush.
Results are informational and cannot retract streamed content. Existing usage remains unchanged; injected events report zero usage. Responses SDK wrappers may discard unknown top-level fields, so read the extensions from raw events. English and Chinese documentation describes the behavior.
Integration coverage includes usage and no-usage streams, split/coalesced frames and terminators, in-place and injected fields, safe/rejected/failed scans, multiple choices, protocol conversion, and truncated streams. Lakera tests verify scanning without usage while retaining fail-open/fail-closed coverage for incomplete streams. Provider conversion semantics and plugin schemas are unchanged.