Skip to content

ci: avoid catastrophic backtracking in aidev anchor check - #22046

Open
wconti27 wants to merge 1 commit into
mainfrom
wconti27/fix-aidev-anchor-regex
Open

wconti27 wants to merge 1 commit into
mainfrom
wconti27/fix-aidev-anchor-regex

Conversation

@wconti27

Copy link
Copy Markdown
Contributor

Description

Fix the deprecated-anchor check so it no longer hangs on lines with many escaped quotes.

The check removes quoted strings from each added line before it looks for the deprecated label. The old string pattern let a backslash match two ways: as part of an escape pair and as a plain character. A line with many escaped quotes and no closing quote then took exponential time. The CI job ran until its timeout.

The new pattern uses the unambiguous form "(?:[^"\\]|\\.)*" for each quote character (", ' and a backtick). Each character has one way to match. Results for normal input do not change.

Customer impact

None. This is a CI script.

Testing

  • Added regression tests: a line with 200 escaped quotes must scan in under one second, for each quote character. Without the fix, these tests time out.
  • Added tests that a real label is still found after a long escaped string, and is still ignored inside an escaped string.
  • Ran the script on the diff of feat(crewai): support crewai 1.x [SIGN-45] #21455, which hung before. It now finishes in about 0.2 seconds and reports no new labels. The old script was stopped after 120 seconds.
  • Added a real label to that diff. The script reports it and exits with code 1.

Risks

None. The script only runs in CI.

Additional Notes

Edge case: an unterminated string that ends in a backslash before its last quote, such as "abc\", is no longer treated as a closed string. This follows normal string rules. The check still matches the label anywhere on the line first, so no label is missed.

🤖 Generated with Claude Code

STRING_RE let a backslash match both the escape branch and the generic
any-character branch, so lines with many escaped quotes and no closing
quote took exponential time to scan. Use the unambiguous
"(?:[^"\\]|\\.)*" form per quote character and add regression tests.

Environment: Datadog workspace

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@wconti27
wconti27 requested review from a team as code owners November 23, 2026 22:52
@wconti27
wconti27 requested review from danielsn and juanjux and removed request for a team November 23, 2026 22:52
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T22:53:47.516643Z 60790e7 PR opened
🔒 Security Review ✅ Completed 2026-11-23T22:57:30.480865Z 60790e7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

scripts/check_no_new_aidev_anchors.py                                   @DataDog/apm-python-guild
tests/internal/test_check_no_new_aidev_anchors.py                       @DataDog/apm-core-python

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 22 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 22 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=103)
ddtrace.llmobs._integrations.bedrock_agents -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=101)
ddtrace.llmobs._integrations.base -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=101)
ddtrace.internal.span_bus -×-> ddtrace._trace.span  (internal-core -> product:tracing, score=35)
ddtrace.llmobs._llmobs -×-> ddtrace._trace.span  (product:llmobs -> product:tracing, score=33)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Direct timing and detection probes support that all three quote forms avoid the reported backtracking while preserving anchor detection. No actionable regression was identified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 60790e7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant