← Back to Pull requests

perf: make the Ray entrypoint and LLM judge template regexes linear #22194

Closed
unknown closed this pull request without merging on Dec 02, 2026 16:51 UTC
View on GitHub
unknown unknown commented on Nov 30, 2026 16:07 UTC
Author

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.

  • Ray ENTRY_POINT_REGEX, called with .search by get_dd_job_name_from_entrypoint and the exec_entrypoint wrapper: 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.

  • LLM judge template rendering: the placeholder regex is now \{\{(?:(.+?)\}\}|.*). 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, and replace returns 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-changelog label.

    Testing

  • New linear-time tests, bounded at 1 s:

  • - 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.
  • New behavior tests:

  • - entrypoints with / and \ paths, a dotted script name, and a bare .py argument;
    - a template with unclosed placeholders on one line and a closed one on the next.
  • Not committed: the old and new regexes give the same first match and group on 300,000 random entrypoints, and the same rendered template on 300,000 random templates.

  • Local runs with 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

    Diff: 303 lines (+227 / -76) across 3 files Reviewer: dubloom Review duration: 2923m
    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
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.1% (MEDIUM) · Higher = larger blast radius
    45.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.8% · Safe to merge
    17.8%