Skip to content

Fix NUL collisions in runtime cache keys - #152

Merged
jbachorik merged 1 commit into
mainfrom
fix/cache-key-nul-collision
Oct 20, 2026
Merged

jbachorik merged 1 commit into
mainfrom
fix/cache-key-nul-collision

Conversation

@jbachorik

Copy link
Copy Markdown
Collaborator

What does this PR do?

Replaces NUL-delimited string cache identities with an immutable structural key containing the
source pattern, flags, and enabled ReggieOption values.

The structural key is used consistently by the level-1 matcher cache and all runtime
engine/factory caches. Annotation-stub backtracker entries now have a separate string-keyed cache,
matching the existing PikeVM stub/runtime separation.

Regression coverage exercises the formerly colliding identities in both call orders through:

  • the shared level-1 matcher cache;
  • mutable hybrid/factory reconstruction;
  • the runtime backtracking cache, including JDK capture-span parity;
  • explicit cached(key, pattern, options) validation.

Motivation

NUL is a supported pattern literal, so concatenating option names to the pattern with a NUL
separator is not injective. For example, these two identities previously produced the same engine
key:

pattern="a", options=CAPTURE_NAMED_ONLY
pattern="a\0CAPTURE_NAMED_ONLY", options=DEFAULT

That could return a matcher compiled for a different pattern instead of compiling independently or
throwing for reuse of an explicit user key.

This follows up the finding on #149:
#149 (comment)

Knowledge constraint consumed: kb/find-nul-pattern-truncation — pattern-side NUL remains valid
data and must not be treated as a sentinel or separator.

Related Issue(s)

Follow-up to #149.

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

No matching-path impact is expected. Compilation-cache lookup now hashes a small immutable value
object instead of a delimiter-encoded string. Default and non-default option identities use the
same structural representation.

Additional Notes

Verification completed:

  • focused cache-key, user-cache, cache-hygiene, diagnostic, and shared-DFA tests;
  • full :reggie-runtime:test suite (3,667 tests);
  • ./gradlew build;
  • :reggie-integration-tests:test;
  • spotlessApply / spotlessCheck;
  • git diff --check.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T19:59:25.275571Z 35724ba 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.

@datadog-prod-us1-4 datadog-prod-us1-4 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

The structural keys keep literal-NUL patterns distinct from option-bearing compilations across runtime caches, including explicit user-key validation and mutable matcher reconstruction. The completed static review identified no reportable regression.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 35724ba

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.0%. Comparing base (e37366f) to head (35724ba).

Additional details and impacted files
@@           Coverage Diff           @@
##              main    #152   +/-   ##
=======================================
  Coverage     85.0%   85.0%           
  Complexity       1       1           
=======================================
  Files          168     168           
  Lines        49878   49882    +4     
  Branches      7594    7592    -2     
=======================================
+ Hits         42409   42417    +8     
+ Misses        5466    5464    -2     
+ Partials      2003    2001    -2     
Files with missing lines Coverage Δ
.../com/datadoghq/reggie/runtime/RuntimeCompiler.java 82.9% <100.0%> (+0.2%) ⬆️

... 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 e37366f...35724ba. 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 merged commit 23a61fd into main Oct 20, 2026
9 checks passed
@jbachorik
jbachorik deleted the fix/cache-key-nul-collision branch October 20, 2026 05:59
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.

2 participants