perf(ci_visibility): make four CI Visibility and testing regexes linear #22200
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 581 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 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.381
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #22200"
general
weight: 0.35
gnufede
Description
APPSEC-72086
Four regexes in CI Visibility and the testing plugin could take time quadratic in their input on some inputs, because each failed attempt rescanned the rest of the input. They now run in linear time, with the same results on the inputs they are called with.
testing/internal/git.py), called with.searchon git's stderr: the regex is replaced by_is_git_lock_error(). It uses_contains_in_order(), which finds each part withstr.findat least one character after the previous one ends, as.+required. ForUnable to create .+\.lock.+File exists, the earliestUnable to createand then the earliest.lockafter it leave the most room for what follows, so checking only those is enough. The same holds forcannot lock ref .+ but expected.ci_visibility/recorder.py): the name group is[^/\n]?instead of.?, so a failed attempt cannot rescan past the next/or newline. The regex is also compiled once at module level.testing/internal/pytest/utils.py): compiled withre.DOTALL, so the name group always reaches the end and a failed name can no longer force a rescan.testing/internal/session_manager.py): anchored with^. Its call site usesre.match, which was already linear, so this changes nothing there. A scan of the repository's regexes, which assumesre.search, flags the unanchored pattern; the anchor keeps it linear if the call changes.Customer impact
None. These inputs are git output, repository URLs and pytest node IDs, and the results are the same. There is no release note, hence the
changelog/no-changeloglabel.Testing
-
_is_git_lock_erroron'cannot lock ref ' 30_000: about 8 s;- the repository-name regex on
'a/' 30_000 + '\nx': about 17 s;-
nodeid_to_nameson a 60 KB node ID with a newline: about 3 s.-
_is_git_lock_erroron the three messages from the module comment, three near misses, and the boundaries: one character between the parts is a lock error, none is not, as with the previous regex;-
nodeid_to_nameson a node ID with a newline in its test name, the one declared behavior change.scripts/run-tests:-
ci_visibility::ci_visibility,-k repository_name(Python 3.9 and 3.15);-
ci_visibility::testing,-k "IsGitLockError or GitLockRetry or NodeIdToTestRef"(3.9 and 3.15).scripts/lint checks.Risks
/and::; a newline in the module path or the test name made the match fail, so the node ID fell back tounknown_moduleandunknown_suite. Pytest escapes newlines in parametrize IDs, so this needs a test file path or a custom item name that contains a newline.Additional Notes
ddtrace/internal/coverage/report.pywas dropped from this PR. That file is frozen for theddtrace-coverageextraction (frozen-paths.txt, #22134), so it is left unchanged here, and the fix should land in the extracted package instead. The previous regex,^\s(?P<command>.)\s#.\s+pragma\s:\sno\s?cover.$, is quadratic on long source lines with many#, such as'# ' n. A linear replacement with the samecommandon every stripped line is: find the last match of\spragma\s:\sno\s?cover, then take everything before the last#that comes before it (text[:text.rfind("#", 0, match.start())]), or no match when either is missing.(?:.git)has an unescaped.and is not optional, so a URL ending in/org/my-digitgives the service namemy-d. Fixing it changes behavior, so it belongs in a separate change with a release note.🤖 Generated with Claude Code
[APPSEC-72086]: https://datadoghq.atlassian.net/browse/APPSEC-72086?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ