Repository navigation
fix(search): Run every search query as written and link the syntax docs - #2846
Conversation
The query repair agent in search_issues, search_issue_events, and the search_events family (search_errors, search_logs, search_traces, and the rest) could drop a key:value filter, change its value, rename its key, or turn OR into AND, and then run a broader search without saying so. After the repair, compare its query with the caller's. Put back any explicit filter it dropped or changed, replacing the repaired version, and add a note that names the restored filters and the query that ran. When the repair removed an OR or a filter inside parentheses, run the caller's query as written, so issue search rejects OR it cannot express instead of searching with AND. search_issues and search_issue_events treat a renamed key as a change. The event datasets still accept a rename that keeps the condition, which maps guessed names to real attributes. Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
dcramer
left a comment
There was a problem hiding this comment.
Part of this might also be making sure that the agent call that is doing this knows that it should not be reducing or removing filters. Doesn't mean we can't have some determinism here, but we should also look for an opportunity to improve the agent because I don't know that our evals are really good here
|
Also, maybe the agent running to fix the search query is not the right call going forward. Maybe there's a better path with hints or other things that we can give the agent |
Address review feedback: fix the agents as well as checking their output. The search_issue_events prompt told the agent to check every tag against issueEventFields, because "non-existent tags will cause query failures". That pushed it to drop or rename custom tags missing from the list, such as store or terminal_id. The prompt now says filters the user wrote are authoritative, and that the tag list may be incomplete and is only for translating natural language. Its repair prompt now matches the one search_issues uses. The search_issues prompt said to rewrite any OR, which led to OR → AND. It now allows only the same-field in-list rewrite and otherwise keeps the OR, so the tool can reject it. The search_events prompt also says to keep timestamp filters and never drop a filter, change its value, or turn OR into AND. Add agent eval cases for each regression: dropped and renamed custom tags, negation, timestamp filters, and OR.
|
I think that's the right direction, and I'd keep it out of this PR. Here's the path I'd take:
This PR's restore step keeps people safe until that lands, and becomes dead code for structured input once it does. Want me to open a follow-up issue in getsentry/toolkit with this plan, or start on it as a separate PR after this one merges? |
|
Yeah lets step back and change how this works and focus on not brekaing user behavior, and ensuring it has the right hints, and can improve failure scenarios vs breaking potential success scenarios... |
Address review feedback: stop putting the query repair agent in front of queries Sentry would accept. A query written entirely in Sentry syntax (filters, boolean operators, groups, and quoted phrases, with no unquoted words) now runs as written in search_issues, search_issue_events, and the search_events family. The agent only runs when Sentry rejects that query, through validation or a 400 from the search endpoint. It gets Sentry's reason, gets one attempt, and the result note shows the query that ran. If the repair fails too, or would trade a structured filter for full-text matching, the caller gets the original rejection and its recovery hints. Natural-language and mixed queries still go through translation, and the explicit-filter preservation from the earlier commits still applies to them. Two gaps the agent used to cover when it saw every request: - A query run as written takes its time range from absolute timestamp bounds such as timestamp:>=2026-01-01T00:00:00Z when the caller sets no period, so the 14d default doesn't cut it off. - Aggregate fields with no sort now sort by the first aggregate, rather than by timestamp, which would add timestamp as a group-by column. Co-Authored-By: David Cramer <david@sentry.io>
The query-repair code this PR adds puts the @sentry/mcp-server bundle at 3.776 MiB, just over the 3.77 MiB budget. Earlier feature PRs raised the budget the same way, by 0.01 MiB.
fb5ebb9 to
2b7d99e
Compare
|
Heads up: this PR and #2845 both fix the same bug in #2844 (an explicit Maintainers, could you pick one? If this is the direction, #2845 can be closed. via automation |
The search tool descriptions and query params carried the syntax inline, which added tokens to every tools/list. Each description now says the query uses Sentry search syntax, links https://docs.sentry.io/concepts/search/, and notes that a rejected or empty search suggests a fix. Issue search still notes it has no OR or parentheses. The query params go back to short descriptions. The link works for every client and costs fewer tokens than pointing at get_doc, which the triage and seer skills don't include. search-syntax.ts keeps the syntax text for the suggestion agent prompt. Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
The eval reporter shows only the score, so a failing case gave no clue what the model sent. Log the query when it fails the check. Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
Without inline syntax, models reach for level, which logs don't have. One line in the search_logs description says to use severity, with severity:[error,fatal] as the example. Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
They over-steer and the doc needs to stay tight. The contributor docs still describe how search runs queries.
| export async function suggestSearchEventsFix( | ||
| options: SearchEventsSuggestionRequest & { | ||
| organizationSlug: string; | ||
| apiService: SentryApiService; | ||
| projectId?: string | undefined; | ||
| environmentNames: string[]; | ||
| }, | ||
| ): Promise<string | null> { | ||
| if (!hasAgentProvider()) { | ||
| return null; | ||
| } | ||
| const suggestion = await suggestWithAgent( | ||
| "search_events.suggest", | ||
| async () => | ||
| ( | ||
| await searchEventsAgent({ | ||
| query: buildSearchEventsSuggestionPrompt(options), | ||
| organizationSlug: options.organizationSlug, | ||
| apiService: options.apiService, | ||
| projectId: options.projectId, | ||
| environmentNames: options.environmentNames, | ||
| }) | ||
| ).result, | ||
| ); | ||
| return formatSearchSuggestion({ | ||
| ran: options.ran, | ||
| suggestion, | ||
| dataset: options.dataset, | ||
| }); |
There was a problem hiding this comment.
Replay suggestions that use five tool steps cannot pass the finalization gate
If a replay suggestion uses all five work steps before returning, it is stopped because finalization requires a successful validateSearch, which does not accept the replay dataset. The best-effort fallback then omits the suggestion from the otherwise successful replay search result.
Evidence
- When a replay search returns no results,
search.tscallssuggestSearchEventsFixthroughsuggestForEmptyResult. searchEventsAgentuseshasSuccessfulSearchValidationas its finalization condition. ThevalidateSearchtool accepts onlyPUBLIC_EVENTS_DATASETS, excludingreplays, and the prompt calls for validation only on non-replay datasets.callEmbeddedAgentallows a final response after five work steps only when that condition passes; otherwise it stops without output.suggestWithAgentconverts the resultingUserInputErrortonull, so the replay search loses the optional suggestion.
Identified by Warden · code-review · X8T-NHC
The MCP search tools (
search_issues,search_issue_events, and thesearch_eventsfamily such assearch_errors,search_logs, andsearch_traces) ran an LLM agent on the caller's query and then ran the agent's version. The agent dropped or changed filters the caller wrote, such as a missingstore:853,terminal_id:Xrenamed todevice:X,(a OR b)turned intoa b, and strippedtimestamp:>=bounds, then ran a broader search than the caller asked for.This PR stops the tools from rewriting or translating a query at all.
Run as written. Every query runs exactly as the caller wrote it, including one with no Sentry syntax, which Sentry searches as literal text.
query,fields,sort,dataset,environment, andperiodare passed through. Absolutetimestamp:bounds set the time range, so the 14d default doesn't cut them off, and a request with only aggregate orequation|fields sorts by its first one instead of-timestamp.A pointer to the syntax instead of translation. No tool promises natural-language search anymore. Each search tool's description says its query uses Sentry search syntax, links https://docs.sentry.io/concepts/search/ (operators,
OR/AND, lists, wildcards, and logs regex), and says a rejected or empty search suggests a fix. Issue search also notes it has no OR or parentheses, andsearch_logssays its level key isseverity, notlevel(severity:[error,fatal]), because models otherwise writelevel:there. Thequeryparams keep short descriptions. A docs link is the lightest pointer: any client can follow it,get_docaccepts the URL, and it adds no tool. Namingget_docinstead would not work everywhere, because the triage and seer skills don't include it. Compared with teaching the syntax inline in each description andqueryparam, the link saves 37 to 80 tokens per search tool, about 455 in total.search-syntax.tskeeps the syntax text for the suggestion agent's prompt only. Thesearch-query-syntaxeval gives a model only one tool's definition and a task, with no docs fetch, and checks that the query it writes parses, uses the filters the task names, and has no loose words. A failing case prints the query the model wrote.Suggestions on failure, never a re-run. When Sentry rejects the query, or it matches nothing, the search agent is asked for a fix. The result shows it as
Suggested request, not run: query …, fields …, sort …, appended to the rejection or in aNothing matched the request as writtennote. The caller decides whether to retry with it. No suggestion is shown when the agent is unavailable, returns the same request, empties the query, or trades a structured filter for full-text matching. A fix that changes onlyfieldsorsortstill counts. Without a suggestion, a plain-words query that matches nothing gets a note to retry with Sentry search syntax.What the agent inferred is now an explicit parameter.
search_errorstakestimeSeries(axesof aggregates plus an optionalinterval) and returns the series from theevents-timeseriesendpoint, as Seer's translation did. It doesn't accept transformations, because Sentry runs fill and smooth only on the spans, logs, and metrics datasets.search_logs,search_traces, andsearch_metricskeep their existingtimeSeries; transformations are now optional there, so they also return plain series.search_tracestakescrossEventQueries(spanQuery,logQuery,metricQuery) to keep spans whose trace also has a matching span, log, or metric, using the api-client'sCrossEventQueriestype. Sentry reads them on both the events andevents-timeseriesendpoints, so they apply to rows and time series.search_eventsrequiresdataset; it no longer defaults toerrors.Breaking schema changes.
includeExplanationis removed from every search tool's input, andexplanationfrom their structured output.transformedTimeSeriesoutput field is renamed totimeSeries, replacing the oldtimeSeriesfield that only Seer's translation filled. It holds every series, and an axis without transformations lists none.search_eventscalls withoutdatasetnow fail validation.Removed.
seer.ts, the client's search-agent endpoints, and their schemas), and the agent translation before execution, along with dataset locking and field resolution that only translation used.assisted_query.outcomelogs and metrics that only Seer's translation reported. The Seer team loses MCP traffic in that metric, about 40k runs in the last 7 days.explanationfield in the search agents' output schemas and prompts, which only translation used.isFullyStructuredQuery. Every Warden round found new edge cases in that code, and each one was a way to run something other than what the caller wrote.The contributor docs describe how search runs queries and document the new parameters. The bundle stays under the current budget.
via @dcramer.
--
View Session [Sentry]