Skip to content

ref(seer): Propagate viewer_context to explorer Seer call sites#109716

Merged
azulus merged 1 commit intomasterfrom
viewer-context/explorer
Mar 4, 2026
Merged

ref(seer): Propagate viewer_context to explorer Seer call sites#109716
azulus merged 1 commit intomasterfrom
viewer-context/explorer

Conversation

@azulus
Copy link
Member

@azulus azulus commented Mar 2, 2026

Pass SeerViewerContext to all Seer API wrapper call sites in the explorer module.

PR #109697 added an optional viewer_context parameter to all Seer API wrapper functions. This PR updates the explorer module call sites:

  • SeerExplorerClient: Builds context from self.organization and self.user in __init__, passes to start_run, continue_run, get_runs, push_changes
  • Service map utils (_send_to_seer): Pass organization_id only (no user available)

No behavior change — viewer_context defaults to None which preserves existing behavior.

Co-Authored-By: Claude noreply@anthropic.com

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 2, 2026
@azulus azulus marked this pull request as ready for review March 3, 2026 19:06
@azulus azulus requested a review from a team as a code owner March 3, 2026 19:06
Copy link
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.

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

  • ✅ Fixed: Missing viewer_context for state request call sites
    • I updated explorer state-fetching helpers and their call sites to propagate viewer_context into make_explorer_state_request, and adjusted tests to assert the new argument flow.

Create PR

Or push these changes by commenting:

@cursor push 35a696c929
Preview (35a696c929)
diff --git a/src/sentry/seer/explorer/client.py b/src/sentry/seer/explorer/client.py
--- a/src/sentry/seer/explorer/client.py
+++ b/src/sentry/seer/explorer/client.py
@@ -401,9 +401,15 @@
             TimeoutError: If polling exceeds poll_timeout when blocking=True
         """
         if blocking:
-            state = poll_until_done(run_id, self.organization, poll_interval, poll_timeout)
+            state = poll_until_done(
+                run_id,
+                self.organization,
+                poll_interval,
+                poll_timeout,
+                viewer_context=self.viewer_context,
+            )
         else:
-            state = fetch_run_status(run_id, self.organization)
+            state = fetch_run_status(run_id, self.organization, viewer_context=self.viewer_context)
 
         return state
 
@@ -548,7 +554,7 @@
         start_time = time.time()
 
         while True:
-            state = fetch_run_status(run_id, self.organization)
+            state = fetch_run_status(run_id, self.organization, viewer_context=self.viewer_context)
 
             # Check if any PRs are still being created
             any_creating = any(

diff --git a/src/sentry/seer/explorer/client_utils.py b/src/sentry/seer/explorer/client_utils.py
--- a/src/sentry/seer/explorer/client_utils.py
+++ b/src/sentry/seer/explorer/client_utils.py
@@ -224,10 +224,14 @@
     }
 
 
-def fetch_run_status(run_id: int, organization: Organization) -> SeerRunState:
+def fetch_run_status(
+    run_id: int,
+    organization: Organization,
+    viewer_context: SeerViewerContext | None = None,
+) -> SeerRunState:
     """Fetch current run status from Seer."""
     body = ExplorerStateRequest(run_id=run_id, organization_id=organization.id)
-    response = make_explorer_state_request(body)
+    response = make_explorer_state_request(body, viewer_context=viewer_context)
 
     if response.status >= 400:
         raise SeerApiError("Seer request failed", response.status)
@@ -245,12 +249,13 @@
     organization: Organization,
     poll_interval: float,
     poll_timeout: float,
+    viewer_context: SeerViewerContext | None = None,
 ) -> SeerRunState:
     """Poll the run status until completion, error, awaiting_user_input, or timeout."""
     start_time = time.time()
 
     while True:
-        result = fetch_run_status(run_id, organization)
+        result = fetch_run_status(run_id, organization, viewer_context=viewer_context)
 
         # Check if run is complete
         if result.status in ("completed", "error", "awaiting_user_input"):

diff --git a/tests/sentry/seer/explorer/test_explorer_client.py b/tests/sentry/seer/explorer/test_explorer_client.py
--- a/tests/sentry/seer/explorer/test_explorer_client.py
+++ b/tests/sentry/seer/explorer/test_explorer_client.py
@@ -265,7 +265,9 @@
 
         assert result.run_id == 123
         assert result.status == "processing"
-        mock_fetch.assert_called_once_with(123, self.organization)
+        mock_fetch.assert_called_once_with(
+            123, self.organization, viewer_context=client.viewer_context
+        )
 
     @patch("sentry.seer.explorer.client.has_seer_access_with_detail")
     @patch("sentry.seer.explorer.client.poll_until_done")
@@ -285,7 +287,9 @@
 
         assert result.run_id == 123
         assert result.status == "completed"
-        mock_poll.assert_called_once_with(123, self.organization, 1.0, 30.0)
+        mock_poll.assert_called_once_with(
+            123, self.organization, 1.0, 30.0, viewer_context=client.viewer_context
+        )
 
     @patch("sentry.seer.explorer.client.has_seer_access_with_detail")
     @patch("sentry.seer.explorer.client.fetch_run_status")
This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Pass SeerViewerContext to Seer API wrapper call sites in the explorer
module. SeerExplorerClient builds context from self.organization and
self.user. Service map utils use org_id only.
@azulus azulus force-pushed the viewer-context/explorer branch from 7c09d29 to 7375eb1 Compare March 4, 2026 01:15
@azulus azulus merged commit f09c978 into master Mar 4, 2026
76 checks passed
@azulus azulus deleted the viewer-context/explorer branch March 4, 2026 01:57
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.

2 participants