perf: make the Ray entrypoint and LLM judge template regexes linear #22194
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 303 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.342
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #22194"
general
weight: 0.35
dubloom
Description
APPSEC-72086
Two regexes owned by ML Observability could take time quadratic in their input on inputs that do not match, because each failed attempt rescanned the rest of the input from the next position. Both now run in linear time with the same results.
ENTRY_POINT_REGEX, called with.searchbyget_dd_job_name_from_entrypointand theexec_entrypointwrapper: the lookbehind(?<![^\s\/\\])lets a match start only at the beginning of a run of non-separator characters. Any match that starts inside a run can also be reached from the start of that run, so the first match and its group are unchanged.\{\{(?:(.+?)\}\}|.*). When a{{has no}}after it on the same line, no later{{on that line has one either. The second alternative then takes the rest of the line, andreplacereturns it unchanged. Closed placeholders are rendered as before.Customer impact
None. Both regexes read input that the application developer writes (the Ray job entrypoint command and the evaluator prompt template), and the results are the same. There is no release note, hence the
changelog/no-changeloglabel.Testing
- a 32,000-character entrypoint without
.py, which takes about 7 s with the previous regex locally;- a 60,000-character template of unclosed placeholders, which takes about 4.6 s.
- entrypoints with
/and\paths, a dotted script name, and a bare.pyargument;- a template with unclosed placeholders on one line and a closed one on the next.
scripts/run-tests:-
contrib::ray,-k test_ray_utils(Python 3.11 and 3.13);-
llmobs::llmobs,-k test_llm_judge(3.9 and 3.13).scripts/lint checks.Risks
None: both changes give the same results on every input.
Additional Notes
Follow-up to #22183 and #22192, under the same Jira ticket.
🤖 Generated with Claude Code
[APPSEC-72086]: https://datadoghq.atlassian.net/browse/APPSEC-72086?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ