Skip to content

Enhance GitHub client with retry/rate-limit and add bot-loop prevention#5

Open
Keramikus-97 wants to merge 2 commits into
mainfrom
devin/1780763023-enhance-client
Open

Enhance GitHub client with retry/rate-limit and add bot-loop prevention#5
Keramikus-97 wants to merge 2 commits into
mainfrom
devin/1780763023-enhance-client

Conversation

@Keramikus-97

Copy link
Copy Markdown
Owner

Summary

The GitHubClient now handles transient failures automatically and the WebhookProcessor prevents bot-loop storms.

Retry + rate-limit in _request: Retries up to max_retries on 429/5xx with exponential backoff. Respects Retry-After and X-RateLimit-Reset headers (capped at 60s). When 429 retries are exhausted, raises RateLimitError(reset_at=...) instead of generic GitHubAPIError. Non-retryable 4xx errors fail immediately on first attempt.

client = GitHubClient(token=tok, max_retries=3, backoff_base=1.0)
# 500 → wait 1s → 500 → wait 2s → 500 → wait 4s → raise GitHubAPIError
# 429 with Retry-After: 5 → wait 5s → retry

Bot-loop prevention in WebhookProcessor: New ignore_logins parameter — comments from those logins return skipped_reason="ignored_login" before command extraction, preventing the bot from responding to its own comments.

async with WebhookProcessor(config, ignore_logins={"my-bot[bot]"}) as proc:
    result = await proc.process(...)  # skips if sender is in ignore set

New API methods: create_pull_request, update_file (Contents API), create_commit_status.

21 new tests (83 total).

Link to Devin session: https://app.devin.ai/sessions/306b14b0580b4a1d830a4afc1c2dfd86
Requested by: @Keramikus-97

- Add handler.py with WebhookProcessor that orchestrates the full webhook
  processing flow: signature verification, payload parsing, command
  extraction, and acknowledgement via reaction
- Export all public symbols from __init__.py
- Add comprehensive tests for the handler module (9 tests)
- GitHubClient: automatic retries with exponential backoff for 429/5xx
- GitHubClient: respect Retry-After and X-RateLimit-Reset headers
- GitHubClient: RateLimitError raised when retries exhausted on 429
- GitHubClient: new methods create_pull_request, update_file, create_commit_status
- WebhookProcessor: ignore_logins parameter for bot-loop prevention
- Export RateLimitError from package __init__
- 21 new tests (83 total, all passing)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant