Repository navigation
COLDBOX-1468 Answer 400 when a toAi() body is not a JSON object - #728
Merged
Merged
Conversation
The invoke, stream and batch routes passed the result of
getHTTPContent( json: true ) straight to resolveAiContext( struct ).
A missing body, invalid JSON, a JSON array or a JSON string made that
a type error and the request ended as a 500. They now share one body
check and answer 400 with { "error": true, "message": ... }.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BJdN5wqon9WEbCykxdPcNN
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BJdN5wqon9WEbCykxdPcNN
The local cfformat reflowed a line outside this change, which the CI formatter rejects. Restore it and keep the 400 payload in a local variable like the other renderData calls in the router. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BJdN5wqon9WEbCykxdPcNN
Member
Author
|
CI status on this PR so far: the formatting check was mine and is fixed in 15433cb. The two remaining test failures are not caused by this change:
This PR only touches the toAi() routes in Generated by Claude Code |
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BJdN5wqon9WEbCykxdPcNN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
toAi()routes ({base}/invoke,{base}/stream,{base}/batch) answered HTTP 500 when the request had no body, or the body was not a JSON object.event.getHTTPContent( json: true )returns an empty string for no body or invalid JSON (and an array or string for those JSON types), andresolveAiContext( required struct body )then failed with a type error. Introduced with COLDBOX-1417.They now answer 400 with
{ "error": true, "message": "The request body must be a JSON object" }for: no body, invalid JSON, a JSON array and a JSON string. A valid object body behaves exactly as before.The check lives in two private helpers,
resolveAiBody()andrejectAiBody(), shared by the three routes.Jira Issues
https://ortussolutions.atlassian.net/browse/COLDBOX-1468
Type of change
HTTP verb finding (not changed here)
The routes declare
"verbs": "POST", but a PUT with a valid body also returns 200. Cause:RoutingService.cfconly setsisInvalidHTTPMethodon the event for a verb mismatch.Controller.runEventis the only place that acts on that flag, and it only runs for handler events.response(closure) go straight torenderResponse(), so the verb is never checked.This affects every
responseroute (toResponse(), closure responses,toMCP(),toAiGateway()), not onlytoAi(). Enforcing it (405) would change behavior for all of them, so I left it out of this fix. Proposal: a follow-up ticket to enforceverbsforresponseroutes inRoutingService, or if you prefer a narrow fix, a 405 check inside the three toAi closures.Testing
RouterAITest.cfc: 12 new specs (4 bad bodies x invoke/stream/batch) plus the unchanged valid-body case for invoke and batch. Without the fix the 12 reject specs error; with it all 34 pass.RouterTest,RouterGatewayTestandRouterSSETeststill pass. Run on BoxLang 1.18.0 with bx-ai 3.6.0. The stream route is only covered for the 400 cases, since a valid stream needs theSSE()BIF.Not run locally:
cfformat(CommandBox could not reach ForgeBox through the sandbox proxy), so formatting was matched by hand. CI will check it.Checklist
Generated by Claude Code