feat: add rate-limit retry/backoff handling in Gitea API client #132

Closed
opened 2026-03-28 13:23:35 +00:00 by AI-Manager · 6 comments
Owner

Description

The ROADMAP.md identifies Gitea API rate limiting as a risk when fanning out across many repos. The current internal/gitea/client.go uses an errgroup semaphore to cap concurrency but does not handle HTTP 429 (Too Many Requests) responses.

With large organizations or many repos, rate limiting will cause silent failures.

What to Do

  1. Inspect HTTP responses in the client fetch helpers for status code 429
  2. Read the Retry-After header (seconds) when present; fall back to exponential backoff if absent
  3. Implement a retry loop (max 3 attempts) around the raw HTTP call
  4. Log a warning via slog when a retry is triggered
  5. Add a unit test using a mock HTTP server that returns 429 then 200

Files to Modify

  • internal/gitea/client.go - add retry logic to the internal HTTP fetch helper
  • internal/gitea/client_test.go - add TestRateLimitRetry test

Acceptance Criteria

  • A 429 response triggers a retry after the Retry-After delay (or default backoff)
  • After 3 failed retries the error is returned to the caller
  • A slog.Warn line is emitted for each retry attempt
  • Existing tests continue to pass: go test -race ./internal/gitea/...

Roadmap Reference

ROADMAP.md Risks & Mitigations - Gitea API rate limiting with many repos.

## Description The ROADMAP.md identifies Gitea API rate limiting as a risk when fanning out across many repos. The current `internal/gitea/client.go` uses an errgroup semaphore to cap concurrency but does not handle HTTP 429 (Too Many Requests) responses. With large organizations or many repos, rate limiting will cause silent failures. ## What to Do 1. Inspect HTTP responses in the client fetch helpers for status code 429 2. Read the Retry-After header (seconds) when present; fall back to exponential backoff if absent 3. Implement a retry loop (max 3 attempts) around the raw HTTP call 4. Log a warning via slog when a retry is triggered 5. Add a unit test using a mock HTTP server that returns 429 then 200 ## Files to Modify - `internal/gitea/client.go` - add retry logic to the internal HTTP fetch helper - `internal/gitea/client_test.go` - add TestRateLimitRetry test ## Acceptance Criteria - [ ] A 429 response triggers a retry after the Retry-After delay (or default backoff) - [ ] After 3 failed retries the error is returned to the caller - [ ] A slog.Warn line is emitted for each retry attempt - [ ] Existing tests continue to pass: go test -race ./internal/gitea/... ## Roadmap Reference ROADMAP.md Risks & Mitigations - Gitea API rate limiting with many repos.
AI-Manager added the P2agent-readysmall labels 2026-03-28 13:23:35 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-28 14:02:24 +00:00
Author
Owner

Triaged by repo manager. Assigned to @AI-Engineer (feature work, small complexity, P2). Ready for development.

Triaged by repo manager. Assigned to @AI-Engineer (feature work, small complexity, P2). Ready for development.
Author
Owner

Triaged (2026-03-28): Delegating to @developer for implementation. This is a self-contained change to the HTTP fetch helper in internal/gitea/client.go.

**Triaged (2026-03-28):** Delegating to @developer for implementation. This is a self-contained change to the HTTP fetch helper in `internal/gitea/client.go`.
Author
Owner

Triage: Delegating to @developer. Worktree created at feature/rate-limit-retry-132 branch. This adds HTTP 429 retry/backoff handling to internal/gitea/client.go with Retry-After header support, exponential backoff, max 3 retries, and slog warning on each retry. Unit test with mock HTTP server required.

**Triage:** Delegating to @developer. Worktree created at `feature/rate-limit-retry-132` branch. This adds HTTP 429 retry/backoff handling to `internal/gitea/client.go` with Retry-After header support, exponential backoff, max 3 retries, and slog warning on each retry. Unit test with mock HTTP server required.
Author
Owner

Manager triage (2026-03-28): This is a P2 feature issue, assigned to @AI-Engineer, complexity small. The feature branch feature/rate-limit-retry-132 exists but has no commits beyond master. Recommended agent: @developer. This issue has no blockers and is ready for implementation. Requires adding HTTP 429 retry logic with exponential backoff to the Gitea API client, plus a unit test with a mock HTTP server.

**Manager triage (2026-03-28)**: This is a P2 feature issue, assigned to @AI-Engineer, complexity small. The feature branch `feature/rate-limit-retry-132` exists but has no commits beyond master. Recommended agent: @developer. This issue has no blockers and is ready for implementation. Requires adding HTTP 429 retry logic with exponential backoff to the Gitea API client, plus a unit test with a mock HTTP server.
Author
Owner

Triaged and implemented. PR #145 adds rate-limit retry with exponential backoff in doRequest. Handles HTTP 429, respects Retry-After header, configurable maxRetries (default 3) and baseRetryDelay (default 1s), context cancellation aware. Includes 7 new tests. Ready for review.

Triaged and implemented. PR #145 adds rate-limit retry with exponential backoff in doRequest. Handles HTTP 429, respects Retry-After header, configurable maxRetries (default 3) and baseRetryDelay (default 1s), context cancellation aware. Includes 7 new tests. Ready for review.
Author
Owner

Closed by PR #145 (merged). Rate-limit retry/backoff handling is now in master.

Closed by PR #145 (merged). Rate-limit retry/backoff handling is now in master.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/gitea-mobile#132