Skip to content

feat(storage): adding more context to the custom should-retry method#13750

Merged
cpriti-os merged 6 commits intogoogleapis:mainfrom
raj-prince:add_more_retry_ctx
Mar 17, 2026
Merged

feat(storage): adding more context to the custom should-retry method#13750
cpriti-os merged 6 commits intogoogleapis:mainfrom
raj-prince:add_more_retry_ctx

Conversation

@raj-prince
Copy link
Copy Markdown
Contributor

@raj-prince raj-prince commented Feb 2, 2026

Description:

  • Adding new interface for ShouldRetry method to get more context, like, attempt#, id, operation_name, object_name, bucket_name.
  • Marking the previous ErrorFun as deprecated to migrate on the new interface.
  • GCSFuse will use it for logging purpose - which will be helpful in connecting multiple retries for same overall request.

Test:

  • Unit test - passed.

@raj-prince raj-prince requested review from a team February 2, 2026 13:22
@raj-prince raj-prince requested a review from a team as a code owner February 2, 2026 13:22
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @raj-prince, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the flexibility of custom retry policies by introducing additional context to the WithErrorFunc. Users can now leverage the attempt number and a unique invocation ID to implement more intelligent retry strategies, while ensuring that existing implementations using the simpler function signature remain fully functional. The changes involve updating the WithErrorFunc to dynamically handle different function signatures and propagating the new contextual information throughout the retry invocation paths.

Highlights

  • Enhanced Custom Retry Logic: The WithErrorFunc now allows users to define custom retry logic with more context, specifically providing the currentAttempt number and a unique invocationID to the shouldRetry function. This enables more sophisticated and granular control over retry decisions.
  • Backward Compatibility: The WithErrorFunc automatically detects whether the provided custom retry function uses the new signature (func(error, int, string) bool) or the legacy signature (func(error) bool). If the legacy signature is used, it is automatically wrapped to maintain backward compatibility without requiring users to update existing code.
  • Internal Adaptations: Internal retry mechanisms across gRPC and HTTP clients have been updated to pass the new currentAttempt and invocationID parameters to the runShouldRetry method. For external libraries that only accept the legacy func(error) bool signature, an adapter is used to call the new function with default values for the new parameters.
  • New Test Coverage and Example: A new test file (backward_compat_test.go) has been added to explicitly verify the backward compatibility of WithErrorFunc. An example (example_test.go) has also been included to demonstrate the usage of the enhanced WithErrorFunc with the new contextual parameters.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

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

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 enhances the retry mechanism by allowing the custom shouldRetry function to receive more context, namely the current attempt number and a unique invocation ID. This is a valuable addition for users who need more sophisticated retry logic. The implementation is backward-compatible, gracefully handling both the old and new function signatures. The changes are well-tested, including new unit tests for backward compatibility.

My review focuses on a few places where the new context (currentAttempt, invocationID) is not fully available, specifically in the context of streaming gRPC calls. I've suggested improvements to provide more accurate information to the user's retry function in these cases, or at least document the limitations. Overall, this is a solid feature addition.

Comment thread storage/grpc_client.go Outdated
Comment thread storage/grpc_reader.go Outdated
Comment thread storage/grpc_reader_multi_range.go Outdated
Comment thread storage/storage.go Outdated
@raj-prince raj-prince changed the title feat(retry): adding more context to the custom should-retry method [Don't review] feat(retry): adding more context to the custom should-retry method Feb 2, 2026
@raj-prince raj-prince changed the title [Don't review] feat(retry): adding more context to the custom should-retry method feat(retry): adding more context to the custom should-retry method Feb 2, 2026
@raj-prince raj-prince requested a review from tritone February 2, 2026 17:05
Comment thread storage/client_test.go
Comment thread storage/grpc_client.go Outdated
Comment thread storage/storage.go
@raj-prince raj-prince requested review from a team as code owners February 23, 2026 15:51
@raj-prince raj-prince requested a review from meet2mky February 24, 2026 06:34
Comment thread storage/storage.go Outdated
Comment thread storage/storage.go Outdated
Comment thread storage/storage.go
Comment thread storage/storage_test.go Outdated
Comment thread storage/retry_context_test.go
Comment thread storage/invoke.go Outdated
Comment thread storage/invoke.go Outdated
Comment thread storage/invoke_test.go
Comment thread storage/integration_test.go Outdated
Comment thread storage/storage.go
@tritone tritone changed the title feat(retry): adding more context to the custom should-retry method feat(storage): adding more context to the custom should-retry method Feb 25, 2026
@krishnamd-jkp
Copy link
Copy Markdown
Contributor

Can you check the failing kokoro test?

Copy link
Copy Markdown
Contributor

@cpriti-os cpriti-os left a comment

Choose a reason for hiding this comment

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

Mostly looks good, added some nits and clarifications.

Comment thread storage/storage.go Outdated
Comment thread storage/storage_test.go
Comment thread storage/storage.go Outdated
@raj-prince raj-prince requested a review from cpriti-os March 14, 2026 11:27
Comment thread storage/example_test.go Outdated
Comment thread storage/example_test.go Outdated
Comment thread storage/grpc_client.go
Comment thread storage/invoke_test.go Outdated
Comment thread storage/invoke.go
Comment thread storage/storage.go
@raj-prince raj-prince requested a review from cpriti-os March 16, 2026 12:34
@cpriti-os cpriti-os merged commit 5aec566 into googleapis:main Mar 17, 2026
10 checks passed
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.

5 participants