Aias00 opened a new issue, #7474: URL: https://github.com/apache/shenyu/issues/7474
## Finding `AiPromptPlugin.doExecute()` obtains the plugin-level `AiPromptConfig` singleton and then writes rule-specific fields into that same object: - `shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-prompt/src/main/java/org/apache/shenyu/plugin/ai/prompt/AiPromptPlugin.java:63-76` - `shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-prompt/src/main/java/org/apache/shenyu/plugin/ai/prompt/handler/AiPromptPluginDataHandler.java:44-51` `AiPromptPluginDataHandler.handlerPlugin()` stores plugin config as a singleton. Request handling should treat that config as a base template, but `doExecute()` mutates it when a rule handle exists. ## Trigger / caller flow Two AI Prompt requests match different rules, or a later request has no/partial rule handle after a previous request applied rule overrides: `AbstractShenyuPlugin.execute()` -> `AiPromptPlugin.doExecute(exchange, chain, selector, rule)` -> `Singleton.INST.get(AiPromptConfig.class)` -> `CACHED_HANDLE.obtainHandle(ruleKey)` -> singleton setters. ## Actual behavior Per-rule `preRole`, `prepend`, `postRole`, and `append` values are written into the global singleton `AiPromptConfig`. Those values remain for subsequent requests and concurrent requests share the same mutable object. ## Expected behavior Each request should build an isolated effective config by copying plugin-level config and then applying rule-level overrides to the copy. Request execution should not mutate global plugin config. ## Impact Prompt text and roles from one selector/rule can bleed into unrelated AI requests until another rule overwrites them. Concurrent requests can also race on the same mutable config object. ## Suggested fix Add a copy constructor, clone method, or small factory for `AiPromptConfig`. In `doExecute()`: 1. Read the singleton base config. 2. Create a request-local copy. 3. Apply `AiPromptHandle` overrides to that copy. 4. Pass the request-local config downstream. Add a regression test where rule A sets a prepend value and a following request for rule B/no handle does not inherit rule A's value. ## Existing issue de-dupe This is not #6342, which covers an older bug that drops all messages except the first. This issue is about mutable singleton config leaking rule-specific values across requests. ## Validation - Source flow inspected at `a89b6a2338c24e978428b731e8f1edce86022418`. - `./mvnw -pl shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-prompt -Dtest=AiPromptPluginTest,AiPromptPluginDataHandlerTest test -DfailIfNoTests=false -Dcheckstyle.skip -Drat.skip=true -Djacoco.skip=true` passed. Existing tests do not cover cross-rule/request isolation. ## Reviewed Revision And Validation Apache ShenYu 2.7.2-SNAPSHOT, master at a89b6a2338c24e978428b731e8f1edce86022418. Severity: medium. Confidence: high. Isolated source/caller verification confirmed request-time mutation of the global AiPromptConfig. The actual #6043 screenshot identifies old AiProxyPlugin/AiCommonConfig, a different component. Current source references: - `shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-prompt/src/main/java/org/apache/shenyu/plugin/ai/prompt/AiPromptPlugin.java:63` - `shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-prompt/src/main/java/org/apache/shenyu/plugin/ai/prompt/handler/AiPromptPluginDataHandler.java:44` No implementation fix or full deployed end-to-end validation was performed by this review. Source-flow and runtime evidence are distinguished above. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
