fix: apply redirect response rate-limit headers to the request that produced them - #1159
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
…roduced them 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/1789429753-limiter-redirect-policy#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/1789429753-limiter-redirect-policyPR 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:53
Copilot started reviewing on behalf of
Airbyte Support Bot (airbyte-support-bot)
September 14, 2026 23:53
View session
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved review issues were identified.
Pull request overview
Fixes rate-limit accounting for redirected HTTP requests by associating each response with the request that produced it.
Changes:
- Corrects redirect response-to-request budget updates.
- Adds coverage for separate/shared policies and non-redirected requests.
File summaries
| File | Summary |
|---|---|
unit_tests/sources/streams/test_call_rate.py |
Adds redirect behavior tests. |
airbyte_cdk/sources/streams/call_rate.py |
Corrects rate-limit response pairing. |
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: When an API call is redirected, the rate-limit headers from the redirect target were being applied to the original endpoint's rate-limit policy, so the wrong endpoint could be marked as exhausted.
Specifically,
LimiterMixin.sendnow pairsrequestwithresponse.history[0](the response it actually produced) instead of the final response of the redirect chain when callingHttpAPIBudget.update_from_response.Resolves https://github.com/airbytehq/airbyte-internal-issues/issues/17249:
Changes
LimiterMixin.send: update the budget from the first response in the chain (response.history[0]when redirects were followed, elseresponse). Each redirect hop already passes throughsend(..., allow_redirects=False)and acquires/updates its own policy, so hop behavior is unchanged.TestLimiterSessionRedirectsinunit_tests/sources/streams/test_call_rate.py(mocksHTTPAdapter.sendsoLimiterMixin.sendis exercised): A→B redirect with separate policies (only B exhausted), A→B redirect with a shared policy (final headers win), and no-redirect (unchanged).Design notes
Show/Hide Content
requests.Session.sendresolves redirects viaself.send(hop_request, allow_redirects=False), so for a chain A→B the inner call pairs (B, B-response) correctly; the outer call previously paired (A, B-response). Usingresponse.history[0]gives the outer call A's own 302 response, whose headers are the ones that belong to A's policy. A response hook was considered but this is a smaller change with the same effect.response.historyis read viagetattr(..., [])because existing tests inunit_tests/sources/streams/http/test_http.pyinjectMock(spec=requests.Response)objects, which lack the instance-levelhistoryattribute.Test plan
poetry run pytest unit_tests/sources/streams/test_call_rate.py -q— 41 passedtest_redirect_updates_only_target_policyfails withCallRateLimitHiton A when thecall_rate.pychange is revertedpoetry run pytest unit_tests/sources/streams/http -q— 466 passedpoetry run ruff check .,poetry run ruff format --check .,poetry run mypy --config-file mypy.ini airbyte_cdk/sources/streams/call_rate.py— cleanRequested via
/ai-fixon the linked issue.Link to Devin session: https://app.devin.ai/sessions/72d637a3822e4b93b3f4381b84739fa4
Open in Devin Desktop: https://app.devin.ai/desktop/session/72d637a3822e4b93b3f4381b84739fa4?variant=devin