fix(cdk): retry async job download on HTTP 403 with fresh polling URL#959
Draft
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Draft
fix(cdk): retry async job download on HTTP 403 with fresh polling URL#959devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
Conversation
When downloading async job results (e.g., Bing Ads reports), the download URL may contain a time-limited SAS token that expires before the download starts. This causes an HTTP 403 that the CDK misclassifies as config_error, preventing retries and killing all running jobs. This change adds retry logic to AsyncHttpJobRepository.fetch_records that: 1. Catches HTTP 403 errors during the download phase 2. Re-polls the polling endpoint to obtain a fresh download URL 3. Retries the download with the new URL Resolves airbytehq/airbyte-internal-issues#16096 Related to airbytehq/oncall#11749 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/1774342850-fix-async-download-403-retry#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/1774342850-fix-async-download-403-retryPR Slash CommandsAirbyte Maintainers can execute the following slash commands on your PR:
|
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.
Summary
When
AsyncHttpJobRepositorydownloads async job results (e.g., Bing Ads reports via Azure Blob Storage), the download URL may contain a time-limited SAS token that expires before the download starts. This causes an HTTP 403 that the CDK currently treats as a fatalconfig_error, killing all running jobs for the stream.This PR adds retry logic to
fetch_records(): when a download fails with HTTP 403, it re-polls the polling endpoint to obtain a fresh download URL and retries the full download. The retry is limited to 1 attempt (_MAX_DOWNLOAD_RETRIES = 1).Changes:
fetch_records()into_download_records_for_job()(pure refactor of existing code)fetch_records()now wraps the download call in a retry loop that catchesAirbyteTracedExceptioncontaining"status code '403'"ininternal_message_is_retriable_download_error()— string-matches on the CDK's internal error message format_refresh_polling_response()— re-polls the polling endpoint and updates the cached responseResolves https://github.com/airbytehq/airbyte-internal-issues/issues/16096
Related to https://github.com/airbytehq/oncall/issues/11749
Review & Testing Checklist for Human
yield from self._download_records_for_job(job)will re-yield records from earlier targets that already succeeded. Verify whether this causes duplicate records downstream or if the platform deduplicates. This is the highest-risk item._is_retriable_download_errorchecks for"status code '403'"ininternal_message. Confirm this matches the exact string produced byHttpClient._handle_error_resolution()/DefaultErrorHandler. If the format changes, the retry silently stops working.yield frominside atry/exceptinside aforloop behaves correctly — specifically that theexceptfires if the inner generator raises mid-iteration.Notes
default_error_mapping.pyis not changed in this PR. The fix addresses the root cause (expired download URL) rather than just improving the error string._MAX_DOWNLOAD_RETRIES = 1means at most 2 total attempts (1 original + 1 retry). This is intentionally conservative.ruff formatand are unrelated to the functional change.Link to Devin session: https://app.devin.ai/sessions/9df259ec2e4f40f5a10f4b86151705f1