fix(ai-aliyun-content-moderation): return nil instead of ngx.OK in lua_body_filter#13623
Merged
nic-6443 merged 2 commits intoJul 1, 2026
Conversation
nic-6443
previously approved these changes
Jun 29, 2026
membphis
previously approved these changes
Jun 29, 2026
membphis
left a comment
Member
There was a problem hiding this comment.
Code review looks good to me. Please make sure CI is green before merging.
shreemaan-abhishek
previously approved these changes
Jun 29, 2026
… chained With lua_body_filter non-terminal, it re-runs on every streamed chunk once llm_response_text is set. Moderate only once, and synthesize a [DONE] terminator only when the stream is actually done, so chaining another response-path plugin (e.g. ai-lakera-guard) after it can't double-moderate or emit duplicate terminators. Add a streaming chain test plus an X-AI-Fixture-Flush-Events fixture mode that splits usage and done into separate chunks to exercise it.
janiussyafiq
dismissed stale reviews from shreemaan-abhishek, membphis, and nic-6443
via
June 30, 2026 05:04
b5fdca2
membphis
approved these changes
Jun 30, 2026
shreemaan-abhishek
approved these changes
Jun 30, 2026
nic-6443
approved these changes
Jul 1, 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.
Description
ai-aliyun-content-moderation'slua_body_filterreturnedngx.OKon the streamingfinal_packetpath. Inapisix/plugin.lua'slua_response_filter, returning a non-nil code prints the body andngx.exits the whole response filter chain, so any lower-priority response body filter is skipped.Because
ai-aliyun-content-moderation(priority 1029) runs beforeai-lakera-guard(priority 1028), a route chaining both terminated the chain beforeai-lakera-guard's output scan ran — even thoughfinal_packetonly annotatesrisk_leveland never blocks. The result was a silent moderation gap: a streamed response thatai-lakera-guardwould block could leak through unscanned.This returns
nil(transform-and-continue) instead ofngx.OKon thefinal_packetpath, so the chain keeps running lower-priority response body filters. The paths that genuinely terminate the response (realtimeblock) still return a code and are unchanged.A combined-plugin streaming test (
t/plugin/ai-lakera-guard-chain.t) is added: it assertsai-lakera-guard's output scan still runs and blocks a flagged stream when chained afterai-aliyun-content-moderation, and that a clean stream still passes through the chain.Which issue(s) this PR fixes:
Fixes #13620
Fixes #13291
Checklist