Skip to content

fix: fallback to cjson after simdjson decode errors#13449

Open
nic-6443 wants to merge 2 commits into
apache:masterfrom
nic-6443:codex/simdjson-decode-fallback
Open

fix: fallback to cjson after simdjson decode errors#13449
nic-6443 wants to merge 2 commits into
apache:masterfrom
nic-6443:codex/simdjson-decode-fallback

Conversation

@nic-6443
Copy link
Copy Markdown
Member

@nic-6443 nic-6443 commented May 28, 2026

Description

When apisix.request_body_json_lib is set to simdjson, request body decoding now logs a warning and retries with cjson if simdjson returns a decode error. This keeps simdjson as the default fast path while preserving the existing cjson behavior as a fallback path.

This also updates api7-lua-resty-simdjson to 0.1.2-1, which includes decoder state cleanup after errors.

Checklist

  • Tests added
  • Documentation updated

Tests

  • TEST_NGINX_CASE=19 prove -Itest-nginx/lib -I. -r t/core/request.t
  • prove -Itest-nginx/lib -I. -r t/core/request.t
  • prove -Itest-nginx/lib -I. -r t/plugin/ai-proxy-simdjson-error-state.t

Copilot AI review requested due to automatic review settings May 28, 2026 11:28
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 28, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves robustness of JSON request-body decoding when apisix.request_body_json_lib is set to simdjson by retrying with cjson after simdjson decode failures, aiming to keep simdjson as the fast path while preserving previous cjson compatibility.

Changes:

  • Add a simdjson→cjson fallback path in apisix.core.request_json.decode() with a warning log on simdjson decode failures.
  • Update api7-lua-resty-simdjson dependency to 0.1.2-1.
  • Add/adjust tests and update ai-proxy documentation (EN/ZH) to reflect the fallback behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
apisix/core/request_json.lua Adds simdjson decode wrapper that logs and falls back to cjson decoding on failure.
apisix-master-0.rockspec Bumps api7-lua-resty-simdjson version to include decoder cleanup after errors.
t/core/request.t Adds a regression test ensuring fallback to cjson occurs and warning is logged; renumbers subsequent tests.
docs/en/latest/plugins/ai-proxy.md Documents warning + retry-with-cjson behavior for simdjson mode.
docs/zh/latest/plugins/ai-proxy.md Same documentation update in Chinese.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apisix/core/request_json.lua
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants