Skip to content

Add retries with exponential backoff for GitHub API calls - #96109

Merged
alexey-milovidov merged 4 commits into
masterfrom
retry-gh-commands-with-backoff
Feb 6, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
retry-gh-commands-with-backoff

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 5, 2026 •

Copy link
Copy Markdown
Member

GitHub GraphQL API occasionally returns transient errors like "Something went wrong while executing your query". Add retries with exponential backoff (capped at 60 seconds) to handle these:

  • Shell.run: add backoff sleep between retries
  • GH.do_command_with_retries: replace fixed 5s sleep with backoff
  • pr_labels_and_category.py: retry gh pr edit up to 5 times
  • merge_sync_pr.py: retry gh pr ready/gh pr merge up to 5 times

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

@maxknv, see here: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96015&sha=c71f3c4a5279f70b0f2bed0d8a8ebde3ca00ab18&name_0=PR
#96015

Version info

  • Merged into: 26.2.1.333

GitHub GraphQL API occasionally returns transient errors like
"Something went wrong while executing your query". Add retries
with exponential backoff (capped at 60 seconds) to handle these:

- `Shell.run`: add backoff sleep between retries
- `GH.do_command_with_retries`: replace fixed 5s sleep with backoff
- `pr_labels_and_category.py`: retry `gh pr edit` up to 5 times
- `merge_sync_pr.py`: retry `gh pr ready`/`gh pr merge` up to 5 times
- `check_ci.py`: retry `gh pr ready`/`gh pr merge` up to 5 times

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Feb 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2646faa]

Summary: ❌

job_name test_name status info comment
Stress test (arm_asan) failure
AddressSanitizer: heap-use-after-free (STID: 2071-560b) FAIL cidb
Upgrade check (amd_release) failure
Cannot start clickhouse-server FAIL cidb
Check failed failure cidb
Stress test (amd_tsan) error
Stress test (amd_msan) error

@maxknv maxknv self-assigned this Feb 5, 2026
@maxknv
maxknv marked this pull request as draft February 5, 2026 23:11
@maxknv maxknv changed the title Add retries with exponential backoff for GitHub API calls [WIP] Add retries with exponential backoff for GitHub API calls Feb 5, 2026
@alexey-milovidov
alexey-milovidov marked this pull request as ready for review February 6, 2026 02:22
@alexey-milovidov alexey-milovidov changed the title [WIP] Add retries with exponential backoff for GitHub API calls Add retries with exponential backoff for GitHub API calls Feb 6, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

@maxknv, this is finished and ready for review!

@alexey-milovidov

Copy link
Copy Markdown
Member Author

@maxknv, we need it because GitHub is very unstable.

@maxknv

maxknv commented Feb 6, 2026

Copy link
Copy Markdown
Member

@maxknv, we need it because GitHub is very unstable.

I set it as a draft to finish it myself. Implementation is not really good. Some files should not be changed, in some places, it interferes with existing retry functionality

@maxknv
maxknv marked this pull request as draft February 6, 2026 11:47
@maxknv

maxknv commented Feb 6, 2026

Copy link
Copy Markdown
Member

@maxknv, we need it because GitHub is very unstable.

It’s the first time I’ve seen this error. I also checked other failures in this job that uses the GH CLI intensively; all of them are not GitHub-related. I’d say the gh CLI works reliably, and most issues with the GitHub API come from the checkout step, which is not related to this change anyway.

Based on the linked report, there was indeed an unexpected error returned from GitHub, but there’s no evidence that it happens occasionally or that retries would help avoid it. I’m OK to merge with some edits (i'll make them) in the code, but please no rush.

The retry mechanism in `Shell.check` was sleeping before checking if the error was retryable. This wasted time on non-retryable errors. Now checks error type first, then only sleeps if retry is warranted.

Also removed explicit `retries=5` from `gh pr` commands in `check_ci` as they now rely on default retry behavior.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@maxknv
maxknv marked this pull request as ready for review February 6, 2026 15:09
@maxknv
maxknv enabled auto-merge February 6, 2026 15:10
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Thanks for the fixes, super appreciated!

@alexey-milovidov
alexey-milovidov merged commit 79870ef into master Feb 6, 2026
249 of 257 checks passed
@alexey-milovidov
alexey-milovidov deleted the retry-gh-commands-with-backoff branch February 6, 2026 19:05
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants