Skip to content

Commit 6702bbf

Browse files
fix(autofix): Only show PR section when PRs are in sync with code
The PR card now only appears when all PRs match the current code changes (commit SHA comparison). This prevents the PR card from showing above the "Are you happy with these code changes?" prompt. - Added areAllPRsInSync() helper for commit SHA comparison - PR section hidden when code is out of sync or no PR exists yet - CodeChangesNextStep returns null when all PRs are in sync Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ee288f5 commit 6702bbf

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

static/app/components/events/autofix/useExplorerAutofix.tsx

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -371,26 +371,22 @@ export function getOrderedAutofixSections(runState: ExplorerAutofixState | null)
371371
// Finalize the last in-progress section.
372372
finalizeSection();
373373

374-
// Only show synthetic PR and coding-agent sections when code_changes is
375-
// completed. After a retry-from-step truncates blocks, these would be stale
376-
// and would prevent NextStep buttons from appearing.
377374
const hasCompletedCodeChanges = sections.some(
378375
s => s.step === 'code_changes' && s.status === 'completed'
379376
);
380377

381378
if (hasCompletedCodeChanges) {
382-
const pullRequests = Object.values(runState?.repo_pr_states ?? {});
383-
if (pullRequests.length) {
379+
// Only show the PR section when all PRs are in sync with current code.
380+
// Otherwise the NextStep prompt handles create/update flow.
381+
const repoPRStates = runState?.repo_pr_states ?? {};
382+
if (areAllPRsInSync(blocks, repoPRStates)) {
383+
const pullRequests = Object.values(repoPRStates);
384384
sections.push({
385385
step: 'pull_request',
386386
blockIndex: blocks.length,
387387
artifacts: [pullRequests],
388388
messages: [],
389-
status: pullRequests.some(
390-
pullRequest => pullRequest.pr_creation_status === 'creating'
391-
)
392-
? 'processing'
393-
: 'completed',
389+
status: 'completed',
394390
});
395391
}
396392

@@ -435,6 +431,36 @@ export function isCodingAgentsSection(section: AutofixSection): boolean {
435431
return section.step === 'coding_agents';
436432
}
437433

434+
/**
435+
* Checks if all PRs are in sync with the current code changes.
436+
* A PR is in sync when its commit_sha matches the pr_commit_shas on the
437+
* last block that has merged patches for that repo.
438+
*/
439+
export function areAllPRsInSync(
440+
blocks: Block[],
441+
repoPRStates: Record<string, RepoPRState>
442+
): boolean {
443+
const pullRequests = Object.values(repoPRStates);
444+
if (!pullRequests.length) {
445+
return false;
446+
}
447+
return pullRequests.every(pr => {
448+
if (pr.pr_creation_status === 'creating') {
449+
return false;
450+
}
451+
if (!pr.pr_number || !pr.pr_url || !pr.commit_sha) {
452+
return false;
453+
}
454+
for (let i = blocks.length - 1; i >= 0; i--) {
455+
const block = blocks[i];
456+
if (block?.merged_file_patches?.some(p => p.repo_name === pr.repo_name)) {
457+
return block.pr_commit_shas?.[pr.repo_name] === pr.commit_sha;
458+
}
459+
}
460+
return false;
461+
});
462+
}
463+
438464
export type AutofixArtifact =
439465
| Artifact<unknown>
440466
| ExplorerFilePatch[]

static/app/components/events/autofix/v3/nextStep.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
type CodingAgentIntegration,
1414
} from 'sentry/components/events/autofix/useAutofix';
1515
import {
16+
areAllPRsInSync,
1617
getAutofixArtifactFromSection,
1718
isCodeChangesSection,
1819
isCodingAgentsSection,
@@ -240,7 +241,17 @@ function CodeChangesNextStep({autofix, group, runId, section, referrer}: NextSte
240241

241242
const artifact = useMemo(() => getAutofixArtifactFromSection(section), [section]);
242243

243-
if (!defined(artifact)) {
244+
// All PRs are already in sync with current code — nothing for the user to do
245+
const allInSync = useMemo(
246+
() =>
247+
areAllPRsInSync(
248+
autofix.runState?.blocks ?? [],
249+
autofix.runState?.repo_pr_states ?? {}
250+
),
251+
[autofix.runState?.blocks, autofix.runState?.repo_pr_states]
252+
);
253+
254+
if (!defined(artifact) || allInSync) {
244255
return null;
245256
}
246257

0 commit comments

Comments
 (0)