Skip to content

fix(mcp): default whereLanguage to lucene when creating a saved search - #3404

Merged
kodiakhq[bot] merged 15 commits into
mainfrom
agent/mcp-saved-search-where-language
Oct 19, 2026
Merged

kodiakhq[bot] merged 15 commits into
mainfrom
agent/mcp-saved-search-where-language

Conversation

@brandon-pereira

Copy link
Copy Markdown
Member

Summary

clickstack_save_saved_search stores a new saved search without whereLanguage when the caller omits it. The app reads a missing value as Lucene, but alerts read it as SQL (buildSearchChartConfig falls back to 'sql'). So a Lucene filter such as level:error looks fine in the search page while the search's alerts evaluate it as SQL and break. Found by @pulpdrew in review of #3396.

  • On create, an omitted whereLanguage is now stored as lucene, which matches the app and the tool's description.
  • On update, an omitted whereLanguage still keeps the stored value. A schema-level .default('lucene') would have overwritten a stored sql value on every update that left the field out, so the default lives on the create path only.

Stacked on #3396, which kept its changes to descriptions only.

How to reproduce

Starting point: local yarn dev, with an MCP client connected (see MCP.md).

On main:

  1. Call clickstack_save_saved_search with a name, a sourceId, and where: "level:error", and no whereLanguage.
  2. Call clickstack_get_saved_search with the returned id. whereLanguage is missing.

On this branch:

  1. Repeat the steps above. whereLanguage is lucene.
  2. Update the same search with whereLanguage: "sql", then update it again without whereLanguage. It stays sql.

packages/api/src/mcp/__tests__/savedSearches.int.test.ts covers both cases.

References

@changeset-bot

changeset-bot Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4ffb744

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

@vercel

vercel Bot commented Oct 19, 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 Oct 19, 2026 7:15pm UTC
hyperdx-storybook Ready Ready Preview Oct 19, 2026 7:15pm UTC

Request Review

@github-actions

github-actions Bot commented Oct 19, 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 · 🟠 1 major · 🔵 0 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.

@greptile-apps

greptile-apps Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

clickstack_save_saved_search now stores lucene when a new search omits whereLanguage.

  • New MCP saved searches record Lucene when callers leave out the language.

No actionable issues found. Tests were not run.

Reviews (3) · Last reviewed commit: "Merge branch 'main' into agent/mcp-saved..." · Reviewed by Greptile

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found.

This is a correct, narrowly-scoped fix. On create, an omitted whereLanguage is now stored as 'lucene', matching how the app reads a missing value and avoiding the alert path (packages/common-utils/src/filters.ts whereLanguage ?? 'sql') silently reparsing a Lucene filter as SQL. On update, an omitted value resolves to undefined, which Mongoose findOneAndUpdate drops so the stored value is preserved — and the new integration test confirms this. The create/update asymmetry is documented in the schema and tool descriptions.

🟡 P2 — recommended

  • packages/api/src/mcp/tools/savedSearches/saveSavedSearch.ts:65 — the update path cannot repair a saved search already persisted without whereLanguage (legacy rows, or rows created before this fix), so a Lucene where on such a search keeps misparsing as SQL in its alerts even after an MCP update that omits the field.
    • Fix: file a follow-up to backfill existing whereLanguage-less saved searches, or have the update path normalize a missing stored value to lucene.
🔵 P3 nitpicks (2)
  • packages/api/src/mcp/tools/savedSearches/saveSavedSearch.ts:65 — the create default is a bare 'lucene' literal that restates the app's implicit default and can drift from it if the app's default ever changes.
    • Fix: source the default from a shared SearchConditionLanguage constant so the MCP tool and app stay in lockstep.
  • packages/api/src/mcp/__tests__/savedSearches.int.test.ts:381 — tests cover create-defaults-lucene and update-omit-keeps-stored, but not an update that explicitly changes the language (e.g. sql → lucene).
    • Fix: add a case asserting an update with an explicit whereLanguage overwrites the stored value.

Reviewers (6): correctness, testing, maintainability, kieran-typescript, api-contract, previous-comments.

Testing gaps:

  • No test documents that updating a legacy saved search lacking whereLanguage leaves it unset (the known limitation behind the P2 above).
  • No direct test for an update that changes whereLanguage from sql to lucene.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

pulpdrew
pulpdrew previously approved these changes Oct 19, 2026
@brandon-pereira
brandon-pereira changed the base branch from agent/mcp-tool-descriptions to main October 19, 2026 16:51
@brandon-pereira
brandon-pereira dismissed pulpdrew’s stale review October 19, 2026 16:51

The base branch was changed.

@github-actions github-actions Bot added the review/tier-2 Low risk — AI review + quick human skim label Oct 19, 2026
@github-actions

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: 1
  • Production lines changed: 4 (+ 19 in test files, excluded from tier calculation)
  • Branch: agent/mcp-saved-search-where-language
  • Author: brandon-pereira

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

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 124 in total (1.67%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 437 passed • 1 skipped • 1319s

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

Tests ran across 4 shards in parallel.

View full report →

whereLanguage: input.whereLanguage,
// Alerts read a missing whereLanguage as sql while the app reads it as
// lucene, so a new search must store it explicitly.
whereLanguage: input.whereLanguage ?? (isUpdate ? undefined : 'lucene'),

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.

🟠 major — Saved searches already stored without whereLanguage keep running their alerts as SQL

This change only fixes searches created from now on. Searches that clickstack_save_saved_search already created with no whereLanguage still have the field missing. checkAlerts (packages/api/src/tasks/checkAlerts/index.ts:176, 802) passes that missing value on, and buildSearchChartConfig (packages/common-utils/src/core/searchChartConfig.ts:165) turns it into 'sql'. So an existing search with where: "level:error" still breaks its alerts. An MCP update that leaves out whereLanguage keeps the field missing too, which the new update test now locks in. Fix: add a backfill migration under packages/api/migrations/mongo that sets whereLanguage: 'lucene' on saved searches where it does not exist. Another option is to default a missing value to lucene where alerts read saved searches, which matches how the app already reads it.

Nothing blocks merge automatically, but a maintainer will expect this fixed if it is a real defect in code this PR changes. If it is about surrounding code, reply and say so instead of patching. Do not widen the PR. How to respond

@kodiakhq
kodiakhq Bot merged commit 24d324c into main Oct 19, 2026
29 checks passed
@kodiakhq
kodiakhq Bot deleted the agent/mcp-saved-search-where-language branch October 19, 2026 19:22

This branch was successfully deployed

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

Labels

automerge 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