From 5d50df77fd684a61b6abbd27adb02adb8be114cf Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 10 Nov 2026 21:38:26 +0000 Subject: [PATCH] fix(search-events): Note when a time series is cut to the newest buckets Structured time-series results keep only the most recent 48 buckets. Callers saw bucketCount differ from the returned buckets but got no note saying older buckets were left out. Co-Authored-By: Claude Co-Authored-By: BYK <126780+BYK@users.noreply.github.com> --- .../catalog/search-errors.structured.test.ts | 53 +++++++++++++++++++ .../tools/support/search-events/structured.ts | 11 +++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/packages/mcp-core/src/tools/catalog/search-errors.structured.test.ts b/packages/mcp-core/src/tools/catalog/search-errors.structured.test.ts index f56ed538d..e22b7f544 100644 --- a/packages/mcp-core/src/tools/catalog/search-errors.structured.test.ts +++ b/packages/mcp-core/src/tools/catalog/search-errors.structured.test.ts @@ -440,4 +440,57 @@ describe("search_errors structured output", () => { } `); }); + + it("notes when a long time series is cut to the most recent buckets", async () => { + vi.mocked(translateWithSeer).mockResolvedValue({ + query: "level:error", + fields: [], + sort: "-count()", + timeParams: { statsPeriod: "9d" }, + timeSeries: { yAxis: "count()", interval: "5m" }, + crossEventQueries: undefined, + suggestedProjectIds: [], + explanation: "", + runId: "run-1", + mode: "time_series", + organizationFeatures: [], + } as unknown as Awaited>); + const start = 1757545200000; + const fiveMinutes = 300_000; + mswServer.use( + http.get( + "https://sentry.io/api/0/organizations/test-org/events-timeseries/", + () => + HttpResponse.json({ + timeSeries: [ + { + yAxis: "count()", + values: Array.from({ length: 60 }, (_, i) => ({ + timestamp: start + i * fiveMinutes, + value: i, + incomplete: false, + })), + meta: { + interval: fiveMinutes, + valueType: "integer", + valueUnit: null, + }, + }, + ], + }), + ), + ); + + const structuredContent = await runSearch({ + query: "errors per 5 minutes", + period: "9d", + }); + + expect(structuredContent.timeSeries?.bucketCount).toBe(60); + expect(structuredContent.timeSeries?.buckets).toHaveLength(48); + expect(structuredContent.timeSeries?.buckets[0]?.value).toBe(12); + expect(structuredContent.notes).toEqual([ + "**Note:** Only the most recent 48 of 60 buckets are returned; older buckets in the time range are left out. Use a coarser interval to cover more of the range.", + ]); + }); }); diff --git a/packages/mcp-core/src/tools/support/search-events/structured.ts b/packages/mcp-core/src/tools/support/search-events/structured.ts index 5b3b1bcff..92e219267 100644 --- a/packages/mcp-core/src/tools/support/search-events/structured.ts +++ b/packages/mcp-core/src/tools/support/search-events/structured.ts @@ -479,6 +479,15 @@ export function buildStructuredTimeSeriesResult(params: { directToolNames: session.directToolNames, }); + // Only the newest buckets are returned, so say when older ones were cut. + const notes = + bucketCount > shown.length + ? [ + ...params.notes, + `**Note:** Only the most recent ${shown.length} of ${bucketCount} buckets are returned; older buckets in the time range are left out. Use a coarser interval to cover more of the range.`, + ] + : params.notes; + return structuredResult({ query: params.inputQuery, explanation: @@ -493,7 +502,7 @@ export function buildStructuredTimeSeriesResult(params: { }), url: params.url, presentationHint: DASHBOARD_LINK_HINT, - notes: params.notes, + notes, resultType: "timeSeries", results: [], timeSeries: {