Skip to content

Commit 95e2abc

Browse files
joseph-sentryclaude
andcommitted
feat(autofix): Push PR iteration changes and sync completion webhook
When a PR iteration run finishes, the agent's new file patches still need to be pushed to the existing PR. Trigger that push from the completion hook so the PR is updated, and only emit the iteration completion webhook on the synced pass so the payload reflects the updated PR and we don't double-fire. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 30f8ee6 commit 95e2abc

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/sentry/seer/autofix/on_completion_hook.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ def _send_step_webhook(
186186
elif current_step == AutofixStep.PR_ITERATION:
187187
# PR iteration only runs against an existing PR, so there must be pr states.
188188
assert state.repo_pr_states, "PR iteration completed without any repo PR states"
189+
# The iteration agent produces new file patches that still need to be
190+
# pushed to the existing PR. The first hook fire (right after the agent
191+
# finishes) has unsynced changes; _maybe_continue_pipeline triggers the
192+
# push, which re-fires this hook once the PR is updated. Only emit the
193+
# completion webhook on that synced pass so the payload reflects the
194+
# updated PR and we don't double-fire.
195+
_, is_synced = state.has_code_changes()
196+
if not is_synced:
197+
return
189198
webhook_action_type = SeerActionType.ITERATION_COMPLETED
190199
iteration_index = get_latest_iteration_index(state)
191200
webhook_payload["pull_requests"] = cls._format_pull_requests_payload(state)
@@ -410,6 +419,14 @@ def _maybe_continue_pipeline(
410419
},
411420
)
412421

422+
# PR iteration runs against an existing PR rather than the automated
423+
# pipeline. Once the agent finishes iterating, push the new changes to
424+
# update that PR. _push_changes is a no-op once the repos are synced, so
425+
# the hook re-fire after the push doesn't loop.
426+
if current_step == AutofixStep.PR_ITERATION:
427+
cls._push_changes(group, run_id, state)
428+
return
429+
413430
if stopping_point is None or reached_stopping_point:
414431
# We've reached the stopping point
415432
return

0 commit comments

Comments
 (0)