-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(autofix automation): Use user preference as upper bound for stopping point [feature flagged] #103237
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
feat(autofix automation): Use user preference as upper bound for stopping point [feature flagged] #103237
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 |
|---|---|---|
|
|
@@ -51,6 +51,13 @@ | |
| SeerAutomationSource.POST_PROCESS: "issue_summary_on_post_process_fixability", | ||
| } | ||
|
|
||
| STOPPING_POINT_HIERARCHY = { | ||
| AutofixStoppingPoint.ROOT_CAUSE: 1, | ||
| AutofixStoppingPoint.SOLUTION: 2, | ||
| AutofixStoppingPoint.CODE_CHANGES: 3, | ||
| AutofixStoppingPoint.OPEN_PR: 4, | ||
| } | ||
|
|
||
|
|
||
| def _get_stopping_point_from_fixability(fixability_score: float) -> AutofixStoppingPoint | None: | ||
| """ | ||
|
|
@@ -64,6 +71,58 @@ def _get_stopping_point_from_fixability(fixability_score: float) -> AutofixStopp | |
| return AutofixStoppingPoint.CODE_CHANGES | ||
|
|
||
|
|
||
| def _fetch_user_preference(project_id: int) -> str | None: | ||
| """ | ||
| Fetch the user's automated_run_stopping_point preference from Seer. | ||
| Returns None if preference is not set or if the API call fails. | ||
| """ | ||
| try: | ||
| path = "/v1/project-preference" | ||
| body = orjson.dumps({"project_id": project_id}) | ||
|
|
||
| response = requests.post( | ||
| f"{settings.SEER_AUTOFIX_URL}{path}", | ||
| data=body, | ||
| headers={ | ||
| "content-type": "application/json;charset=utf-8", | ||
| **sign_with_seer_secret(body), | ||
| }, | ||
| timeout=5, | ||
| ) | ||
| response.raise_for_status() | ||
|
|
||
| result = response.json() | ||
| preference = result.get("preference") | ||
| if preference: | ||
| return preference.get("automated_run_stopping_point") | ||
| return None | ||
| except Exception as e: | ||
| sentry_sdk.set_context("project", {"project_id": project_id}) | ||
| sentry_sdk.capture_exception(e) | ||
| return None | ||
|
|
||
|
|
||
| def _apply_user_preference_upper_bound( | ||
| fixability_suggestion: AutofixStoppingPoint | None, | ||
| user_preference: str | None, | ||
| ) -> AutofixStoppingPoint | None: | ||
| """ | ||
| Apply user preference as an upper bound on the fixability-based stopping point. | ||
| Returns the more conservative (earlier) stopping point between the two. | ||
| """ | ||
| if fixability_suggestion is None or user_preference is None: | ||
| return fixability_suggestion | ||
|
|
||
| user_stopping_point = AutofixStoppingPoint(user_preference) | ||
|
|
||
| return ( | ||
| fixability_suggestion | ||
| if STOPPING_POINT_HIERARCHY[fixability_suggestion] | ||
| <= STOPPING_POINT_HIERARCHY[user_stopping_point] | ||
| else user_stopping_point | ||
| ) | ||
|
|
||
|
|
||
| @instrumented_task( | ||
| name="sentry.tasks.autofix.trigger_autofix_from_issue_summary", | ||
| namespace=seer_tasks, | ||
|
|
@@ -277,8 +336,19 @@ def _run_automation( | |
|
|
||
| stopping_point = None | ||
| if features.has("projects:triage-signals-v0", group.project): | ||
| stopping_point = _get_stopping_point_from_fixability(issue_summary.scores.fixability_score) | ||
| logger.info("Fixability-based stopping point: %s", stopping_point) | ||
| fixability_stopping_point = _get_stopping_point_from_fixability( | ||
| issue_summary.scores.fixability_score | ||
| ) | ||
| logger.info("Fixability-based stopping point: %s", fixability_stopping_point) | ||
|
|
||
| # Fetch user preference and apply as upper bound | ||
| user_preference = _fetch_user_preference(group.project.id) | ||
| logger.info("User preference stopping point: %s", user_preference) | ||
|
|
||
| stopping_point = _apply_user_preference_upper_bound( | ||
| fixability_stopping_point, user_preference | ||
| ) | ||
| logger.info("Final stopping point after upper bound: %s", stopping_point) | ||
|
Comment on lines
+342
to
+351
Member
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. are these logs necessary?
Contributor
Author
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. They are a bit extra but I was thinking to keep them in for now to validate everything and in case we see something unexpected. I do plan to remove them soon. |
||
|
|
||
| _trigger_autofix_task.delay( | ||
| group_id=group.id, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.