Skip to content

Commit bb13217

Browse files
trevor-eclaude
andcommitted
ref(seer): Drop state-push plumbing; link path just fetches
Avoiding the completion-hook re-query isn't worth a base-class change across the hooks — the extra fetch is negligible relative to existing state-endpoint traffic. The link path fetches run status directly. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f83d2a9 commit bb13217

2 files changed

Lines changed: 4 additions & 33 deletions

File tree

src/sentry/seer/agent/on_completion_hook.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from sentry import options
1010
from sentry.models.organization import Organization
11-
from sentry.seer.agent.client_models import SeerRunState
1211
from sentry.seer.agent.client_utils import fetch_run_status
1312
from sentry.seer.pr_links import link_seer_run_to_pull_request
1413

@@ -81,7 +80,6 @@ def call_on_completion_hook(
8180
module_path: str,
8281
organization_id: int,
8382
run_id: int,
84-
state: dict | None = None,
8583
allowed_prefixes: tuple[str, ...] = ("sentry.",),
8684
) -> None:
8785
"""Dynamically import and call an on-completion hook class.
@@ -90,8 +88,6 @@ def call_on_completion_hook(
9088
module_path: Full module path to the hook class (e.g., "sentry.api.MyHook")
9189
organization_id: Organization ID to load and pass to the hook
9290
run_id: The run ID that completed
93-
state: The completed run's serialized state, if Seer pushed it; lets us
94-
skip re-querying Seer for PR linking.
9591
allowed_prefixes: Tuple of allowed module path prefixes for security
9692
"""
9793
# Only allow imports from approved package prefixes
@@ -106,7 +102,7 @@ def call_on_completion_hook(
106102
except Organization.DoesNotExist:
107103
raise ValueError(f"Organization with id {organization_id} does not exist")
108104

109-
_link_run_pull_requests(organization, run_id, state)
105+
_link_run_pull_requests(organization, run_id)
110106

111107
# Split module path and class name
112108
parts = module_path.rsplit(".", 1)
@@ -130,19 +126,13 @@ def call_on_completion_hook(
130126
hook_class.execute(organization, run_id)
131127

132128

133-
def _link_run_pull_requests(
134-
organization: Organization, run_id: int, state: dict | None
135-
) -> None:
136-
"""Record a SeerRunPullRequest for each PR the completed run opened.
137-
138-
Uses the run state Seer pushed with the hook call; falls back to querying Seer
139-
when it wasn't provided.
140-
"""
129+
def _link_run_pull_requests(organization: Organization, run_id: int) -> None:
130+
"""Record a SeerRunPullRequest for each PR the completed run opened."""
141131
if options.get("seer.run-pr-link.killswitch.enabled"):
142132
return
143133

144134
try:
145-
run_state = SeerRunState(**state) if state is not None else fetch_run_status(run_id, organization)
135+
run_state = fetch_run_status(run_id, organization)
146136
except Exception:
147137
logger.exception(
148138
"seer.pr_link.state_unavailable",

tests/sentry/seer/agent/test_on_completion_hook.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,6 @@ def test_links_pull_requests_for_any_hook(self, mock_fetch) -> None:
9999
assert link.seer_run_id == run.id
100100
assert self.organization.get_option("test_hook_run_id") == 777
101101

102-
@patch("sentry.seer.agent.on_completion_hook.fetch_run_status")
103-
def test_links_from_pushed_state_without_querying_seer(self, mock_fetch) -> None:
104-
repo = self.create_repo(
105-
self.project, name="getsentry/sentry", provider="integrations:github"
106-
)
107-
run = self.create_seer_run(organization=self.organization, seer_run_state_id=777)
108-
109-
call_on_completion_hook(
110-
module_path=HOOK_PATH,
111-
organization_id=self.organization.id,
112-
run_id=777,
113-
state=_state_with_pr(777, "getsentry/sentry", 5).dict(),
114-
allowed_prefixes=("tests.sentry.",),
115-
)
116-
117-
mock_fetch.assert_not_called()
118-
pr = PullRequest.objects.get(repository_id=repo.id, key="5")
119-
assert SeerRunPullRequest.objects.get(pull_request=pr).seer_run_id == run.id
120-
121102
@patch("sentry.seer.agent.on_completion_hook.fetch_run_status")
122103
def test_killswitch_skips_linking_but_runs_hook(self, mock_fetch) -> None:
123104
self.create_repo(self.project, name="getsentry/sentry", provider="integrations:github")

0 commit comments

Comments
 (0)