Repository navigation
fix(mcp): default whereLanguage to lucene when creating a saved search - #3404
Conversation
…ls and test input descriptions
…s; share schema walker in tests
🦋 Changeset detectedLatest commit: 4ffb744 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Review
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. |
[Medium impact] The PR appears safe to merge. Summary
No actionable issues found. Tests were not run. Reviews (3) · Last reviewed commit: "Merge branch 'main' into agent/mcp-saved..." · Reviewed by Greptile |
Deep Review✅ No critical issues found. This is a correct, narrowly-scoped fix. On create, an omitted 🟡 P2 — recommended
🔵 P3 nitpicks (2)
Reviewers (6): correctness, testing, maintainability, kieran-typescript, api-contract, previous-comments. Testing gaps:
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 |
The base branch was changed.
🔵 Tier 2 — Low RiskSmall, isolated change with no API route or data model modifications. Why this tier:
Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns. Stats
|
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
E2E Test Results✅ All tests passed • 437 passed • 1 skipped • 1319s
Tests ran across 4 shards in parallel. |
| 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'), |
There was a problem hiding this comment.
🟠 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
Summary
clickstack_save_saved_searchstores a new saved search withoutwhereLanguagewhen the caller omits it. The app reads a missing value as Lucene, but alerts read it as SQL (buildSearchChartConfigfalls back to'sql'). So a Lucene filter such aslevel:errorlooks fine in the search page while the search's alerts evaluate it as SQL and break. Found by @pulpdrew in review of #3396.whereLanguageis now stored aslucene, which matches the app and the tool's description.whereLanguagestill keeps the stored value. A schema-level.default('lucene')would have overwritten a storedsqlvalue 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 (seeMCP.md).On
main:clickstack_save_saved_searchwith aname, asourceId, andwhere: "level:error", and nowhereLanguage.clickstack_get_saved_searchwith the returned id.whereLanguageis missing.On this branch:
whereLanguageislucene.whereLanguage: "sql", then update it again withoutwhereLanguage. It stayssql.packages/api/src/mcp/__tests__/savedSearches.int.test.tscovers both cases.References