fix: make APIBudget honor maximum_attempts_to_acquire exactly - #1157
Draft
devin-ai-integration[bot] wants to merge 1 commit into
Draft
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Co-Authored-By: bot_apk <apk@cognition.ai>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
👋 Greetings, Airbyte Team Member!Here are some helpful tips and reminders for your convenience. 💡 Show Tips and TricksTesting This CDK VersionYou 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/1789429689-call-rate-max-attempts#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/1789429689-call-rate-max-attemptsPR Slash CommandsAirbyte Maintainers can execute the following slash commands on your PR:
|
Airbyte Support Bot (airbyte-support-bot)
requested a lite review from Copilot
September 14, 2026 23:51
Copilot started reviewing on behalf of
Airbyte Support Bot (airbyte-support-bot)
September 14, 2026 23:52
View session
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved issues block approval.
Pull request overview
Updates APIBudget to honor configured retry counts, avoid unnecessary final sleeps, and reject invalid attempt values.
Changes:
- Corrects retry-loop counting and final-attempt behavior.
- Validates
maximum_attempts_to_acquire >= 1. - Adds focused tests for retries, exhaustion, and validation.
File summaries
| File | Description |
|---|---|
unit_tests/sources/streams/test_call_rate.py |
Adds coverage for maximum-attempt behavior. |
airbyte_cdk/sources/streams/call_rate.py |
Updates retry logic and input validation. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
👉 TL;DR: The rate limiter's retry loop made one fewer attempt than configured, so with a single allowed attempt it never checked the rate limit at all and let calls through even when the budget was exhausted. It also slept once more than necessary before giving up.
Specifically,
APIBudget._do_acquirenow iteratesrange(1, maximum_attempts_to_acquire + 1), breaks before sleeping on the final failed attempt, andAPIBudget.__init__rejectsmaximum_attempts_to_acquire < 1with aValueError.Resolves https://github.com/airbytehq/airbyte-internal-issues/issues/17247:
Part of epic https://github.com/airbytehq/airbyte-internal-issues/issues/17243.
Changes
APIBudget._do_acquire: loop boundrange(1, n)->range(1, n + 1)so exactlyntry_acquirecalls are made;breakafter the last failed attempt soblock=Trueno longer sleeps fortime_to_waitbefore raising.APIBudget.__init__: raiseValueErrorwhenmaximum_attempts_to_acquire < 1.TestAPIBudgetMaximumAttemptstests: exhausted policy +n=1raisesCallRateLimitHit(blocking and non-blocking);try_acquireis called exactlyntimes withn-1sleeps forn in {1, 2, 5}; values< 1rejected.Reproduction
Before the fix, with an exhausted
FixedWindowCallRatePolicy(call_limit=1):Risks
100000) is one extra attempt (100000 vs 99999); the only known external caller passing this argument issource-slack, which uses the default.Test plan
poetry run pytest unit_tests/sources/streams/test_call_rate.py -q(45 passed; the 3 newn>=2count tests fail onmainwithout the fix)poetry run ruff check .,poetry run ruff format --check .,poetry run mypy --config-file mypy.ini airbyte_cdk/sources/streams/call_rate.pyRequested via
/ai-fixon the linked issue (triage session: https://app.devin.ai/sessions/33bc7ef3d07c40578437ec2c41099b62).Link to Devin session: https://app.devin.ai/sessions/55032d81326149dcba6a546fb345a1d8
Open in Devin Desktop: https://app.devin.ai/desktop/session/55032d81326149dcba6a546fb345a1d8?variant=devin