nic-6443 opened a new pull request, #13461: URL: https://github.com/apache/apisix/pull/13461
### Description When the AI proxy (`ai-transport/http.lua`) forwards a request body to the upstream LLM provider, it currently serializes the body with `core.json.encode`, which does **not** guarantee a stable key order. Because many providers key their server-side prompt cache on the exact request bytes, a non-deterministic key order lowers the cache hit rate for otherwise-identical requests. This PR encodes the upstream request body with `rapidjson` using `sort_keys = true`, producing a deterministic key order. Details: - Empty arrays are preserved as `[]` (via `core.json.array_mt`) and `core.json.null` is mapped to JSON `null`, so the payload is semantically unchanged — only key order becomes stable. - Encoding **falls back to `cjson`** on any rapidjson error and logs it, so a serialization edge case can never fail the request. - Adds `rapidjson = 0.7.2-1` as a dependency. A second commit makes the new dependency build portably: `lua-rapidjson` enables `-march=native` by default, which can bake the build host's CPU features into the shipped `rapidjson.so` and crash on older CPUs. `ci/install-lua-rapidjson.sh` strips that flag and is wired into the Makefile / CI runner / dev image build. New test: `t/plugin/ai-transport-http.t` asserts sorted keys, empty-array preservation, and the cjson fallback path. ### Checklist - [x] I have explained the need for this PR and the problem it solves - [x] I have explained the changes or the new features added to this PR - [x] I have added tests corresponding to this change - [ ] I have updated the documentation to reflect this change - [x] I have verified that this change is backward compatible (falls back to cjson; payload semantics unchanged) > Note for reviewers: this introduces a new C dependency (`rapidjson`), built without `-march=native` for portable binaries. Verified locally: build succeeds with the flag stripped, and the encoder yields sorted / empty-array-preserving / null-preserving deterministic output. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
