Skip to content

Conversation

@swaroopAkkineniWorkos
Copy link

@swaroopAkkineniWorkos swaroopAkkineniWorkos commented Nov 18, 2025

Updating python library sdk to always generating an idempotencyKey if not present when POSTing audit-logs events.
Also updated to add retryability to endpoints. I set it up to not be enabled by default

- Add max_retries and auto_idempotency_keys config options
- Implement exponential backoff with jitter for retryable errors
- Auto-generate UUID v4 idempotency keys when not provided
- Retry on 5xx, 429, and network timeout errors
- Add retryable? method to WorkOSError
- Add comprehensive test coverage for retry and idempotency features
@linear
Copy link

linear bot commented Nov 18, 2025

swaroopakkineni added 9 commits November 18, 2025 07:06
- Remove auto_idempotency_keys config flag
- Always auto-generate idempotency keys when not provided
- Remove related test for disabled flag
- Set max_retries=3 in test setup since default is now 0
- Add after hook to reset config between tests
- Fix successful retry test to properly mock response headers
- Remove redundant manual reset calls in individual tests
- Add Metrics/PerceivedComplexity to existing rubocop:disable comment
- Remove trailing whitespace in client_retry_spec.rb

def initialize
@timeout = 60
@max_retries = 0

Choose a reason for hiding this comment

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

default to 0 retries

@swaroopAkkineniWorkos
Copy link
Author

/review

@swaroopAkkineniWorkos swaroopAkkineniWorkos marked this pull request as ready for review November 18, 2025 16:01
@swaroopAkkineniWorkos
Copy link
Author

@greptile review plz

@greptile-apps
Copy link

greptile-apps bot commented Nov 18, 2025

Greptile Summary

  • Adds automatic UUID generation for idempotency keys when not provided for audit log event creation
  • Implements retry logic with exponential backoff for 5xx, 408, and 429 HTTP errors with configurable max retries (defaults: 0 for general requests, 3 for audit logs)

Confidence Score: 5/5

  • This PR is safe to merge with no critical issues found
  • The implementation is well-designed with proper retry logic, comprehensive test coverage, and follows Ruby best practices. The retry mechanism correctly handles retryable errors with exponential backoff, reuses HTTP connections, and maintains idempotency across retries. All edge cases are tested.
  • No files require special attention

Important Files Changed

Filename Overview
lib/workos/audit_logs.rb Added auto-generation of idempotency keys using SecureRandom.uuid and configured retry logic to use audit_log_max_retries setting
lib/workos/client.rb Implemented retry logic with exponential backoff for 5xx, 408, and 429 errors, including support for Retry-After headers

Sequence Diagram

sequenceDiagram
    participant User
    participant AuditLogs
    participant Client
    participant API

    User->>AuditLogs: create_event(organization, event, idempotency_key)
    AuditLogs->>AuditLogs: Generate UUID if idempotency_key is nil
    AuditLogs->>Client: execute_request(request, retries: audit_log_max_retries)
    Client->>API: POST /audit_logs/events with Idempotency-Key
    
    alt Request succeeds (2xx)
        API-->>Client: 200/201 response
        Client-->>AuditLogs: response
        AuditLogs-->>User: response
    else Retryable error (5xx, 408, 429)
        API-->>Client: 500/503/408/429 response
        Client->>Client: Check attempt < retries
        Client->>Client: Calculate backoff delay
        Client->>Client: Sleep for delay
        Client->>Client: Increment attempt counter
        Client->>API: Retry POST with same Idempotency-Key
        
        alt Retry succeeds
            API-->>Client: 200/201 response
            Client-->>AuditLogs: response
            AuditLogs-->>User: response
        else Max retries exceeded
            API-->>Client: Still failing
            Client->>Client: Raise error (APIError/TimeoutError)
            Client-->>User: Error
        end
    else Non-retryable error (4xx)
        API-->>Client: 400/401/403/404 response
        Client->>Client: Raise error immediately
        Client-->>User: Error
    end
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

7 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format

@swaroopAkkineniWorkos
Copy link
Author

@greptile re-review plz

@swaroopAkkineniWorkos
Copy link
Author

@greptile re-review plz

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

7 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format

@swaroopAkkineniWorkos
Copy link
Author

@greptile re-review plz

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

7 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format

@swaroopAkkineniWorkos swaroopAkkineniWorkos marked this pull request as draft November 18, 2025 17:18
@swaroopAkkineniWorkos
Copy link
Author

@greptile re-review plz

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

7 files reviewed, no comments

Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format

@swaroopAkkineniWorkos
Copy link
Author

@greptile re-review plz

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

6 files reviewed, no comments

Edit Code Review Agent Settings | Greptile
React with 👍 or 👎 to share your feedback on this new summary format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants