Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/sentry/seer/explorer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,15 @@ def get_run(
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

Expand Down Expand Up @@ -599,7 +605,7 @@ def push_changes(
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(
Expand Down
11 changes: 8 additions & 3 deletions src/sentry/seer/explorer/client_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,14 @@ def get_proxy_headers() -> dict[str, str] | None:
return None


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)
Expand All @@ -362,12 +366,13 @@ def poll_until_done(
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"):
Expand Down
8 changes: 6 additions & 2 deletions tests/sentry/seer/explorer/test_explorer_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ def test_get_run_immediate(self, mock_fetch, mock_access):

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")
Expand All @@ -341,7 +343,9 @@ def test_get_run_with_blocking(self, mock_poll, mock_access):

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")
Expand Down
Loading