diff --git a/.github/scripts/pull-request-dashboard/pr_status_comment.py b/.github/scripts/pull-request-dashboard/pr_status_comment.py index 62b1dd6ff96..cc068aca3d3 100644 --- a/.github/scripts/pull-request-dashboard/pr_status_comment.py +++ b/.github/scripts/pull-request-dashboard/pr_status_comment.py @@ -368,7 +368,10 @@ def prepare_rollout_state( rollout_state: dict[str, Any], open_pr_numbers: set[int], ) -> dict[str, Any]: - if rollout_state.get("target_revision") != STATUS_COMMENT_REVISION: + target_revision = int(rollout_state.get("target_revision") or 0) + if target_revision > STATUS_COMMENT_REVISION: + return dict(rollout_state) + if target_revision < STATUS_COMMENT_REVISION: return { "target_revision": STATUS_COMMENT_REVISION, "completed_revision": int(rollout_state.get("completed_revision") or 0), @@ -396,6 +399,12 @@ def update_status_comments_from_state( return [] saved_rollout_state = load_status_comment_rollout_state() + if saved_rollout_state.get("target_revision", 0) > STATUS_COMMENT_REVISION: + print( + "status comment rollout targets a newer renderer revision; skipping stale worker", + file=sys.stderr, + ) + return [] queued_pr_numbers = set(saved_rollout_state.get("pending_pr_numbers") or []) rollout_state = prepare_rollout_state(saved_rollout_state, open_pr_numbers) pending_pr_numbers = set(rollout_state["pending_pr_numbers"]) | queued_pr_numbers diff --git a/.github/scripts/pull-request-dashboard/test_pr_status_comment.py b/.github/scripts/pull-request-dashboard/test_pr_status_comment.py index ca1771c555d..439987ade9e 100644 --- a/.github/scripts/pull-request-dashboard/test_pr_status_comment.py +++ b/.github/scripts/pull-request-dashboard/test_pr_status_comment.py @@ -635,6 +635,45 @@ def test_current_revision_drops_closed_prs_from_queue(self) -> None: self.assertEqual([34], state["pending_pr_numbers"]) + def test_older_revision_preserves_newer_rollout_state(self) -> None: + newer_state = { + "target_revision": pr_status_comment.STATUS_COMMENT_REVISION + 1, + "completed_revision": pr_status_comment.STATUS_COMMENT_REVISION, + "pending_pr_numbers": [12, 34], + } + + state = pr_status_comment.prepare_rollout_state(newer_state, {34, 56}) + + self.assertEqual(newer_state, state) + + @patch.object(pr_status_comment, "save_status_comment_rollout_state") + @patch.object(pr_status_comment, "publish_pr_status") + @patch.object(pr_status_comment, "load_dashboard_state_cache", return_value={"prs": {}}) + @patch.object( + pr_status_comment, + "load_status_comment_rollout_state", + return_value={ + "target_revision": pr_status_comment.STATUS_COMMENT_REVISION + 1, + "completed_revision": pr_status_comment.STATUS_COMMENT_REVISION, + "pending_pr_numbers": [12, 34], + }, + ) + def test_older_revision_does_not_publish_or_mutate_newer_rollout( + self, + _load_rollout: object, + _load_dashboard: object, + publish_pr_status: Mock, + save_rollout: Mock, + ) -> None: + status = pr_status_comment.update_status_comments_from_state( + "open-telemetry/example", + {12, 34}, + ) + + self.assertEqual([], status) + publish_pr_status.assert_not_called() + save_rollout.assert_not_called() + @patch.object(pr_status_comment, "save_status_comment_rollout_state") @patch.object(pr_status_comment, "publish_pr_status") @patch.object(pr_status_comment, "load_dashboard_state_cache", return_value={"prs": {}})