Repository navigation
fix(search-events): Keep the agent's absolute window when a period is also passed - #2146
Conversation
… also passed For structured queries with an explicit `period`, the handler dropped the embedded agent's absolute `start`/`end` and searched the whole period. Callers that name a fixed window in the query and send `period` as an outer guard got rolling-period results without being told. Use the overlap of the agent's absolute range and the period instead. It can only narrow the period; with no overlap, the period is kept.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
Another production case for this path, from Sentry MCP feedback MCP-SERVER-GNC (claude.ai, Span What this PR doesn't cover: the feedback's earlier calls were natural language with no structured filters, for example |
`search_issue_events` fails on open-ended "since X" windows such as
`timestamp:>=2026-11-12T06:39:00Z` or "since November 12 2026 at 06:39
UTC". It returns "The AI was unable to process your query";
`search_errors` handles the same window fine.
**Why it fails**
The embedded agent's output schema
(`tools/support/search-issue-events/agent.ts`) is stricter than its
prompt:
1. An absolute `timeRange` requires both `start` and `end`. A "since X"
request has no natural end, and the agent doesn't know the current time.
2. `timeRange` is required, but the prompt says to omit it for the
default window.
If the model returns `{start}` only, or omits `timeRange`, the AI SDK
raises `NoObjectGeneratedError` ("response did not match schema").
`rescueFromText` can't repair that, so the tool returns the "unable to
process" error (`internal/agents/callEmbeddedAgent.ts:226`). Production
logs show this exact error with `finishReason: stop` for these queries.
Which of the two shapes the model produced is inferred, since the traces
weren't sampled.
**Change**
- In an absolute `timeRange`, `end` is optional. When it's missing, the
handler runs the search until now.
- `timeRange` defaults to `null`, meaning the default 14d window.
- The prompt has open-ended examples and says "null" instead of "omit".
Existing outputs, whether full `{start, end}` or `{statsPeriod}`, behave
as before.
Related but separate: #1215 / #1228 (caller-supplied `start`/`end` for
`search_events` and `search_issues`) and #2139 / #2146 (dropped absolute
bounds in `runSearchEvents`). Longer term, #1896 removes the embedded
search agents.
<!-- junior-request-attribution:start -->
via @joshuarli.
<!-- junior-request-attribution:end -->
<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0CG2CP9ELW%3A1794596896.742009 -->
--
[View
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CG2CP9ELW%3A1794596896.742009)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CG2CP9ELW%3A1794596896.742009/?project=4510944073809921)
<!-- junior-session-footer:end -->
Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
|
Another report of this exact case, from Sentry MCP user feedback MCP-SERVER-GQD (python caller, server 0.42.0, Call: What ran (sampled spans for the call):
With this PR, the overlap of The caller's rerun with Reports for this case (period + prose window + structured filters): 2 (MCP-SERVER-GN4, MCP-SERVER-GQD). The wider "search drops query parts" pattern is at 12 reports. |
…in (#2277) Removes the `!` from `return requests[0]!;` in the search-events tests. #2146 added it on a branch that predates #2125, which made unnecessary type assertions an error, so main has rejected it since 88c26a3e. The return type is still `URLSearchParams`. Nothing else changes. <!-- junior-request-attribution:start --> via @MathurAditya724. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:local%3Aweb%3A4c096bdc12f2a2226186d683 --> -- [View Session](https://junior-prod.sentry.dev/conversations/local%3Aweb%3A4c096bdc12f2a2226186d683) [[Sentry]](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A4c096bdc12f2a2226186d683/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Aditya Mathur <57684218+MathurAditya724@users.noreply.github.com>
search_errors(and the otherrunSearchEventstools) can silently search the wholeperiodwhen the query names a fixed window. This happens when the caller names a window in the query text, uses some structured filters, and also sendsperiodas an outer guard.What happens
hasStructuredQueryis true. Dataset tools setlockDataset, so the handler trusts the caller's explicit params.statsPeriodin its prompt. It still returns an absolutetimeRange({start, end}) for the window that the query names.periodis explicit, the handler discards that range and sends onlystatsPeriod(search.ts:936-938on main).executedSearch.timeRangeshowsstatsPeriodwith nullstart/end. The explanation still describes the agent's plan.A production trace from user feedback (MCP-SERVER-GN4) shows exactly this. The query was
Between <start> and <end>, environment:production <tag>:<value>, …withperiod: "3d". The agent's firstevents/validatecall usedstart/end. The final/events/request and the Snuba query used the 3-day rolling window. The same session without structured filters took the untrusted path, and the absolute range was applied correctly.Change
When the caller passes
periodand the agent returns an absolute range, the search uses the overlap of the two. The overlap can only narrowperiod, so the result never goes outside what the caller allowed. When the two don't overlap, or the agent returned a relative period, the caller'speriodis kept as before.Relation to other work
timestamp:tokens in the query. It puts them back on the query after the agent drops them. This PR covers bounds written in prose, where there are no tokens to put back. The two don't overlap in code, and both can land.start/endinputs) is still the long-term fix for callers that know the exact window.explicit period winsrule (search.ts:851-853). I left it unchanged because I have no trace evidence for it.via Sentry.
--
View Session [Sentry]