Skip to content

fix: PINNED_BACKREFERENCE bugs from review - #97

Merged
jbachorik merged 4 commits into
mainfrom
jb/subfix
Jul 7, 2026
Merged

jbachorik merged 4 commits into
mainfrom
jb/subfix

Conversation

@jbachorik

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fixes correctness bugs and remaining review findings in the PINNED_BACKREFERENCE strategy (a single-forward-scan matcher for backreference patterns like (\w+)\s+\1 where the group's charset is provably disjoint from what follows it):

  • Non-capturing-group-wrapped separator quantifiers (e.g. (?:\s+)) were silently treated as exactly-one-occurrence instead of honoring their real bounds.
  • A capturing group nested inside the pinned group's body or its separator silently broke totalGroupCount(), causing group(n) to be inaccessible or throw.
  • Removed an unnecessary, allocation-equal, -1-buggy custom matchBounded/shiftSpans override in favor of the correct base-class default.
  • Tightened minCandidateLength() to use the real group/separator minimum lengths instead of hardcoded values.
  • Fixed stale javadoc examples and a mislabeled test section that referenced patterns no longer routed to this strategy.
  • Added detector unit tests that kill two previously-surviving mutants (||→&& and <1→<0 on the span/separator-length checks).

Motivation

Follow-up from the PINNED_BACKREFERENCE strategy review (PR #94) — a multi-stream code review surfaced a CRITICAL correctness bug and several HIGH/MEDIUM/LOW findings, all addressed here.

Related Issue(s)

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring (no functional change)
  • Documentation
  • Test improvement
  • Build/CI change

Checklist

  • I have read the CONTRIBUTING.md guidelines
  • All existing tests pass (./gradlew build)
  • I have added tests for my changes
  • I have updated documentation (if applicable)
  • My commits are signed

Performance Impact

minCandidateLength() now prunes more candidates before scanning (uses real group/separator minimum lengths instead of hardcoded 1s); no other performance-relevant change.

Additional Notes

Both commits on this branch (PINNED_BACKREFERENCE fixes) were produced with AI assistance (Claude Code) and reviewed by me.

@jbachorik jbachorik added the AI Generated or assisted by AI label Jul 7, 2026
@codecov-commenter

codecov-commenter commented Jul 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.69231% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.1%. Comparing base (343e776) to head (8d58197).

Files with missing lines Patch % Lines
...doghq/reggie/codegen/analysis/PatternAnalyzer.java 67.8% 6 Missing and 12 partials ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##              main     #97     +/-   ##
=========================================
- Coverage     83.8%   83.1%   -0.7%     
  Complexity       1       1             
=========================================
  Files          134     134             
  Lines        41162   41223     +61     
  Branches      5522    5548     +26     
=========================================
- Hits         34500   34288    -212     
- Misses        4957    5217    +260     
- Partials      1705    1718     +13     
Files with missing lines Coverage Δ
...ggie/codegen/analysis/PinnedBackreferenceInfo.java 100.0% <100.0%> (ø)
.../codegen/PinnedBackreferenceBytecodeGenerator.java 100.0% <100.0%> (ø)
...ggie/processor/ReggieMatcherBytecodeGenerator.java 73.6% <ø> (-0.1%) ⬇️
.../com/datadoghq/reggie/runtime/RuntimeCompiler.java 87.8% <ø> (-0.1%) ⬇️
...doghq/reggie/codegen/analysis/PatternAnalyzer.java 76.0% <67.8%> (-0.1%) ⬇️

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 343e776...8d58197. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jbachorik
jbachorik marked this pull request as ready for review July 7, 2026 17:34

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b0d29b2322

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +3655 to +3656
separatorMinLength = sepQuant.min;
separatorMaxLength = sepQuant.max;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject multi-character separator atoms before using bounds

When the separator quantifier wraps an atom that consumes more than one character, these fields are repetition counts, but generateSeparatorLengthCheck compares them to sepLen, the number of characters scanned. For example, (\w+)(?:--){2}\1 is still accepted by this detector because the first separator charset is -, but the generated matcher scans four hyphens and rejects it as 4 > max(2), so a valid input like ab----ab becomes a false negative. Either reject non-single-character separator atoms here or convert the bounds to character lengths before passing them to codegen.

Useful? React with 👍 / 👎.

jbachorik and others added 4 commits July 7, 2026 20:34
Require group/backref pair to span the whole pattern, enforce
group/separator length bounds in generated bytecode, and fix
matchBounded to report absolute (not substring-relative) spans.
Patterns with anchors outside the span now correctly fall through
to VARIABLE_CAPTURE_BACKREF.
Tighten minCandidateLength to real group/separator bounds, fix stale
javadoc examples and test labels, add mutation-killing detector tests.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Adds coverage for the non-capturing-group separator unwrap, lazy
separator rejection, and nested-capturing-group rejections flagged
as uncovered by codecov.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
generateSeparatorLengthCheck compares a scanned character count against
separatorMinLength/separatorMaxLength, but detectPinnedBackreference set
those from the raw quantifier repetition count (e.g. 2 for (?:--){2}
instead of 4 chars), rejecting valid matches like ab----ab.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jbachorik
jbachorik merged commit 5db1866 into main Jul 7, 2026
9 checks passed
@jbachorik
jbachorik deleted the jb/subfix branch July 7, 2026 18:44
@jbachorik jbachorik added this to the 0.4.0 milestone Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Generated or assisted by AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants