luigidemasi commented on code in PR #150:
URL: https://github.com/apache/camel-kit/pull/150#discussion_r4479570454
##########
kit/camel-kit-core/src/main/java/org/apache/camel/kit/ship/controller/ShipStageResult.java:
##########
@@ -47,6 +48,8 @@ record ShipStageResult(
private static final int MAX_ASSISTANT_BYTES = 1024 * 1024;
private static final int MAX_REPORT_BYTES = MAX_ASSISTANT_BYTES;
private static final Pattern ROUTE_ID =
Pattern.compile("[A-Za-z0-9][A-Za-z0-9_.-]{0,127}");
+ private static final Pattern JSON_FENCE = Pattern.compile(
+ "```(?:json)?\\s*\\n(\\{.*?\\})\\s*\\n```", Pattern.DOTALL);
Review Comment:
[P2] Bound malformed-fence scanning before parsing worker output
`Matcher.find()` retries this DOTALL `.*?` pattern at every opening fence. A
response consisting of `"```json\n{".repeat(20_000)` is only 180,000 bytes, but
each opener scans the remaining response looking for a closing brace/fence. On
Java 21, parser-only measurements grew from 2.56 s at 90 KB to 9.06 s at 180
KB; 900 KB exceeded a 12 s process limit. The base parser rejects those same
inputs in about 0.2 s. Through the real coordinator/RPC fixture, the 180 KB
input took 10.8 s versus 0.33 s with the base parser.
This runs synchronously in `commitWorker()` after the worker has returned,
so the worker timeout does not bound this CPU work. A malformed model response
can therefore stall the caller despite passing the input-size guard. Please
scan the permitted fence structure in bounded/linear work and add a regression
case with many unfinished openers; keep Jackson responsible for validating the
extracted object.
_AI-generated by Codex on behalf of @luigidemasi._
--
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]