Skip to content

fix(search): Run every search query as written and link the syntax docs - #2846

Merged
dcramer merged 21 commits into
mainfrom
fix/search-preserve-explicit-filters
Dec 4, 2026
Merged

dcramer merged 21 commits into
mainfrom
fix/search-preserve-explicit-filters

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

The MCP search tools (search_issues, search_issue_events, and the search_events family such as search_errors, search_logs, and search_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 missing store:853, terminal_id:X renamed to device:X, (a OR b) turned into a b, and stripped timestamp:>= 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, and period are passed through. Absolute timestamp: bounds set the time range, so the 14d default doesn't cut them off, and a request with only aggregate or equation| 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, and search_logs says its level key is severity, not level (severity:[error,fatal]), because models otherwise write level: there. The query params keep short descriptions. A docs link is the lightest pointer: any client can follow it, get_doc accepts the URL, and it adds no tool. Naming get_doc instead would not work everywhere, because the triage and seer skills don't include it. Compared with teaching the syntax inline in each description and query param, the link saves 37 to 80 tokens per search tool, about 455 in total. search-syntax.ts keeps the syntax text for the suggestion agent's prompt only. The search-query-syntax eval 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 a Nothing matched the request as written note. 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 only fields or sort still 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_errors takes timeSeries (axes of aggregates plus an optional interval) and returns the series from the events-timeseries endpoint, 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, and search_metrics keep their existing timeSeries; transformations are now optional there, so they also return plain series.
  • search_traces takes crossEventQueries (spanQuery, logQuery, metricQuery) to keep spans whose trace also has a matching span, log, or metric, using the api-client's CrossEventQueries type. Sentry reads them on both the events and events-timeseries endpoints, so they apply to rows and time series.
  • search_events requires dataset; it no longer defaults to errors.

Breaking schema changes.

  • includeExplanation is removed from every search tool's input, and explanation from their structured output.
  • The structured transformedTimeSeries output field is renamed to timeSeries, replacing the old timeSeries field that only Seer's translation filled. It holds every series, and an axis without transformations lists none.
  • search_events calls without dataset now fail validation.

Removed.

  • The Seer search-agent translation (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.
  • The assisted_query.outcome logs 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.
  • The agent prompt sections for dataset selection and time series, and the explanation field in the search agents' output schemas and prompts, which only translation used.
  • The repair re-run, the explicit-filter checks on the agent's output, and 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]

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>
@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
cli Ready Ready Preview Dec 4, 2026 6:12pm UTC
sentry-local Ready Ready Preview Dec 4, 2026 6:12pm UTC

Request Review

@dcramer dcramer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@dcramer

dcramer commented Dec 3, 2026

Copy link
Copy Markdown
Member

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.
@sentry-junior

sentry-junior Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

I think that's the right direction, and I'd keep it out of this PR. Here's the path I'd take:

  • Run structured queries without the repair agent. If the input is already Sentry syntax (looksLikeSentrySearchSyntax), send it straight to validateSearch, then run it. The trace datasets already do this when the caller passes explicit fields and sort (canRunWithoutAgent). The agent would be left for natural language, which is the only case where it adds value. That also removes an LLM round trip from the most common calls.
  • On a validation failure, return hints to the calling agent instead of repairing. For example: "foo isn't an attribute on logs; closest matches: foo.bar, app.foo; use search_attributes to list more." We already do this for a few field errors in field-hints.ts. Extending it to unknown keys is mostly wiring in search_attributes lookups. The calling agent has the user's intent and can fix the query itself.
  • Treat the embedded agent as a natural-language translator, not a query fixer. Its evals should then only measure translation quality.

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?

@sentry-junior
sentry-junior Bot requested a review from dcramer December 3, 2026 17:39
@dcramer

dcramer commented Dec 3, 2026

Copy link
Copy Markdown
Member

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>
@sentry-junior sentry-junior Bot changed the title fix(search): Keep explicit filters through query repair fix(search): Run structured queries as written, repair only on rejection Dec 3, 2026
@vercel
vercel Bot temporarily deployed to Preview – sentry-local December 3, 2026 18:07 Inactive
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.
@sentry-junior
sentry-junior Bot force-pushed the fix/search-preserve-explicit-filters branch from fb5ebb9 to 2b7d99e Compare December 3, 2026 18:07
@vercel
vercel Bot temporarily deployed to Preview – sentry-local December 3, 2026 18:07 Inactive
@sentry-junior

sentry-junior Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Heads up: this PR and #2845 both fix the same bug in #2844 (an explicit OR in search_issues silently becoming AND). #2845 rejects a free-text OR before the agent sees it; this PR drops query rewriting and runs every query as written. A 4th report came in today (MCP-SERVER-H0B, details on #2844), and both PRs would fix it.

Maintainers, could you pick one? If this is the direction, #2845 can be closed.

via automation evt_905b9c478746fd9deeb853f85ad7441b · Run ID dispatch_3a4e0a9a29fd05ec4222066d2616ab49.

@DominikB2014
DominikB2014 requested a review from a team December 4, 2026 15:47
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>
@sentry-junior sentry-junior Bot changed the title fix(search): Run every search query as written and teach the syntax up front fix(search): Run every search query as written and link the syntax docs Dec 4, 2026
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>
Comment thread design/mcp-tools.md Resolved
They over-steer and the doc needs to stay tight. The contributor docs
still describe how search runs queries.
Comment on lines +306 to +334
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,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.ts calls suggestSearchEventsFix through suggestForEmptyResult.
  • searchEventsAgent uses hasSuccessfulSearchValidation as its finalization condition. The validateSearch tool accepts only PUBLIC_EVENTS_DATASETS, excluding replays, and the prompt calls for validation only on non-replay datasets.
  • callEmbeddedAgent allows a final response after five work steps only when that condition passes; otherwise it stops without output. suggestWithAgent converts the resulting UserInputError to null, so the replay search loses the optional suggestion.

Identified by Warden · code-review · X8T-NHC

This branch was successfully deployed

3 active deployments
Preview – sentry-local — cc733d46 Deployed Dec 4, 2026 by vercel[bot]
Preview – cli — cc733d46 Deployed Dec 4, 2026 by vercel[bot]
Actions — cc733d46 Deployed Dec 4, 2026 by sentry-junior[bot] via eval #2271
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants