Skip to content

refactor(mcp): use the shared pattern predicate for drill-downs - #3663

Merged
SpencerTorres merged 1 commit into
alex/FR-385-shared-pattern-predicatefrom
alex/FR-385-mcp-shared-pattern-predicate
Nov 18, 2026
Merged

SpencerTorres merged 1 commit into
alex/FR-385-shared-pattern-predicatefrom
alex/FR-385-mcp-shared-pattern-predicate

Conversation

@alex-fedotyev

@alex-fedotyev alex-fedotyev commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Switches clickstack_event_patterns to the shared pattern predicate from #3662 and deletes the MCP copy of templateToRegex, buildPatternPredicate and MAX_PREDICATE_TEMPLATE_LENGTH. Part of FR-385.

Stack

Layer 2 of 4 in a GitHub stack (stack #3682). GitHub shows each layer's base as the branch below it, but the stack's base is main: merging any PR lands it and every PR below it on main, one squashed commit each. Each PR's diff is only its own layer, and CI runs as if each targets main:

  1. feat(common-utils): share the Event Patterns drill-down predicate #3662 Share the pattern predicate in common-utils
  2. refactor(mcp): use the shared pattern predicate for drill-downs #3663 MCP uses the shared predicate (this PR)
  3. feat(common-utils): add a compact form of the pattern predicate #3664 Compact form of the predicate, short enough for a URL
  4. feat(app): filter for or exclude a pattern from Event Patterns #3665 Filter for or exclude a pattern from Event Patterns

Summary

Pure refactor. MCP mines without extra delimiters, so the whereSnippet it returns for each pattern is unchanged. PATTERN_MATCH_SEMANTICS, andSql and userWhereAsSql stay in patternDrilldown.ts, since only MCP uses them.

Test plan

  • unit: the existing patternDrilldown.test.ts tests import from common-utils and pass as they are
  • Compared the deleted MCP functions with the shared ones on 5,000 generated templates (wildcards, punctuation, quotes, backslashes, tabs, newlines, non-breaking spaces, CJK): no difference in the regex or the SQL, and a template over the length limit still gets no predicate
  • jest src/mcp in packages/api (29 suites, 578 tests), tsc --noEmit, eslint on the changed files, knip

@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Nov 18, 2026 1:46am UTC
hyperdx-storybook Ready Ready Preview Nov 18, 2026 1:46am UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 52672a1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/api Patch
@hyperdx/app Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -1,11 +1,11 @@
import { minePatterns } from '@hyperdx/common-utils/dist/drain';

import {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 minor — Tests for the common-utils predicate now sit in the api package, so common-utils' own suite doesn't cover them

Move the templateToRegex and buildPatternPredicate cases into packages/common-utils/src/__tests__/pattern-predicate.test.ts and keep only the andSql tests here. Today that file only tests extra delimiters and parsePatternPredicate. These cases cover escaping, quotes and backslashes, Unicode whitespace, empty templates and MAX_PREDICATE_TEMPLATE_LENGTH. Because they import the built @hyperdx/common-utils/dist/drain, changing pattern-predicate.ts and running the common-utils tests can't catch a regression in any of them. They also only run against whatever dist was last built.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Keeping these here: they pin the exact whereSnippet this tool returns, and the common-utils suite now also covers the length limit and the no-option round trip (04c8a76).

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 critical or 🟠 major in code this PR adds or changes: fix before asking for review.
  • 🔵 minor in code this PR changes: your call. Fix if small, otherwise reply.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    severity. Reply with one sentence; if it is critical, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

1 finding(s): 🔴 0 critical · 🟠 0 major · 🔵 1 minor

1 posted as inline comment(s) on the changed lines.


Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found.

This is a behavior-preserving refactor. The MCP clickstack_event_patterns tool drops its local templateToRegex, buildPatternPredicate, and MAX_PREDICATE_TEMPLATE_LENGTH and imports the shared versions from @hyperdx/common-utils/dist/drain.

Verification performed against the diff and both modules:

  • Default-path equivalence confirmed. The shared buildPatternPredicate/templateToRegex called with no options (the two-arg form the caller uses at packages/api/src/mcp/tools/query/runEventPatterns.ts:473) produces a byte-identical regex to the deleted copy: same JS_WHITESPACE (\s\x{0B}\pZ\x{FEFF}), same escapeRe2Literal escaping, same anchors, and the same MAX_PREDICATE_TEMPLATE_LENGTH = 4000. The returned whereSnippet is unchanged.
  • Predicate stays in sync with mining. minePatterns at runEventPatterns.ts:319 is called with no extraDelimiters and default (JS) whitespace, matching the predicate's default separator class — so the regex still matches the mined templates.
  • No stale references to the removed functions remain in packages/api, and the removed escapeSqlString import left no dangling usage in patternDrilldown.ts. The MCP-only PATTERN_MATCH_SEMANTICS, andSql, and userWhereAsSql are correctly retained.
  • Tests re-point imports to common-utils (with andSql still from the local module); all imported symbols remain used, and the suite continues to pin the exact whereSnippet.
  • Changeset present and correctly scoped to @hyperdx/api (patch).

No P0/P1/P2/P3 findings.


Reviewers (5): correctness, testing, maintainability, project-standards, previous-comments.

Testing gaps: none — the existing patternDrilldown.test.ts still pins the returned whereSnippet against the shared implementation, and no new behavior was introduced.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

🔵 Tier 2 — Low Risk

Small, isolated change with no API route or data model modifications.

Why this tier:

  • Standard feature/fix — introduces new logic or modifies core functionality

Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns.
SLA: Resolve within 4 business hours.

Stats
  • Production files changed: 2
  • Production lines changed: 51 (+ 8 in test files, excluded from tier calculation)
  • Branch: alex/FR-385-mcp-shared-pattern-predicate
  • Author: alex-fedotyev

To override this classification, remove the review/tier-2 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 106 in total (1.14%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 469 passed • 1 skipped • 1059s

Status Count
✅ Passed 469
❌ Failed 0
⚠️ Flaky 3
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@alex-fedotyev
alex-fedotyev force-pushed the alex/FR-385-mcp-shared-pattern-predicate branch from 352748d to 4e0b97f Compare November 16, 2026 18:27
@alex-fedotyev
alex-fedotyev changed the base branch from main to alex/FR-385-shared-pattern-predicate November 16, 2026 18:27
@github-actions github-actions Bot added review/tier-2 Low risk — AI review + quick human skim and removed review/tier-3 Standard — full human review required labels Nov 16, 2026
@alex-fedotyev
alex-fedotyev force-pushed the alex/FR-385-mcp-shared-pattern-predicate branch from 4e0b97f to 7d60a1b Compare November 16, 2026 18:29
clickstack_event_patterns now imports templateToRegex,
buildPatternPredicate and MAX_PREDICATE_TEMPLATE_LENGTH from
@hyperdx/common-utils/dist/drain, and its own copy is deleted. MCP mines
without extra delimiters, so the whereSnippet it returns is unchanged. The
existing patternDrilldown tests import from common-utils and pass as they
are.

Part of FR-385.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SpencerTorres
SpencerTorres force-pushed the alex/FR-385-mcp-shared-pattern-predicate branch from 7d60a1b to 52672a1 Compare November 18, 2026 01:42
@@ -1,11 +1,11 @@
import { minePatterns } from '@hyperdx/common-utils/dist/drain';

import {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 minor — Tests for the shared common-utils predicate are left in the api MCP test file

Move the templateToRegex and buildPatternPredicate describe blocks (lines 26-168) into packages/common-utils/src/__tests__/pattern-predicate.test.ts, leaving only andSql here. As it stands, the api package tests functions it no longer owns. The length-limit case is already in the common-utils file (lines 126-130) and the toJsRegex helper is duplicated there too. The common-utils file mostly covers the withPunctuation/python options, so the default JS-whitespace coverage (Unicode spaces, BOM, escaping, Drain round-trip) lives only in the api package. A change in common-utils could break that default and the common-utils suite would still pass.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

@SpencerTorres
SpencerTorres merged commit 8dc1aa7 into main Nov 18, 2026
29 checks passed

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 52672a1f Deployed Nov 18, 2026 by vercel[bot]
Preview – hyperdx-storybook — 52672a1f Deployed Nov 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-2 Low risk — AI review + quick human skim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants