@@ -354,11 +354,13 @@ jobs:
354354 }
355355 }
356356
357- // Strips stateLabels from a PR, optionally keeping one.
357+ // Strips stateLabels from a PR, optionally keeping one desired label
358+ // plus any labels in keepLabels (e.g. has-conflicts while mergeability
359+ // is unknown — kept, never added, per the hoisted check below).
358360 // Also removes stale-awaiting-author when not keeping awaiting-author.
359361 // Only skipped when this run's own token is read-only (see isReadOnlyRun) —
360362 // schedule/workflow_dispatch runs reconcile fork PRs normally.
361- async function reconcileLabels(pr, desiredLabel) {
363+ async function reconcileLabels(pr, desiredLabel, keepLabels = [] ) {
362364 if (isReadOnlyRun && isForkPR(pr)) {
363365 core.info(`PR #${pr.number}: fork PR on a read-only run — skipping label mutation`);
364366 return;
@@ -379,7 +381,7 @@ jobs:
379381 }
380382 }
381383 for (const label of stateLabels) {
382- if (label !== desiredLabel && currentLabels.has(label)) {
384+ if (label !== desiredLabel && !keepLabels.includes(label) && currentLabels.has(label)) {
383385 try {
384386 await github.rest.issues.removeLabel({
385387 owner, repo, issue_number: pr.number, name: label,
@@ -752,6 +754,26 @@ jobs:
752754 continue;
753755 }
754756
757+ // Unknown mergeability is handled once here, ahead of every
758+ // branch that reconciles labels (issue #2045). GitHub recomputes
759+ // mergeability asynchronously after each push and transiently
760+ // reports `mergeable: null` / `mergeable_state: "unknown"` while
761+ // the background job runs, so unknown says nothing about
762+ // conflicts: an existing has-conflicts label is kept through
763+ // reconciliation — unknown is not evidence the conflicts went
764+ // away — and it is never added, since unknown is not evidence
765+ // of conflicts either. Known-dirty never reaches here (the
766+ // conflict check above handles it first); known-clean keeps the
767+ // strip. The awaiting-maintainer branch below still refetches
768+ // mergeability before the maintainer handoff, because a push
769+ // between this fetch and labeling can change the answer.
770+ // A kept has-conflicts label can sit next to other state labels
771+ // until mergeability is known. This is intended.
772+ const mergeabilityUnknown =
773+ prDetail.mergeable === null || prDetail.mergeable_state === 'unknown';
774+ const keepHasConflicts = mergeabilityUnknown &&
775+ pr.labels.some(label => label.name === 'has-conflicts');
776+
755777 // Check CI status for required checks on the PR's head commit only.
756778 // Scoping to required checks avoids advisory checks (e.g. codecov/patch)
757779 // incorrectly blocking label assignment on otherwise-ready PRs.
@@ -851,16 +873,10 @@ jobs:
851873 // Exception (issue #2025): while GitHub is still computing
852874 // mergeability, a missing required check can simply mean a
853875 // conflicting PR got no merge-ref CI run — not that its
854- // conflicts went away. Keep an existing has-conflicts label
855- // through this branch instead of stripping it with the other
856- // state labels. Known-clean mergeability keeps the strip, and
857- // known-dirty never reaches here (the conflict check above
858- // handles it first).
876+ // conflicts went away. keepHasConflicts (computed once above)
877+ // keeps an existing has-conflicts label through this branch
878+ // instead of stripping it with the other state labels.
859879 if (ciPending || ciFailed) {
860- const mergeabilityUnknown =
861- prDetail.mergeable === null || prDetail.mergeable_state === 'unknown';
862- const keepHasConflicts = mergeabilityUnknown &&
863- pr.labels.some(label => label.name === 'has-conflicts');
864880 core.info(
865881 `PR #${pr.number}: CI ${ciPending ? 'pending' : 'failed'} — stripping state labels` +
866882 (keepHasConflicts ? ' (keeping has-conflicts while mergeability is unknown)' : '')
@@ -1133,6 +1149,7 @@ jobs:
11331149
11341150 core.info(
11351151 `PR #${pr.number}: CI passing, reviews=${latest.size}, ` +
1152+ `mergeable=${prDetail.mergeable}, mergeable_state=${prDetail.mergeable_state}, ` +
11361153 `coderabbit=${freshCodeRabbitReview?.state ?? (codeRabbitEligibleAuthor ? 'pending' : 'optional')}, ` +
11371154 `maintainer=${maintainerApproval?.state ?? 'pending'}, blockers=${maintainerBlockers.size} → ${desiredLabel ?? '(none)'}`
11381155 );
@@ -1153,7 +1170,7 @@ jobs:
11531170 if (recyclingActiveLabel) {
11541171 await updateReviewGuide(pr, phase, existingGuide);
11551172 }
1156- await reconcileLabels(pr, desiredLabel);
1173+ await reconcileLabels(pr, desiredLabel, keepHasConflicts ? ['has-conflicts'] : [] );
11571174 await reconcileCommunityApproval(pr, communityDecision);
11581175 if (readyForMaintainer) {
11591176 await updateReviewGate(pr, phase, true);
0 commit comments