Skip to content

fix: harden linear token sequence matcher#111

Draft
jbachorik wants to merge 2 commits into
mainfrom
agent/logs-reggie-l1a
Draft

fix: harden linear token sequence matcher#111
jbachorik wants to merge 2 commits into
mainfrom
agent/logs-reggie-l1a

Conversation

@jbachorik

Copy link
Copy Markdown
Collaborator

Summary

  • make cached LinearTokenSequenceMatcher execution state per-call and make bracket-tail scanning linear
  • admit the named-capture LTS route only when every Grok-observable named group has a capture-producing plan operation
  • add concurrency, projection, and JDK-differential coverage for the expanded Grok access-log fixtures

Why

Grok consumes named capture indexes only. The named-only projection preserves those indexes, but the LTS plan could previously select a route that did not populate every named group. This change declines that route and lets the normal strict compiler choose the implementation instead.

Validation

  • ./gradlew --rerun-tasks :reggie-codegen:test --tests '*LinearTokenSequencePlanTest' :reggie-runtime:test --tests '*LinearTokenSequenceMatcherTest' --tests '*LinearTokenSequenceAccessLogTest'
  • ./gradlew jacocoVerify build

@codecov-commenter

codecov-commenter commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.66667% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.4%. Comparing base (f437ac8) to head (32b245e).

Files with missing lines Patch % Lines
...ghq/reggie/runtime/LinearTokenSequenceMatcher.java 94.8% 0 Missing and 3 partials ⚠️
...ggie/codegen/analysis/LinearTokenSequencePlan.java 93.7% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##              main    #111   +/-   ##
=======================================
  Coverage     84.3%   84.4%           
  Complexity       1       1           
=======================================
  Files          147     147           
  Lines        42922   42955   +33     
  Branches      5845    5851    +6     
=======================================
+ Hits         36213   36255   +42     
+ Misses        4919    4916    -3     
+ Partials      1790    1784    -6     
Files with missing lines Coverage Δ
.../com/datadoghq/reggie/runtime/RuntimeCompiler.java 88.3% <100.0%> (+<0.1%) ⬆️
...ggie/codegen/analysis/LinearTokenSequencePlan.java 81.7% <93.7%> (+1.9%) ⬆️
...ghq/reggie/runtime/LinearTokenSequenceMatcher.java 76.5% <94.8%> (+4.3%) ⬆️

... and 1 file 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 f437ac8...32b245e. Read the comment docs.

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

Copilot AI 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.

Pull request overview

This PR hardens the runtime Linear Token Sequence (LTS) matcher to be safer under concurrency and more correct for Grok-style “named-only” capture projection, while adding targeted regression/performance tests around these behaviors.

Changes:

  • Make LTS execution state per-invocation (removing shared scratch arrays) and make bracket-tail scanning linear-time.
  • Gate runtime LTS routing on whether the plan actually covers all named capture indexes (avoid selecting an LTS route that can’t populate Grok-observable named groups).
  • Add new correctness, JDK-differential, and concurrency tests for named-only routing and bracket scanning edge cases.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
reggie-runtime/src/main/java/com/datadoghq/reggie/runtime/RuntimeCompiler.java Refines LTS routing by requiring plans to cover all named capture indexes before selecting the LTS matcher.
reggie-runtime/src/main/java/com/datadoghq/reggie/runtime/LinearTokenSequenceMatcher.java Removes shared scratch state, introduces per-call workspace, and replaces bracket scanning with a linear pass.
reggie-codegen/src/main/java/com/datadoghq/reggie/codegen/analysis/LinearTokenSequencePlan.java Adds coversCaptureIndexes(...) to verify a plan has capture-producing ops for required group indexes (including inside optional sequences).
reggie-codegen/src/test/java/com/datadoghq/reggie/codegen/analysis/LinearTokenSequencePlanTest.java Adds unit tests validating capture-coverage semantics (optional nesting, named-group coverage, invalid indexes).
reggie-runtime/src/test/java/com/datadoghq/reggie/runtime/LinearTokenSequenceMatcherTest.java Adds routing regression test for named-only coverage plus new bracket-scanning edge/perf tests.
reggie-runtime/src/test/java/com/datadoghq/reggie/runtime/LinearTokenSequenceMatcherConcurrencyTest.java Introduces concurrent-use stress tests for cached LTS matchers and nested optional rollback behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +69 to +73
ExecutorService executor = Executors.newFixedThreadPool(threads);
CountDownLatch ready = new CountDownLatch(threads);
CountDownLatch start = new CountDownLatch(1);
CountDownLatch done = new CountDownLatch(threads);
ConcurrentLinkedQueue<Throwable> failures = new ConcurrentLinkedQueue<>();
Comment on lines +114 to +118
ExecutorService executor = Executors.newFixedThreadPool(threads);
CountDownLatch ready = new CountDownLatch(threads);
CountDownLatch start = new CountDownLatch(1);
CountDownLatch done = new CountDownLatch(threads);
ConcurrentLinkedQueue<Throwable> failures = new ConcurrentLinkedQueue<>();
Comment on lines +134 to +136
private MatchWorkspace newWorkspace() {
return new MatchWorkspace(groupCount, optionalDepth);
}
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

3 participants