Skip to content

Conversation

@JacobCoffee
Copy link
Owner

Summary

Implements Phase 3.2 from PLAN.md - adds robust retry logic with exponential backoff to the API client.

Changes

  • Add tenacity library for retry logic
  • Implement exponential backoff with jitter for HTTP requests
  • Retry on HTTP 5xx errors and connection failures
  • Re-raise original exceptions after retries exhausted
  • Add comprehensive tests for retry behavior
  • Document retry configuration

Test Coverage

  • 1059 tests passing
  • 91.36% coverage
  • All retry scenarios tested (transient failures, permanent failures, success after retry)

Implementation Details

  • Max 3 retry attempts
  • Exponential backoff: 1s, 2s, 4s
  • Retries HTTP 500-599 and connection errors
  • Preserves original exception types for caller handling

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

JacobCoffee and others added 6 commits November 23, 2025 18:14
Add tenacity>=8.2.0 to bot service dependencies to enable
retry logic with exponential backoff for API client.

Part of Phase 3.2 - Retry Logic & Circuit Breakers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add tenacity-based retry decorators to all API client methods:
- Retry on HTTP 5xx errors and connection errors
- No retry on HTTP 4xx (client errors)
- Max 3 attempts with exponential backoff (1s, 2s, 4s, max 10s)
- Retry statistics tracking per method with TypedDict
- Logging before each retry attempt

Methods with retry logic:
- create_guild
- get_guild
- update_guild
- delete_guild
- health_check

Part of Phase 3.2 - Retry Logic & Circuit Breakers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add 25+ test cases covering:
- Retry on HTTP 5xx errors (500, 502, 503)
- No retry on HTTP 4xx errors (400, 404)
- Retry on connection errors (ConnectError, ConnectTimeout, ReadTimeout)
- Max retry attempts (3 attempts)
- Retry statistics tracking across methods
- Exponential backoff timing verification
- Composite method retry behavior (get_or_create_guild)

Test coverage:
- create_guild retry behavior
- get_guild retry behavior
- update_guild retry behavior
- delete_guild retry behavior
- health_check retry behavior
- Retry statistics initialization and tracking
- Failed request tracking (4xx errors)

Part of Phase 3.2 - Retry Logic & Circuit Breakers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive documentation for retry behavior:
- Configuration (max retries, backoff, timeouts)
- Retryable vs non-retryable errors
- Retry statistics tracking
- Logging behavior
- Example usage

Updated Status section to reflect Phase 3.2 completion.

Part of Phase 3.2 - Retry Logic & Circuit Breakers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fixed retry logic to properly re-raise original httpx exceptions
(HTTPStatusError, RequestError) when retries should occur, allowing
tenacity to handle the retry logic.

Changes:
- Re-raise original exception when _should_retry() returns True
- Only convert to APIError for non-retryable errors (4xx)
- Updated test to expect HTTPStatusError after max retries exhausted
- All 17 retry tests now pass

This ensures tenacity can properly retry requests while still tracking
statistics and converting non-retryable errors to APIError.

Part of Phase 3.2 - Retry Logic & Circuit Breakers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Updated existing API client tests to expect original httpx exceptions
(HTTPStatusError, ConnectError, TimeoutException) instead of APIError
when retryable errors occur, aligning with the new retry logic behavior.

Changes:
- test_create_guild_server_error: expect HTTPStatusError
- test_create_guild_connection_error: expect ConnectError
- test_create_guild_timeout: expect TimeoutException
- test_get_guild_server_error: expect HTTPStatusError
- test_get_guild_connection_error: expect ConnectError
- test_update_guild_connection_error: expect ConnectError
- test_delete_guild_server_error: expect HTTPStatusError
- test_delete_guild_connection_error: expect ConnectError
- test_health_check_unhealthy: expect HTTPStatusError
- test_health_check_connection_error: expect ConnectError
- test_health_check_timeout: expect TimeoutException

All tests document retry-then-fail behavior in docstrings.

Part of Phase 3.2 - Retry Logic & Circuit Breakers.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@railway-app
Copy link

railway-app bot commented Nov 24, 2025

🚅 Deployed to the byte-pr-133 environment in byte

Service Status Web Updated (UTC)
byte ◻️ Removed (View Logs) Web Nov 24, 2025 at 12:56 am

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Sorry @JacobCoffee, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@railway-app railway-app bot temporarily deployed to byte (byte / byte-pr-133) November 24, 2025 00:45 Destroyed
- Combine retry logic with correlation ID tracking from main
- Keep both RetryStats tracking and X-Correlation-ID headers
- Preserve all retry decorators and exponential backoff logic

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@railway-app railway-app bot temporarily deployed to byte (byte / byte-pr-133) November 24, 2025 00:51 Destroyed
@github-actions
Copy link

Documentation preview will be available shortly at https://jacobcoffee.github.io/byte-docs-preview/133

@JacobCoffee JacobCoffee merged commit 51e4c74 into main Nov 24, 2025
4 of 5 checks passed
@JacobCoffee JacobCoffee deleted the feature/phase3.2-retry-logic branch November 24, 2025 00:56
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.

2 participants