Skip to content

fix(api): answer 400 for a non-JSON body on POST /api/chaos/run and POST /api/skills/collect/chaos - #16991

Merged
diegosouzapw merged 2 commits into
cheaper-inference:release/v3.8.52from
pacocartones:fix/chaos-malformed-json-400
Oct 18, 2026
Merged

diegosouzapw merged 2 commits into
cheaper-inference:release/v3.8.52from
pacocartones:fix/chaos-malformed-json-400

Conversation

@pacocartones

@pacocartones pacocartones commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Related Issues

  • None found: no open or closed pull request or issue covers this (checked by touched path over the 296 open pull requests, with a positive control, and by keyword over merged and closed pull requests, 16 October).

Target Branch

  • Base is the active release/v3.8.x branch (release/v3.8.52), not main
  • Not a feature: a fix.

Validation

  • Change type: other (chaos API routes)
  • Focused test: the new file below fails on the base for the two non-JSON cases and passes with the change.
  • The existing chaos tests pass with the change (chaos-api-routes, chaos-executor, chaos-config and the new file: 30 tests).
  • prettier --check and eslint on the changed files are clean; check:ai-attribution and check:changelog-integrity pass.
  • Full CI: runs on this PR.
  • Production-code change includes a new automated test in this PR.

Tests Added Or Updated

  • tests/unit/chaos-malformed-json-400.test.ts (new): a body that is not JSON sent to each route, with Chaos Mode enabled and, for the external route, an API key with chaosModeEnabled, must answer 400 with Invalid JSON body; a well-formed but invalid body must still answer 400 as before. On the base the two non-JSON cases fail with 500 !== 400; with the change they pass.

Coverage Notes

  • The change is in src/; the new test calls the handlers directly, with the same setup as chaos-api-routes.test.ts. I did not run the routes under the Next.js server.
  • On both routes the body is read after the auth check and after Chaos Mode is confirmed enabled (/api/chaos/run) or after the API key is verified (/api/skills/collect/chaos), so a caller that is not allowed still gets 401, 403 or the "not enabled" 400 first.

Reviewer Notes

  • Changelog fragment: changelog.d/fixes/PENDING-chaos-json-400.md, one line, left for you to rename.

@diegosouzapw
diegosouzapw merged commit 6ce866c into cheaper-inference:release/v3.8.52 Oct 18, 2026
41 of 60 checks passed
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.

2 participants