Skip to content

Commit 742f25f

Browse files
authored
[AUTOREVERT] Adds circuit breaker with issue in pytorch/pytorch 'ci: disable-autorevert' (#7219)
This adds a circuit breaker to pytorch autorevert. This can be accomplished by opening an issue on pytorch/pytorch with a tag `ci: disable-autorevert`. The decision to NOT gatekeep who are the users that can disable autorevert is based on `ci: sev`. Currently any user that can open a issue in PyTorch can add a `ci: sev` issue that is merge blocking. If we believe this is a safe action and does not require getekeeping, surely it is OK to disable autorevert with the same level of access.
1 parent 9b326c7 commit 742f25f

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

aws/lambda/pytorch-auto-revert/pytorch_auto_revert/__main__.py

100644100755
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from dotenv import load_dotenv
1010

11+
from .autorevert_circuit_breaker import check_autorevert_disabled
1112
from .clickhouse_client_helper import CHCliFactory
1213
from .github_client_helper import GHClientFactory
1314
from .testers.autorevert_v2 import autorevert_v2
@@ -234,13 +235,22 @@ def main(*args, **kwargs) -> None:
234235
)
235236

236237
if opts.subcommand is None:
238+
repo_name = os.environ.get("REPO_FULL_NAME", DEFAULT_REPO_FULL_NAME)
239+
240+
if check_autorevert_disabled(repo_name):
241+
logging.error(
242+
"Autorevert is disabled via circuit breaker (ci: disable-autorevert issue found). "
243+
"Exiting successfully."
244+
)
245+
return
246+
237247
autorevert_v2(
238248
os.environ.get("WORKFLOWS", ",".join(DEFAULT_WORKFLOWS)).split(","),
239249
hours=int(os.environ.get("HOURS", DEFAULT_HOURS)),
240250
notify_issue_number=int(
241251
os.environ.get("NOTIFY_ISSUE_NUMBER", DEFAULT_COMMENT_ISSUE_NUMBER)
242252
),
243-
repo_full_name=os.environ.get("REPO_FULL_NAME", DEFAULT_REPO_FULL_NAME),
253+
repo_full_name=repo_name,
244254
restart_action=(RestartAction.LOG if opts.dry_run else RestartAction.RUN),
245255
revert_action=(
246256
RevertAction.LOG if opts.dry_run else RevertAction.RUN_NOTIFY
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import logging
2+
3+
from .github_client_helper import GHClientFactory
4+
5+
6+
logger = logging.getLogger(__name__)
7+
8+
9+
def check_autorevert_disabled(repo_full_name: str = "pytorch/pytorch") -> bool:
10+
"""
11+
Check if autorevert is disabled by looking for open issues with 'ci: disable-autorevert' label.
12+
13+
Args:
14+
repo_full_name: Repository name in format 'owner/repo'
15+
16+
Returns:
17+
True if autorevert should be disabled (circuit breaker active), False otherwise
18+
"""
19+
try:
20+
gh_client = GHClientFactory().client
21+
repo = gh_client.get_repo(repo_full_name)
22+
23+
should_disable = False
24+
25+
# Search for open issues with the specific label
26+
disable_issues = repo.get_issues(
27+
state="open", labels=["ci: disable-autorevert"]
28+
)
29+
30+
for issue in disable_issues:
31+
logger.info(
32+
f"Found open issue #{issue.number} with 'ci: disable-autorevert' label "
33+
f"created by user {issue.user.login}. "
34+
f"Autorevert circuit breaker is ACTIVE."
35+
)
36+
should_disable = True
37+
38+
sev_issues = repo.get_issues(state="open", labels=["ci: sev"])
39+
for issue in sev_issues:
40+
logger.info(
41+
f"Found open issue #{issue.number} with 'ci: sev' label "
42+
f"created by user {issue.user.login}. "
43+
f"Autorevert circuit breaker is ACTIVE."
44+
)
45+
should_disable = True
46+
47+
if should_disable:
48+
return True
49+
50+
logger.debug("No open issues with 'ci: disable-autorevert' label found.")
51+
return False
52+
53+
except Exception as e:
54+
logger.error(f"Error checking autorevert circuit breaker: {e}")
55+
# On error, default to allowing autorevert to continue
56+
return False

0 commit comments

Comments
 (0)