Skip to content

fix(ai-aliyun-content-moderation): report final results without usage - #13922

Merged
nic-6443 merged 10 commits into
apache:masterfrom
nic-6443:fix/stream-response-text-without-usage
Sep 9, 2026
Merged

fix(ai-aliyun-content-moderation): report final results without usage#13922
nic-6443 merged 10 commits into
apache:masterfrom
nic-6443:fix/stream-response-text-without-usage

Conversation

@nic-6443

@nic-6443 nic-6443 commented Sep 7, 2026

Copy link
Copy Markdown
Member

Streaming responses without usage could 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_packet mode, retain the existing data-event loop and add deny_message alongside risk_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-level deny_message field, 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.

Copilot AI lite review requested due to automatic review settings September 7, 2026 10:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@nic-6443 nic-6443 changed the title fix(ai-proxy): finalize response text without stream usage fix(ai-aliyun-content-moderation): expose final streaming results Sep 8, 2026
@nic-6443 nic-6443 changed the title fix(ai-aliyun-content-moderation): expose final streaming results fix(ai-aliyun-content-moderation): report final results without usage Sep 8, 2026

@membphis membphis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nic-6443
nic-6443 merged commit 1f6120d into apache:master Sep 9, 2026
20 checks passed
@nic-6443
nic-6443 deleted the fix/stream-response-text-without-usage branch September 9, 2026 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants