Skip to content

[data] Make iterate_with_retry more descriptive when throwing exceptions - #66033

Merged
goutamvenkat-anyscale merged 12 commits into
masterfrom
jhsu/clearer-retry-error-message-thrown
Sep 16, 2026
Merged

goutamvenkat-anyscale merged 12 commits into
masterfrom
jhsu/clearer-retry-error-message-thrown

Conversation

@iamjustinhsu

@iamjustinhsu iamjustinhsu commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

Sometimes when writing to s3 using pyarrow file system, the error can be mysterious:

"AWS Error ACCESS_DENIED during HeadBucket"

So to make this more transparent, i decided to special case on ACCESS_DENIED so that we can inform the user how to handle this in iterate_with_retry. See unit test for example

I avoided modifying call_with_retry because
a) it's in a generic utility (so other libraries may want to handle it differently)
b) there is no existing way to modify the # of retries with call_with_retry in Ray Data, but we can modify the # of retries with iterate_with_retry

While i can circumvent a) and b), i don't think it's worth effort

Related issues

Additional information

@iamjustinhsu
iamjustinhsu requested a review from a team as a code owner September 9, 2026 20:30

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a helper function _annotate_exception_with_retry_context to append retry context and helpful S3 permission hints to exceptions raised during iterate_with_retry, along with corresponding unit tests. The review feedback is highly constructive and identifies several key improvements: correcting a bug where the attempt count is incorrectly reset to 1 on non-retryable errors, updating the test assertions accordingly, wrapping the modification of exc.args in a try...except block to prevent secondary exceptions from masking the original error, and pointing out that call_with_retry should also be annotated to fully satisfy the PR's objective for S3 write operations.

Comment thread python/ray/data/_internal/util.py Resolved
Comment thread python/ray/data/_internal/util.py Resolved
Comment thread python/ray/data/tests/test_util.py Resolved
Comment thread python/ray/data/_internal/util.py Resolved
Signed-off-by: iamjustinhsu <[email protected]>
@iamjustinhsu iamjustinhsu changed the title [data] Make call_with_retry more descriptive when throwing exceptions [data] Make iterate_with_retry more descriptive when throwing exceptions Sep 9, 2026
Signed-off-by: iamjustinhsu <[email protected]>
Signed-off-by: iamjustinhsu <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread python/ray/data/_internal/util.py Resolved
Signed-off-by: iamjustinhsu <[email protected]>
Signed-off-by: iamjustinhsu <[email protected]>
@ray-gardener ray-gardener Bot added the data Ray Data-related issues label Sep 10, 2026

@ayushk7102 ayushk7102 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Implementation looks good to me, but I had minor nits about if this warning is showing up when users have set retried_map_errors or not, and how we handle concatting the warning with the actual exception message

Comment on lines 1558 to 1566
def iterate_with_retry(
iterable_factory: Callable[[], Iterable],
description: str,
*,
match: Optional[List[str]] = None,
max_attempts: int = 10,
max_backoff_s: int = 32,
unwrap_cause: bool = False,
) -> Any:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

iterate_with_retry is called from _map_task only if retried_map_errors is truthy (it's false by default). If we want to advise users to configure retried_map_errors we will not be able to do so unless they actually set it to True or any retryable errors, which seems unintuitive. Is there a way for us warn users if they have NOT set this param?

)
try:
if exc.args and isinstance(exc.args[0], str):
exc.args = (f"{exc.args[0]}\n{suffix}",) + exc.args[1:]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: this might lead to unexpected results when the specific exception type has some reserved order of the args tuple.

For example, from the BaseException docs section about args: OSError expects a certain number of arguments and assigns a special meaning to the elements of this tuple.

Signed-off-by: iamjustinhsu <[email protected]>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread python/ray/data/context.py Resolved
Signed-off-by: iamjustinhsu <[email protected]>
@iamjustinhsu
iamjustinhsu force-pushed the jhsu/clearer-retry-error-message-thrown branch from 73c30a1 to 25e930e Compare September 14, 2026 18:55

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 25e930e. Configure here.

Signed-off-by: iamjustinhsu <[email protected]>
@iamjustinhsu iamjustinhsu added the go add ONLY when ready to merge, run all tests label Sep 14, 2026
Signed-off-by: iamjustinhsu <[email protected]>
Signed-off-by: iamjustinhsu <[email protected]>
@goutamvenkat-anyscale
goutamvenkat-anyscale merged commit cd7c819 into master Sep 16, 2026
6 checks passed
@goutamvenkat-anyscale
goutamvenkat-anyscale deleted the jhsu/clearer-retry-error-message-thrown branch September 16, 2026 22:05
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…ons (ray-project#66033)

## Description
Sometimes when writing to s3 using pyarrow file system, the error can be
mysterious:

"AWS Error ACCESS_DENIED during HeadBucket"

So to make this more transparent, i decided to special case on
ACCESS_DENIED so that we can inform the user how to handle this in
`iterate_with_retry`. See unit test for example

I avoided modifying `call_with_retry` because 
a) it's in a generic utility (so other libraries may want to handle it
differently)
b) there is no existing way to modify the # of retries with
`call_with_retry` in Ray Data, but we can modify the # of retries with
`iterate_with_retry`

While i can circumvent a) and b), i don't think it's worth effort

## Related issues

## Additional information

---------

Signed-off-by: iamjustinhsu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data Ray Data-related issues go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants