-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(autofix): Autotrigger root cause if legacy autofix ran #111718
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
Merged
Zylphrex
merged 3 commits into
master
from
txiao/feat/auto-trigger-root-cause-if-legacy-autofix-ran
Mar 27, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
static/app/components/events/autofix/v3/useAutoTriggerAutofix.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import {GroupFixture} from 'sentry-fixture/group'; | ||
|
|
||
| import {renderHook} from 'sentry-test/reactTestingLibrary'; | ||
|
|
||
| import type {useExplorerAutofix} from 'sentry/components/events/autofix/useExplorerAutofix'; | ||
| import {useAutoTriggerAutofix} from 'sentry/components/events/autofix/v3/useAutoTriggerAutofix'; | ||
|
|
||
| function makeAutofix( | ||
| overrides: Partial<ReturnType<typeof useExplorerAutofix>> = {} | ||
| ): ReturnType<typeof useExplorerAutofix> { | ||
| return { | ||
| runState: null, | ||
| startStep: jest.fn(), | ||
| createPR: jest.fn(), | ||
| reset: jest.fn(), | ||
| triggerCodingAgentHandoff: jest.fn(), | ||
| isLoading: false, | ||
| isPolling: false, | ||
| ...overrides, | ||
| } as ReturnType<typeof useExplorerAutofix>; | ||
| } | ||
|
|
||
| describe('useAutoTriggerAutofix', () => { | ||
| it('starts root_cause when seerAutofixLastTriggered is set but seerExplorerAutofixLastTriggered is not', () => { | ||
| const autofix = makeAutofix(); | ||
| const group = GroupFixture({ | ||
| seerAutofixLastTriggered: '2024-01-01T00:00:00Z', | ||
| seerExplorerAutofixLastTriggered: null, | ||
| }); | ||
|
|
||
| renderHook(() => useAutoTriggerAutofix({autofix, group})); | ||
|
|
||
| expect(autofix.startStep).toHaveBeenCalledWith('root_cause'); | ||
| expect(autofix.startStep).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('does not start root_cause when seerExplorerAutofixLastTriggered is set', () => { | ||
| const autofix = makeAutofix(); | ||
| const group = GroupFixture({ | ||
| seerAutofixLastTriggered: '2024-01-01T00:00:00Z', | ||
| seerExplorerAutofixLastTriggered: '2024-01-02T00:00:00Z', | ||
| }); | ||
|
|
||
| renderHook(() => useAutoTriggerAutofix({autofix, group})); | ||
|
|
||
| expect(autofix.startStep).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('does not trigger root_cause more than once on re-render', () => { | ||
| const autofix = makeAutofix(); | ||
| const group = GroupFixture({ | ||
| seerAutofixLastTriggered: '2024-01-01T00:00:00Z', | ||
| seerExplorerAutofixLastTriggered: null, | ||
| }); | ||
|
|
||
| const {rerender} = renderHook(() => useAutoTriggerAutofix({autofix, group})); | ||
|
|
||
| rerender(); | ||
| rerender(); | ||
|
|
||
| expect(autofix.startStep).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
34 changes: 34 additions & 0 deletions
34
static/app/components/events/autofix/v3/useAutoTriggerAutofix.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import {useEffect, useRef} from 'react'; | ||
|
|
||
| import {useExplorerAutofix} from 'sentry/components/events/autofix/useExplorerAutofix'; | ||
| import type {Group} from 'sentry/types/group'; | ||
|
|
||
| interface UseAutoTriggerAutofixOptions { | ||
| autofix: ReturnType<typeof useExplorerAutofix>; | ||
| group: Group; | ||
| } | ||
|
|
||
| export function useAutoTriggerAutofix({autofix, group}: UseAutoTriggerAutofixOptions) { | ||
| const alreadyTriggered = useRef(false); | ||
|
|
||
| // extract startStep first here so we can depend on it directly as `autofix` itself is unstable. | ||
| const startStep = autofix.startStep; | ||
|
|
||
| useEffect(() => { | ||
| if (alreadyTriggered.current) { | ||
| return; | ||
| } | ||
|
|
||
| // In order to have a smooth transition from legacy to explorer autofix, we want to automatically | ||
| // trigger autofix when users view an issue that had legacy but not explorer autofix. | ||
| const shouldAutotriggerAutofix = | ||
| !!group.seerAutofixLastTriggered && !group.seerExplorerAutofixLastTriggered; | ||
|
|
||
| if (!shouldAutotriggerAutofix) { | ||
| return; | ||
| } | ||
|
|
||
| alreadyTriggered.current = true; | ||
| startStep('root_cause'); | ||
| }, [group, startStep]); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ref not reset when group changes prevents re-triggering
Medium Severity
The
alreadyTriggeredref never resets whengroup.idchanges. When a user navigates between issues without the component unmounting (e.g., prev/next navigation), the ref staystruefrom the first issue, preventing auto-trigger for any subsequent qualifying issue. The ref needs to be tied to the group identity so it resets when viewing a different issue.