Skip to content

refactor: extract duplicate backoff delay calc into _backoff_seconds helper - #811

Merged
anderdc merged 2 commits into
entrius:testfrom
wdeveloper16:refactor/extract-backoff-seconds-helper
Apr 30, 2026
Merged

refactor: extract duplicate backoff delay calc into _backoff_seconds helper#811
anderdc merged 2 commits into
entrius:testfrom
wdeveloper16:refactor/extract-backoff-seconds-helper

Conversation

@wdeveloper16

Copy link
Copy Markdown
Contributor

Closes: #810

Summary

  • The expression min(5 * (2**attempt), 30) (and two variants) was copy-pasted across 9 call sites in github_api_tools.py
  • Extracts a single private _backoff_seconds(attempt, base=5, cap=30) helper that encodes the formula once
  • All callers (get_merge_base_sha, get_pull_request_file_changes, execute_graphql_query, get_github_graphql_query) updated — no behaviour change

Test plan

  • Confirm existing tests pass
  • Verify backoff values unchanged: attempt 0→5s, 1→10s, 2→20s, 3→30s (capped)
  • Confirm resource-limit variant (base=2, cap=15) still correct

@xiao-xiao-mao xiao-xiao-mao Bot added the refactor Code restructuring without behavior change label Apr 27, 2026
@wdeveloper16
wdeveloper16 force-pushed the refactor/extract-backoff-seconds-helper branch 9 times, most recently from 374d9d7 to 99878b5 Compare April 29, 2026 20:21

@anderdc anderdc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same formula lives in gittensor/utils/mirror/client.py:106 and :123 — both min(5 * (2**attempt), 30), identical to most call sites here. Pull those in too. Move the helper to gittensor/utils/utils.py (next to parse_repo_name) and drop the leading underscore so both files import it from there — avoids a mirror→github_api_tools dependency and keeps it where shared utilities already live.

The linear 2 * (attempt + 1) at github_api_tools.py:567 and the time.sleep(2**attempt) in neurons/base/neuron.py:147 are different shapes — leave alone.

@wdeveloper16

Copy link
Copy Markdown
Contributor Author

Thanks for your review, Fair point.
Will fix it right away.

@wdeveloper16
wdeveloper16 force-pushed the refactor/extract-backoff-seconds-helper branch 2 times, most recently from fa7ef66 to cfc6ffe Compare April 29, 2026 20:38
@wdeveloper16
wdeveloper16 requested a review from anderdc April 29, 2026 20:39
@wdeveloper16
wdeveloper16 force-pushed the refactor/extract-backoff-seconds-helper branch from cfc6ffe to eb41369 Compare April 29, 2026 20:40
@wdeveloper16

Copy link
Copy Markdown
Contributor Author

Just done!
I'd be happy if you'd review the PR again.
Thanks

@wdeveloper16
wdeveloper16 force-pushed the refactor/extract-backoff-seconds-helper branch from eb41369 to 081e0b1 Compare April 29, 2026 21:44
@anderdc
anderdc merged commit 5d62308 into entrius:test Apr 30, 2026
3 checks passed
plind-junior added a commit to plind-junior/gittensor that referenced this pull request Apr 30, 2026
…lper

- Restore additional_acceptable_branches dropped during rebase (jupyterlab,
  FastGPT, monero, nextcloud/desktop, nextcloud/server, zed) — added upstream
  in entrius#831 and lost when this branch was based on a stale snapshot.
- Add entrius/das-github-mirror at weight 0.2 with trusted_label_pipeline
  (deliverable entrius#4 from issue entrius#911).
- Inline _label_actor_trusted into _resolve_maintainer_set_label per the
  codebase's single-use-helper convention (entrius#818/entrius#811/entrius#801); drop the
  now-redundant TestLabelActorTrusted truth table since coverage lives in
  TestLabelResolution end-to-end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code restructuring without behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicated exponential-backoff formula across 9 call sites in github_api_tools.py

2 participants