perf(internal): make the Python command check of service name inference linear #22292
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 255 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.332
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #22292"
general
weight: 0.35
dubloom
Description
APPSEC-72086
PythonDetector, used to infer the base service name fromsys.argv, checks whether an argument is a Python executable with(^|/)(?!.\.py$)(python(\d+(\.\d+)?)?$)andre.search. At every/the lookahead scans to the end of the line, so an argument made of many/takes time quadratic in its length.The lookahead is removed. Wherever the rest of the pattern matches, the text from that point to the end of the line is
pythonwith an optional version, which cannot end with.py; and.cannot reach past the end of the line. So the lookahead never rejected a match, and the matches and groups are unchanged. The comment above the pattern now says that, because the argument must end right afterpythonand its optional version, it cannot end with.py.Customer impact
None: the same arguments are recognized, and the input is the process's own command line. There is no release note, hence the
changelog/no-changeloglabel.Testing
"/" * 200_000 + ".", bounded at 1 s. It takes about 19 s with the previous regex locally, and 5 ms now.test_python_detector_pattern_matchingcases, includingpython.pyand/path/to/python.py, still pass./,python,py,., digits,.py, newlines and other characters.internalsuite,tests/internal/service_name/test_inferred_base_service.py(Python 3.9 and 3.14): 77 passed.scripts/lint styleandtypingon the changed files.Risks
None: the output is the same for every argument.
Additional Notes
Needed for #22282, which fails on any superlinear regex in
ddtrace/.🤖 Generated with Claude Code
[APPSEC-72086]: https://datadoghq.atlassian.net/browse/APPSEC-72086?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ