Skip to content

feat(assisted-query): Add metrics search feature flag and forward options#112240

Merged
isaacwang-sentry merged 5 commits intomasterfrom
isaac/feat/metrics-ai-search-backend
Apr 10, 2026
Merged

feat(assisted-query): Add metrics search feature flag and forward options#112240
isaacwang-sentry merged 5 commits intomasterfrom
isaac/feat/metrics-ai-search-backend

Conversation

@isaacwang-sentry
Copy link
Copy Markdown
Member

Summary

  • Register gen-ai-explore-metrics-search feature flag to gate the metrics AI search bar independently
  • Update SearchAgentStartEndpoint to accept the new flag when strategy is "Metrics"
  • Forward the full options dict to Seer instead of extracting only model_name, so strategy-specific context (like metric_context) passes through

Test plan

  • Verify the gen-ai-explore-metrics-search flag is registered and exposed to the frontend
  • Verify the endpoint accepts requests with strategy: "Metrics" when the new flag is enabled
  • Verify the full options dict is forwarded to Seer

…ions

Register gen-ai-explore-metrics-search feature flag to gate the metrics
AI search bar independently from the shared gen-ai-search-agent-translate
flag. Forward the full options dict to Seer instead of extracting only
model_name, so strategy-specific context like metric_context can pass
through.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@isaacwang-sentry isaacwang-sentry requested a review from a team as a code owner April 3, 2026 22:23
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 3, 2026
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: State endpoint missing new metrics feature flag check
    • Added gen-ai-explore-metrics-search flag check to state endpoint to match the start endpoint's feature flag logic, allowing users with only the metrics flag to poll for search agent state.

Create PR

Or push these changes by commenting:

@cursor push 1df9d6d530
Preview (1df9d6d530)
diff --git a/src/sentry/seer/endpoints/search_agent_state.py b/src/sentry/seer/endpoints/search_agent_state.py
--- a/src/sentry/seer/endpoints/search_agent_state.py
+++ b/src/sentry/seer/endpoints/search_agent_state.py
@@ -81,9 +81,12 @@
                 }
             }
         """
-        if not features.has(
+        has_feature = features.has(
             "organizations:gen-ai-search-agent-translate", organization, actor=request.user
-        ):
+        ) or features.has(
+            "organizations:gen-ai-explore-metrics-search", organization, actor=request.user
+        )
+        if not has_feature:
             return Response(
                 {"detail": "Feature flag not enabled"},
                 status=status.HTTP_403_FORBIDDEN,

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

…oint

The start endpoint allows access with either gen-ai-search-agent-translate
or gen-ai-explore-metrics-search flag when strategy is Metrics, but the
state endpoint only checked gen-ai-search-agent-translate. This caused
users with only the metrics flag to successfully start a search agent
but get 403 errors when polling for state.

Since the state endpoint doesn't know which strategy was used, it now
accepts either flag to match the start endpoint's behavior.

Co-authored-by: Armen Zambrano G. <armenzg@users.noreply.github.com>

Applied via @cursor push command
Copy link
Copy Markdown
Member

@aliu39 aliu39 left a comment

Choose a reason for hiding this comment

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

what's the reason for the options param change, is it necessary? We're not using any options besides model_name right?
There's nothing wrong w it per se, but validator could let through a random dict of unused options

@isaacwang-sentry
Copy link
Copy Markdown
Member Author

what's the reason for the options param change, is it necessary? We're not using any options besides model_name right? There's nothing wrong w it per se, but validator could let through a random dict of unused options

We did this so metric_context could pass through to Seer without the sentry endpoint needing to know about every field, if we want we can explicitly extract model_name + metric_context and only forward those.

…itch

Change the state endpoint feature flag check from OR to AND so that
gen-ai-search-agent-translate must always be enabled for access.
This lets the translate flag serve as a global killswitch for all
search agent functionality.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Start endpoint: change OR to AND so gen-ai-search-agent-translate
acts as a global killswitch — metrics search requires both flags.

State endpoint: change AND to OR since it is strategy-agnostic and
only takes a run_id. Traces users with only the translate flag must
still be able to poll for results.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 77da5a6. Configure here.

):
) or features.has(
"organizations:gen-ai-explore-metrics-search", organization, actor=request.user
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

State endpoint OR logic defeats global killswitch intent

Medium Severity

The state endpoint uses or to combine the two feature flags, while the start endpoint uses and (per reviewer request) so gen-ai-search-agent-translate acts as a global killswitch. The or in the state endpoint undermines that intent — disabling gen-ai-search-agent-translate won't block state polling for orgs that only have gen-ai-explore-metrics-search enabled.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 77da5a6. Configure here.

@aliu39
Copy link
Copy Markdown
Member

aliu39 commented Apr 10, 2026

Is there validation on Seer side? If so that's fine, otherwise I'd prefer extracting the fields here

Instead of forwarding the raw options dict to Seer, extract only
model_name and metric_context. This prevents unknown fields from
passing through the unvalidated DictField serializer.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@isaacwang-sentry isaacwang-sentry merged commit b7e8d18 into master Apr 10, 2026
77 checks passed
@isaacwang-sentry isaacwang-sentry deleted the isaac/feat/metrics-ai-search-backend branch April 10, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants