Repository navigation
Commit 88c26a3
authored
fix(search-events): Keep the agent's absolute window when a period is also passed (#2146)
`search_errors` (and the other `runSearchEvents` tools) can silently
search the whole `period` when the query names a fixed window. This
happens when the caller names a window in the query text, uses some
structured filters, and also sends `period` as an outer guard.
**What happens**
1. The query has structured filters, so `hasStructuredQuery` is true.
Dataset tools set `lockDataset`, so the handler trusts the caller's
explicit params.
2. The embedded agent sees `statsPeriod` in its prompt. It still returns
an absolute `timeRange` (`{start, end}`) for the window that the query
names.
3. Because `period` is explicit, the handler discards that range and
sends only `statsPeriod` (`search.ts:936-938` on main).
`executedSearch.timeRange` shows `statsPeriod` with null `start`/`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>, …` with `period: "3d"`. The agent's first
`events/validate` call used `start`/`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 `period` and the agent returns an absolute range,
the search uses the overlap of the two. The overlap can only narrow
`period`, 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's `period` is kept as before.
**Relation to other work**
- #2139 handles the case where the bounds are `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.
- #1215 / #1228 (typed `start`/`end` inputs) is still the long-term fix
for callers that know the exact window.
- The Seer path has the same `explicit period wins` rule
(`search.ts:851-853`). I left it unchanged because I have no trace
evidence for it.
<!-- junior-request-attribution:start -->
via **Sentry**.
<!-- junior-request-attribution:end -->
<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0CG2CP9ELW%3A1794328376.548829 -->
--
[View
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CG2CP9ELW%3A1794328376.548829)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CG2CP9ELW%3A1794328376.548829/?project=4510944073809921)
<!-- junior-session-footer:end -->
Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>1 parent d9c6954 commit 88c26a3
2 files changed
Lines changed: 148 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3504 | 3504 | | |
3505 | 3505 | | |
3506 | 3506 | | |
| 3507 | + | |
| 3508 | + | |
| 3509 | + | |
| 3510 | + | |
| 3511 | + | |
| 3512 | + | |
| 3513 | + | |
| 3514 | + | |
| 3515 | + | |
| 3516 | + | |
| 3517 | + | |
| 3518 | + | |
| 3519 | + | |
| 3520 | + | |
| 3521 | + | |
| 3522 | + | |
| 3523 | + | |
| 3524 | + | |
| 3525 | + | |
| 3526 | + | |
| 3527 | + | |
| 3528 | + | |
| 3529 | + | |
| 3530 | + | |
| 3531 | + | |
| 3532 | + | |
| 3533 | + | |
| 3534 | + | |
| 3535 | + | |
| 3536 | + | |
| 3537 | + | |
| 3538 | + | |
| 3539 | + | |
| 3540 | + | |
| 3541 | + | |
| 3542 | + | |
| 3543 | + | |
| 3544 | + | |
| 3545 | + | |
| 3546 | + | |
| 3547 | + | |
| 3548 | + | |
| 3549 | + | |
| 3550 | + | |
| 3551 | + | |
| 3552 | + | |
| 3553 | + | |
| 3554 | + | |
| 3555 | + | |
| 3556 | + | |
| 3557 | + | |
| 3558 | + | |
| 3559 | + | |
| 3560 | + | |
| 3561 | + | |
| 3562 | + | |
| 3563 | + | |
| 3564 | + | |
| 3565 | + | |
| 3566 | + | |
| 3567 | + | |
| 3568 | + | |
| 3569 | + | |
| 3570 | + | |
| 3571 | + | |
| 3572 | + | |
| 3573 | + | |
| 3574 | + | |
| 3575 | + | |
| 3576 | + | |
| 3577 | + | |
| 3578 | + | |
| 3579 | + | |
| 3580 | + | |
| 3581 | + | |
| 3582 | + | |
| 3583 | + | |
| 3584 | + | |
| 3585 | + | |
| 3586 | + | |
| 3587 | + | |
| 3588 | + | |
| 3589 | + | |
| 3590 | + | |
| 3591 | + | |
| 3592 | + | |
| 3593 | + | |
| 3594 | + | |
| 3595 | + | |
| 3596 | + | |
| 3597 | + | |
| 3598 | + | |
3507 | 3599 | | |
3508 | 3600 | | |
3509 | 3601 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
149 | 201 | | |
150 | 202 | | |
151 | 203 | | |
| |||
937 | 989 | | |
938 | 990 | | |
939 | 991 | | |
| 992 | + | |
940 | 993 | | |
941 | | - | |
942 | | - | |
943 | | - | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
944 | 997 | | |
945 | 998 | | |
946 | 999 | | |
| |||
0 commit comments