Skip to content

feat(ai): unify AI protocol detection and support ai-prompt for openai-response - #8409

Open
eye-gu wants to merge 1 commit into
apache:masterfrom
eye-gu:feature/ai-protocol-detection
Open

eye-gu wants to merge 1 commit into
apache:masterfrom
eye-gu:feature/ai-protocol-detection

Conversation

@eye-gu

@eye-gu eye-gu commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Fixes #8371

Adds shenyu-plugin-ai-protocol, a small module (depends only on plugin-base) with the protocol id constants and a single detector: path → header → body, unknown when a tier is ambiguous, result cached on the exchange. ai-proxy resolves a blank protocol with it — an unresolved request fails instead of being guessed by bean order. ai-pii picks the request-side profile by the detected id, keeping its shape validation. ai-prompt now injects into openai-responses requests instead of silently skipping them; chat behavior is unchanged.

Defaults don't change: protocol still defaults to openai-chat, detection only runs when it's explicitly blank. One visible edge: /v1/responses with a chat-shaped body now fails pii's shape validation instead of being treated as chat (path wins over body). Details in the new module's README and the updated plugin READMEs.

Problem and change

IssueSpec

IssueSpec-Mode: full IssueSpec-Reason: New shared AI protocol detection module consumed by ai-proxy/ai-pii/ai-prompt. IssueSpec-Proposal: #NNN IssueSpec-Design: #NNN IssueSpec-Implement: #NNN IssueSpec-Specs: SPEC-NNNNNNN IssueSpec-Tasks: TASK-NNNNNNN IssueSpec-Validation: ./mvnw -pl shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-protocol -am test and the ai-prompt/ai-pii/ai-proxy equivalents, all passed. Integrated/e2e not run.

Make sure that:

  • You have read the contribution guidelines.
  • You submit test cases (unit or integration tests) that back your changes.
  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stream Agent analysis

Reviewed PR #8409 (feat(ai): unify AI protocol detection and support ai-prompt for openai-response) at head ee0416a. The change extracts protocol detection into a new shenyu-plugin-ai-protocol module (AiProtocolDescriptor, AiProtocolDetector, AiProtocols, plus OpenAI chat/responses descriptors), replaces the removed AiProxyProtocol.detect/bodyMatches and AiProxyProtocolFactory.protocolFor/detect APIs with the shared detector, wires ai-common/ai-proxy/ai-pii/ai-prompt to depend on ai-protocol, updates AiRequestViewParser/AiRequestViewOperations to use the shared detector, extends ai-prompt/AiPromptPlugin to handle OpenAI responses, and adds module READMEs. Full VERSIONED_DIFF coverage was achieved (all pages read, has_more=false).

Evidence

  • Full VERSIONED_DIFF consumed: resource_diff for head fa8d1d6d-f660-4a7c-b00c-fae8a8467876 vs base f2e49051-17e0-44af-a287-08f3badd4c60, all pages read (total 128255 chars, next_unread_offset reached end, has_more=false).
  • CI not passing: coverage metadata complete=true, passed=false; 6 checks queued (policy, agent_gateway_migrations, registry_dependencies, build_local_repo, check-license-header, rat_check).
  • No stale API / no circular dep: ai-protocol pom depends only on shenyu-plugin-base; ai-proxy pom adds shenyu-plugin-ai-protocol; searches for .detect(, .bodyMatches(, .protocolFor( show no leftover callers of the removed API outside the new AiProtocolDescriptor.

Recommended next steps

  • Wait for/trigger the queued CI checks (build_local_repo, check-license-header, rat_check) so the new module compiles and license headers are validated.
  • Re-run a full module build (mvn -pl shenyu-plugin/shenyu-plugin-ai -am verify) to validate cross-module wiring after removing AiProxyProtocol.detect/bodyMatches.
  • Confirm AiProtocolDetector descriptor discovery (static registry vs ServiceLoader) covers all enabled protocols in production configuration.

Scope: captured diff and GitHub check metadata only; no local tests were executed.

Task: 5295587b-9b90-49d1-a83d-4f703045815d · Commit: ee0416a167755109f801ed50b9c45b0e7b7f79df

Review verdict: INCONCLUSIVE

Full diff coverage was achieved, and no concrete HIGH/CRITICAL defect was found: Maven wiring is cycle-free (ai-protocol depends only on shenyu-plugin-base; ai-common/ai-proxy/ai-pii/ai-prompt depend on ai-protocol), the new module is registered in the ai parent pom, and no remaining callers of the removed AiProxyProtocol.detect/bodyMatches or AiProxyProtocolFactory.protocolFor/detect APIs exist. However, the mandatory PASS precondition 'passing CI' is not satisfied: CI metadata is complete but passed=false with 6 checks still queued, including build_local_repo (actual module compilation of the new pom wiring and removed-API refactor) and check-license-header/rat_check. Because those build/license verifications have not executed, build safety cannot be confirmed, so the verdict is INCONCLUSIVE.

Publication: COMMENT (INCONCLUSIVE_REVIEW)

Review details

I reviewed the complete diff for #8409. The refactor is internally consistent: the new ai-protocol module depends only on shenyu-plugin-base (no circular dependency), it is registered in the ai parent pom, and there are no remaining callers of the removed AiProxyProtocol.detect/bodyMatches or AiProxyProtocolFactory.protocolFor/detect APIs. Tests were added/updated for the new detection path. However, I cannot mark this PASS because CI has not passed: 6 checks (including build_local_repo and the license/rat checks) are still queued, so the actual compilation of the new module wiring and the license-header compliance are unverified. Verdict: INCONCLUSIVE until those checks run green.

@codecov-commenter

codecov-commenter commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.73206% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.93%. Comparing base (1748a0e) to head (ea147cc).
⚠️ Report is 1424 commits behind head on master.

Files with missing lines Patch % Lines
...nyu/plugin/ai/common/view/AiRequestViewParser.java 71.42% 2 Missing and 6 partials ⚠️
...apache/shenyu/plugin/ai/prompt/AiPromptPlugin.java 84.61% 1 Missing and 5 partials ⚠️
.../shenyu/plugin/ai/protocol/AiProtocolDetector.java 92.42% 2 Missing and 3 partials ⚠️
.../shenyu/plugin/ai/protocol/OpenAiChatProtocol.java 62.50% 0 Missing and 3 partials ⚠️
...yu/plugin/ai/protocol/OpenAiResponsesProtocol.java 62.50% 0 Missing and 3 partials ⚠️
...shenyu/plugin/ai/proxy/enhanced/AiProxyPlugin.java 84.21% 0 Missing and 3 partials ⚠️
...lugin/ai/proxy/enhanced/service/AiProxyEngine.java 83.33% 1 Missing and 2 partials ⚠️
...i/proxy/enhanced/service/AiProxyConfigService.java 60.00% 1 Missing and 1 partial ⚠️
...plugin/ai/common/view/AiRequestViewOperations.java 80.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             master    #8409       +/-   ##
=============================================
+ Coverage     61.49%   72.93%   +11.43%     
- Complexity     8818    19395    +10577     
=============================================
  Files          1261     1818      +557     
  Lines         39273    71294    +32021     
  Branches       3725     8531     +4806     
=============================================
+ Hits          24151    51998    +27847     
- Misses        12952    14940     +1988     
- Partials       2170     4356     +2186     
Flag Coverage Δ
admin 76.80% <ø> (?)
client-register-registry 54.35% <ø> (?)
core 66.79% <ø> (?)
dist-extra 64.37% <ø> (?)
gateway-runtime 83.65% <ø> (?)
plugin-ai 77.32% <83.73%> (?)
plugin-base 79.85% <ø> (?)
plugin-logging 77.65% <ø> (?)
plugin-proxy 77.30% <ø> (?)
starters 79.06% <ø> (?)
starters-agent 94.10% <ø> (?)
sync 66.05% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Aias00
Aias00 previously approved these changes Nov 14, 2026

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stream Agent analysis

Unify AI protocol detection via new shenyu-plugin-ai-protocol module and add ai-prompt support for openai-responses requests.

Evidence

  • Complete versioned diff read (has_more=false): 129,523 chars across 39 files incl. new shenyu-plugin-ai-protocol module and ai-proxy/ai-pii/ai-prompt/ai-common changes plus tests.
  • CI green: 92 checks completed, all success (build, CodeQL, e2e incl. cluster-jdbc/websocket/grpc/http-sync); no failed checks reported.
  • Verified cross-module contract: AiProtocolDetector (path->header->body, UNKNOWN on tier ambiguity, cached on exchange via Constants.AI_PROTOCOL) is consumed by ai-proxy (fail on unresolved), ai-pii (profile by detected id) and ai-prompt (responses injection); removed AiProxyProtocolFactory.getProtocol and per-protocol id fields are replaced by the detector registry with no dangling references (build success).

Recommended next steps

Scope: captured diff and GitHub check metadata only; no local tests were executed.

Task: 4562e7ca-3802-42fd-a200-1dc8e9a44a31 · Commit: 4d47d771882e41d53e0803e6a4c76d86d10c4141

Review verdict: PASS

Full diff coverage achieved, CI passing with no failed checks, and no concrete HIGH/CRITICAL defect identified. The new detection module is cohesive and consistently wired across ai-proxy/ai-pii/ai-prompt; the removed resolution method and per-protocol id fields are superseded by the detector registry, and the remaining AiProxyProtocolFactory usage is consistent (compile/tests pass).

Publication: APPROVE (EXPLICIT_PASS)

@eye-gu
eye-gu force-pushed the feature/ai-protocol-detection branch from 2f2d0e4 to ea147cc Compare November 18, 2026 01:09

This branch has not been deployed

No deployments
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.

[Task] Unify AI protocol detection and support ai-prompt for more protocols

3 participants