Skip to content

fix(cdk): improve rate limiting error messages to suggest reducing num_workers#949

Open
sophiecuiy wants to merge 4 commits intomainfrom
devin/1773181449-improve-rate-limit-error-messaging
Open

fix(cdk): improve rate limiting error messages to suggest reducing num_workers#949
sophiecuiy wants to merge 4 commits intomainfrom
devin/1773181449-improve-rate-limit-error-messaging

Conversation

@sophiecuiy
Copy link
Contributor

@sophiecuiy sophiecuiy commented Mar 10, 2026

fix(cdk): improve rate limiting error messages to suggest reducing num_workers

Summary

Improves error messaging across the CDK's HTTP rate limiting pipeline so that users encountering 429 errors receive actionable guidance to reduce the number of workers.

Three source files changed:

  1. default_error_mapping.py — Updated the default 429 error message from "HTTP Status Code: 429. Error: Too many requests." to "Rate limit exceeded (HTTP status code 429). Try decreasing the number of workers to stay within API rate limits."
  2. http_client.py — Added a dedicated RateLimitBackoffException branch in _send_with_retry that surfaces a rate-limit-specific message when retries are exhausted (applies when exit_on_rate_limit=False, i.e. the "retry endlessly" path). Also removed "Please see logs for more details." from the generic exhaustion message.
  3. rate_limiting.py — Updated the retry log message in rate_limit_default_backoff_handler to explicitly mention rate limiting and the num_workers guidance, while preserving the original exception text (Last error: {str(exc)}) for debug context.

Updates since last revision

  • Per feedback, kept the HTTP status code reference in the 429 error message (now reads "Rate limit exceeded (HTTP status code 429). ..." instead of dropping the status code entirely).
  • Simplified guidance to reference only "the number of workers" (removed "concurrency" since num_workers is the standard user-configurable field name).
  • Addressed Copilot review feedback:
    • Restored str(exc) in the rate-limit retry log line so underlying error details are preserved alongside the new guidance.
    • Updated the exit_on_rate_limit=True test assertion to verify the full message including the "Exhausted available request attempts. Exception: ..." prefix, ensuring both the generic exhaustion wrapper and the new 429 mapping text are covered by tests.

Review & Testing Checklist for Human

  • Verify no downstream connectors pattern-match on the old 429 string ("HTTP Status Code: 429. Error: Too many requests."). The default_error_mapping change affects all connectors using the default error handler. Search the airbyte monorepo for any code that matches against this exact string.
  • Check the generic exhaustion message change: The non-rate-limit path in _send_with_retry now says "Exhausted available request attempts. Exception: {e}" instead of "Exhausted available request attempts. Please see logs for more details. Exception: {e}". This affects ALL non-rate-limit backoff failures — confirm this is acceptable.
  • Verify the exit_on_rate_limit=True path: When exit_on_rate_limit=True, 429s follow the DefaultBackoffException path (not RateLimitBackoffException), so the new dedicated branch in _send_with_retry does NOT fire. The improved message still reaches the user via the exception string from the updated 429 mapping, but the user-facing message field on AirbyteTracedException will show the generic exhaustion text wrapping the new 429 text. The test now verifies this full combined string.
  • Confirm "number of workers" is the right terminology for all user-facing contexts (Cloud, OSS, declarative connectors). The CDK schema uses num_workers as an example config key; verify this is the standard term users would recognize.

Suggested manual test plan: Trigger a 429 response in a connector using the default error handler (e.g., source-pokeapi with aggressive concurrency) and confirm the new error message appears in both logs and the traced exception output.

Notes

Requested by sophiecuiy

Devin session

Summary by CodeRabbit

Release Notes

  • Improvements
    • Enhanced HTTP 429 rate limit error messages with clearer guidance on reducing worker count to stay within API limits
    • Improved retry attempt logging with more detailed rate limit information to help diagnose and resolve issues faster

…ncurrency or workers

Co-Authored-By: sophie.cui@airbyte.io <sophie.cui@airbyte.io>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@github-actions
Copy link

👋 Greetings, Airbyte Team Member!

Here are some helpful tips and reminders for your convenience.

💡 Show Tips and Tricks

Testing This CDK Version

You can test this version of the CDK using the following:

# Run the CLI from this branch:
uvx 'git+https://github.com/airbytehq/airbyte-python-cdk.git@devin/1773181449-improve-rate-limit-error-messaging#egg=airbyte-python-cdk[dev]' --help

# Update a connector to use the CDK from this branch ref:
cd airbyte-integrations/connectors/source-example
poe use-cdk-branch devin/1773181449-improve-rate-limit-error-messaging

PR Slash Commands

Airbyte Maintainers can execute the following slash commands on your PR:

  • /autofix - Fixes most formatting and linting issues
  • /poetry-lock - Updates poetry.lock file
  • /test - Runs connector tests with the updated CDK
  • /prerelease - Triggers a prerelease publish with default arguments
  • /poe build - Regenerate git-committed build artifacts, such as the pydantic models which are generated from the manifest JSON schema in YAML.
  • /poe <command> - Runs any poe command in the CDK environment
📚 Show Repo Guidance

Helpful Resources

📝 Edit this welcome message.

Co-Authored-By: sophie.cui@airbyte.io <sophie.cui@airbyte.io>
@github-actions
Copy link

github-actions bot commented Mar 10, 2026

PyTest Results (Fast)

3 914 tests  +9   3 902 ✅ +9   6m 52s ⏱️ +35s
    1 suites ±0      12 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 7301186. ± Comparison against base commit 3e65ad5.

♻️ This comment has been updated with latest results.

…P status code

Co-Authored-By: sophie.cui@airbyte.io <sophie.cui@airbyte.io>
@devin-ai-integration devin-ai-integration bot changed the title fix(cdk): improve rate limiting error messages to suggest reducing concurrency or workers fix(cdk): improve rate limiting error messages to suggest reducing num_workers Mar 10, 2026
@github-actions
Copy link

github-actions bot commented Mar 10, 2026

PyTest Results (Full)

3 917 tests  +9   3 905 ✅ +9   11m 13s ⏱️ +3s
    1 suites ±0      12 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 7301186. ± Comparison against base commit 3e65ad5.

♻️ This comment has been updated with latest results.

@sophiecuiy sophiecuiy marked this pull request as ready for review March 11, 2026 16:36
Copilot AI review requested due to automatic review settings March 11, 2026 16:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates CDK rate limiting messaging so users hitting HTTP 429 get actionable guidance to reduce num_workers, and adds a rate-limit-specific failure path when rate-limit retries are exhausted.

Changes:

  • Updated the default 429 error mapping message to include explicit “reduce number of workers” guidance.
  • Added a dedicated RateLimitBackoffException handling branch in HttpClient._send_with_retry with a rate-limit-specific user message, and simplified the generic retry-exhaustion message.
  • Updated rate-limit retry logging to explicitly mention rate limiting and recommend reducing workers.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
airbyte_cdk/sources/streams/http/error_handlers/default_error_mapping.py Updates the default 429 mapped message to include actionable worker guidance.
airbyte_cdk/sources/streams/http/http_client.py Adds rate-limit-specific traced exception messaging when RateLimitBackoffException exhausts and adjusts generic exhaustion text.
airbyte_cdk/sources/streams/http/rate_limiting.py Changes backoff retry log line to explicitly call out rate limits and num_workers guidance.
unit_tests/sources/streams/http/test_http.py Updates assertions to match the new 429 message.
unit_tests/sources/declarative/requesters/error_handlers/test_http_response_filter.py Updates expected 429 error message string for declarative error handling tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

logger.info(
f"Caught retryable error '{str(exc)}' after {details['tries']} tries. Waiting {details['wait']} seconds then retrying..."
f"Rate limit hit after {details['tries']} tries. Waiting {details['wait']} seconds then retrying. "
f"Try decreasing the number of workers to stay within API rate limits."
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

The new retry log message no longer includes the underlying exception text (previously str(exc)), which can remove useful context like the request URL / error details when diagnosing repeated 429s. Consider appending str(exc) (or key fields like request URL) to this log line while keeping the actionable guidance.

Suggested change
f"Try decreasing the number of workers to stay within API rate limits."
f"Try decreasing the number of workers to stay within API rate limits. "
f"Last error: {str(exc)}"

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch — restored str(exc) as Last error: {str(exc)} in the log line so debug context is preserved alongside the new guidance. Fixed in 7301186.


Devin session

Comment on lines 318 to 323
with pytest.raises(
AirbyteTracedException,
match="Exhausted available request attempts. Please see logs for more details. Exception: HTTP Status Code: 429. Error: Too many requests.",
match="Rate limit exceeded \\(HTTP status code 429\\). Try decreasing the number of workers to stay within API rate limits.",
):
stream.exit_on_rate_limit = True
list(stream.read_records(SyncMode.full_refresh))
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

This assertion used to verify the full "Exhausted available request attempts..." message (including the removed "Please see logs for more details." text). With the updated regex only matching the 429 mapping string, the change in HttpClient._send_with_retry’s generic exhaustion message is no longer covered by tests. Consider adding/adjusting an assertion to explicitly check the new exhaustion message (or at least ensure the old "Please see logs" text is absent).

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Good point — updated the test to assert the full "Exhausted available request attempts. Exception: Rate limit exceeded (HTTP status code 429). Try decreasing the number of workers to stay within API rate limits." message, which verifies both the generic exhaustion prefix and the new 429 mapping text. Fixed in 7301186.


Devin session

…erage per review

Co-Authored-By: sophie.cui@airbyte.io <sophie.cui@airbyte.io>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3ca923a2-c60a-445e-8fd1-90db99041211

📥 Commits

Reviewing files that changed from the base of the PR and between 3e65ad5 and 7301186.

📒 Files selected for processing (5)
  • airbyte_cdk/sources/streams/http/error_handlers/default_error_mapping.py
  • airbyte_cdk/sources/streams/http/http_client.py
  • airbyte_cdk/sources/streams/http/rate_limiting.py
  • unit_tests/sources/declarative/requesters/error_handlers/test_http_response_filter.py
  • unit_tests/sources/streams/http/test_http.py

📝 Walkthrough

Walkthrough

This PR improves HTTP 429 rate limit error messaging and handling across the Airyte CDK HTTP client stack. It replaces generic rate limit messages with more descriptive guidance suggesting users reduce worker count, implements specialized exception handling for rate limit errors, and updates corresponding test expectations.

Changes

Cohort / File(s) Summary
Rate Limit Error Messaging
airbyte_cdk/sources/streams/http/error_handlers/default_error_mapping.py, airbyte_cdk/sources/streams/http/rate_limiting.py
Updated HTTP 429 error messages in default mapping and retry logging to provide more actionable guidance about reducing worker count to stay within API rate limits.
Rate Limit Exception Handling
airbyte_cdk/sources/streams/http/http_client.py
Added specialized catch path for RateLimitBackoffException with rate-limit-specific logging and exception raising; retained existing path for other backoff exceptions with updated message text.
Test Assertions
unit_tests/sources/declarative/requesters/error_handlers/test_http_response_filter.py, unit_tests/sources/streams/http/test_http.py
Updated expected error message assertions in rate limit test cases to match new descriptive rate limit messaging.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main objective of the changeset: improving rate limiting error messages to suggest reducing the num_workers parameter.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/1773181449-improve-rate-limit-error-messaging

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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