perf(ci_visibility): make the coverage no-cover pragma check linear #22226
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 · 432 lines diff across 5 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.363
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #22226"
general
weight: 0.35
gnufede
Description
APPSEC-72086
no_cover()inddtrace/internal/coverage/report.pymatches each stripped source line against^\s(?P<command>.)\s#.\s+pragma\s:\sno\s?cover.$. The command group, the whitespace before#and the whitespace beforepragmacan all take the same whitespace runs, so a line with a long run of spaces on both sides of a#and no pragma takes time cubic in its length. With 2,000 spaces on each side, one match takes about 9.5 s.NOCOVER_PRAGMA_REis now\spragma\s:\sno\s?cover, and the new_nocover_command()returns the text before the last#that comes before the last pragma match. That is the#the greedy command group chose, so the command is the same. Two pragma matches can't overlap, so the lastfinditermatch is the last place a pragma starts; a one-line comment above the loop says so. Lines like#pragma: no coverandpragma: no coverstill don't count as pragmas, as with the old regex: this PR keeps the existing behavior.report.pyis frozen for the ddtrace-coverage extraction. It is unfrozen with the agreement of the ddtrace-coverage extraction owner (@gnufede), so this PR removes its entry fromfrozen-paths.txt, as the manifest header describes.frozen-paths.txtis owned by@DataDog/apm-core-python. I will add the entry back with the new hash in a follow-up PR right after this one merges:Customer impact
None. Since #13982 removed the old pytest plugin (v3.11.0),
ModuleCodeCollector.report()andwrite_json_report_to_file()are only called from tests, and the result is the same. There is no release note, hence thechangelog/no-changeloglabel.Testing
tests/coverage/test_report.py:_nocover_commandonpragma: no coverandpragma: nocover, a#inside a string before the comment, text between#andpragma, a string containing a pragma before the real one (fails if the loop is replaced bysearch()), and four lines that are not pragmas, including a pragma with no#before it (fails if the#check is dropped)."# " 30_000, bounded at 1 s. It takes about 15 s with the previous regex locally, and under 1 ms now.#, whitespace (including\x0c,\x1cand non-breaking spaces),:,pragma,no,cover,nocover, quotes and letters.ci_visibility::dd_coveragesuite: passed on Python 3.9 (100 passed) and 3.15 (165 passed).scripts/lint checksandscripts/lint typingonreport.py.Risks
Low: the result is the same for every line tested, and the code only runs when a coverage report is generated.
Additional Notes
This change was dropped from #22200 because of the freeze. The extracted copy of this file in DataDog/datadog-apm-python#82 (
packages/ddtrace-coverage/src/_ddtrace_coverage/report.py) has the same regex; I will port the same change there separately. Follow-up to #22183, #22192, #22194, #22200, #22215 and #22216, under the same Jira ticket.🤖 Generated with Claude Code
[APPSEC-72086]: https://datadoghq.atlassian.net/browse/APPSEC-72086?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ