feat(generator): add hub parity retry/timeout policies to giskard agents library#101
Conversation
Add max_delay field to RetryPolicy to cap exponential backoff delays. When max_delay is set, exponential backoff wait times are capped at the specified value. Falls back to MAX_WAIT_SECONDS when max_delay is None to maintain backward compatibility. - Add max_delay field to RetryPolicy model - Add MAX_WAIT_SECONDS constant for default max wait time - Update exponential backoff to respect max_delay - Add comprehensive tests for max_delay behavior
Add timeout parameter to GenerationParams to support timeout configuration for completion requests. This enables hub parity for retry timeout policy in the giskard agents library. - Add timeout field to GenerationParams with optional float/int type - Add test case to verify timeout parameter is preserved in generator params
Summary of ChangesHello @kevinmessiaen, 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 enhances the robustness of generator agents by implementing both timeout and advanced retry policies. The timeout feature allows users to define a maximum execution time for generation requests, preventing indefinite waits. The retry policy has been upgraded to include a maximum delay for exponential backoff, providing finer control over retry behavior and preventing excessively long delays. These additions ensure more reliable and predictable interactions with external services, improving the overall stability of the agents. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request adds retry and timeout policies to the LiteLLMGenerator, bringing it to parity with other components. The changes include adding timeout to GenerationParams, and max_delay to RetryPolicy. The implementation correctly uses tenacity for exponential backoff with a configurable max delay. The changes are well-tested, covering various scenarios for the retry logic. I've suggested a refactoring in the test suite to reduce code duplication and improve maintainability by using pytest.mark.parametrize.
| wait=t.wait_exponential(multiplier=self.retry_policy.base_delay), | ||
| wait=t.wait_exponential( | ||
| multiplier=self.retry_policy.base_delay, | ||
| max=self.retry_policy.max_delay or MAX_WAIT_SECONDS, |
There was a problem hiding this comment.
Falsy max_delay value incorrectly treated as unset
Low Severity
The expression self.retry_policy.max_delay or MAX_WAIT_SECONDS uses Python's truthiness evaluation, meaning if max_delay is explicitly set to 0 (a valid float), it will be treated as falsy and replaced with MAX_WAIT_SECONDS. Since max_delay is typed as float | None, setting it to 0 is valid and could be desired for testing scenarios with immediate retries. This would silently result in effectively unlimited wait times instead of zero delay.
There was a problem hiding this comment.
should we allow 0 as max_delay, here it will be changed to MAX_WAIT_SECONDS silently
Document retry policy behavior, no nested retries, and how per-call params override generator defaults.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
|
|
||
| def _tenacity_retry_condition(self, retry_state: t.RetryCallState) -> bool: | ||
| return self._should_retry(retry_state.outcome.exception()) | ||
|
|
There was a problem hiding this comment.
Retry condition passes None to exception handler
Medium Severity
The _tenacity_retry_condition method unconditionally calls self._should_retry(retry_state.outcome.exception()) without first checking if the attempt failed. When the request succeeds, outcome.exception() returns None, but _should_retry is documented and type-hinted to receive an Exception. This can cause crashes in custom generator implementations that don't defensively handle None. The method needs to check retry_state.outcome.failed() before accessing the exception.
| patch = { | ||
| "max_retries": max_retries, | ||
| "base_delay": base_delay, | ||
| "max_delay": max_delay, |
There was a problem hiding this comment.
how about validating the numbers here?
e.g., "max_delay": max(0, max_delay), so that we do not have a negative value
|
Changes integrated to Giskard-AI/giskard-oss#2239 |


Retry policy:
Max timeout:
Note, max timeout is considered a completion param by LiteLLM, therefore we follow the same pattern:
Writing custom Generator with above patterns:
Note
Medium Risk
Touches core generator completion/retry behavior and changes backoff timing semantics; risk is mainly behavioral (timeouts/backoff caps) rather than data/security-related.
Overview
Adds a new
timeoutfield toGenerationParamsand clarifies/standardizes the contract that per-callcomplete(..., params=...)values override generator defaults while tools may be merged.Enhances
WithRetryPolicyby introducingRetryPolicy.max_delay(plus a sentinelMAX_WAIT_SECONDS), capping Tenacity exponential backoff, improvingwith_retries()to patch/retain existing policy values, and adding an overridable_tenacity_before_sleephook; tests are updated/expanded to assert correct param merging and retry sleep timings (including max-delay capping and exponential growth).Written by Cursor Bugbot for commit 987f07d. This will update automatically on new commits. Configure here.