-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(seer): Wire explorer chat write site through SeerRun outbox #115231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: telkins/seer-run-outbox
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,12 +8,16 @@ | |
|
|
||
| import sentry_sdk | ||
| from django.contrib.auth.models import AnonymousUser | ||
| from django.db import router, transaction | ||
| from django.utils import timezone as django_timezone | ||
| from django.utils.timezone import now | ||
| from pydantic import BaseModel | ||
| from rest_framework.request import Request | ||
|
|
||
| from sentry import features, options | ||
| from sentry.constants import ENABLE_SEER_CODING_DEFAULT, ObjectStatus | ||
| from sentry.hybridcloud.models.outbox import CellOutbox, outbox_context | ||
| from sentry.hybridcloud.outbox.category import OutboxCategory, OutboxScope | ||
| from sentry.models.organization import Organization | ||
| from sentry.models.project import Project | ||
| from sentry.seer.agent.client_models import AgentRun, AgentRunWithPrs, SeerRunState | ||
|
|
@@ -36,6 +40,7 @@ | |
| extract_hook_definition, | ||
| ) | ||
| from sentry.seer.models import SeerApiError, SeerPermissionError, SeerRepoDefinition | ||
| from sentry.seer.models.run import SeerRun, SeerRunMirrorStatus, SeerRunType | ||
| from sentry.seer.seer_setup import has_seer_access_with_detail | ||
| from sentry.seer.signed_seer_api import SeerViewerContext | ||
| from sentry.tasks.seer.context_engine_index import build_service_map, index_org_project_knowledge | ||
|
|
@@ -254,6 +259,7 @@ def start_run( | |
| request: Request | None = None, | ||
| override_ce_enable: bool = True, | ||
| ui_tools: str | None = None, | ||
| run_type: SeerRunType | None = None, | ||
| ) -> int: | ||
| """ | ||
| Start a new Seer Agent session. | ||
|
|
@@ -345,6 +351,34 @@ def start_run( | |
| ): | ||
| chat_body["is_context_engine_enabled"] = override_ce_enable | ||
|
|
||
| if run_type and features.has("organizations:seer-run-mirror", self.organization): | ||
| user_id = ( | ||
| self.user.id | ||
| if self.user and hasattr(self.user, "id") and self.user.id is not None | ||
| else None | ||
| ) | ||
| with outbox_context(transaction.atomic(using=router.db_for_write(SeerRun)), flush=True): | ||
| run = SeerRun.objects.create( | ||
| organization=self.organization, | ||
| user_id=user_id, | ||
| type=run_type, | ||
| last_triggered_at=now(), | ||
| ) | ||
| CellOutbox( | ||
| shard_scope=OutboxScope.ORGANIZATION_SCOPE, | ||
| shard_identifier=self.organization.id, | ||
| category=OutboxCategory.SEER_RUN_CREATE, | ||
| object_identifier=run.id, | ||
| payload={ | ||
| "body": dict(chat_body), | ||
| "viewer_context": dict(self.viewer_context), | ||
| }, | ||
| ).save() | ||
| run.refresh_from_db() | ||
| if run.mirror_status != SeerRunMirrorStatus.LIVE or run.seer_run_state_id is None: | ||
| raise SeerApiError("Seer run mirror failed to materialize", 500) | ||
| return run.seer_run_state_id | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Outbox path skips explorer index triggeringMedium Severity The outbox path returns early at line 380, completely bypassing Additional Locations (1)Reviewed by Cursor Bugbot for commit 9e2060d. Configure here. |
||
|
|
||
| response = make_agent_chat_request(chat_body, viewer_context=self.viewer_context) | ||
|
|
||
| if response.status >= 400: | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
OutboxFlushErrorhandling in outbox pathHigh Severity
The outbox context with
flush=Truecan raiseOutboxFlushErrorif the signal receiver fails (e.g., Seer returns a 500, triggering aRuntimeErrorinhandle_seer_run_create). This exception is not caught here, unlike the analogous code insearch_agent_start.pywhich wraps the block in atry/except OutboxFlushError. SinceOutboxFlushErrordoes not inherit fromSeerApiError, the endpoint's exception handler inorganization_seer_agent_chat.pywon't catch it either, resulting in an unhandled crash instead of a graceful error response.Reviewed by Cursor Bugbot for commit 9e2060d. Configure here.