add timeout to env for sampling messages#8
Conversation
Summary of ChangesHello @Royal-lobster, 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 enhances the message sampling functionality by introducing configurable timeouts for both generating responses and sending reactions. By exposing these timeout settings as environment variables, the system gains greater flexibility and control over the duration of these operations, which can help prevent indefinite waits and improve overall responsiveness. Highlights
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 configurable timeouts for sampling requests, which is a good improvement for robustness. I've identified a few areas for improvement in the configuration handling to enhance consistency and prevent potential issues with hanging requests. I've also noted a point of redundancy in the timeout logic that could be simplified.
| SAMPLING_DEFAULT_TIMEOUT: z | ||
| .number() | ||
| .optional() | ||
| .describe('A timeout (in milliseconds) for this request'), | ||
| SAMPLING_REACTION_TIMEOUT: z | ||
| .number() | ||
| .optional() | ||
| .describe('A timeout for sending reactions to discord'), |
There was a problem hiding this comment.
These new timeout configurations could be improved for robustness and clarity.
- Missing Defaults:
SAMPLING_DEFAULT_TIMEOUTandSAMPLING_REACTION_TIMEOUTare optional but lack default values. If not set, they will beundefined, which could lead to requests hanging if the underlying SDK has no default timeout. This is particularly risky forSAMPLING_DEFAULT_TIMEOUTas there's no other timeout mechanism for the main message sampling. - Misleading Description: The description for
SAMPLING_REACTION_TIMEOUTis inaccurate. It's a timeout for the sampling request, not for sending the reaction to Discord.
I suggest adding default values and correcting the description to address these points.
SAMPLING_DEFAULT_TIMEOUT: z
.number()
.optional()
.default(30000) // 30 seconds
.describe('A timeout (in milliseconds) for this request'),
SAMPLING_REACTION_TIMEOUT: z
.number()
.optional()
.default(3000) // Align with REACTION_TIMEOUT_MS
.describe('A timeout (in milliseconds) for the reaction sampling request'),| SAMPLING_DEFAULT_TIMEOUT: z | ||
| .number() | ||
| .optional() | ||
| .describe('A timeout (in milliseconds) for this request'), | ||
| SAMPLING_REACTION_TIMEOUT: z | ||
| .number() | ||
| .optional() | ||
| .describe('A timeout for sending reactions to discord'), |
There was a problem hiding this comment.
For consistency with other configuration variables in this file (like DEFAULT_RATE_LIMIT_SECONDS which has a --rate-limit flag), consider adding command-line argument support for SAMPLING_DEFAULT_TIMEOUT and SAMPLING_REACTION_TIMEOUT. This would allow overriding them via CLI flags (e.g., --sampling-default-timeout and --sampling-reaction-timeout) in addition to environment variables. This change would need to be implemented in the getConfigFromArgs function.
| z.any(), | ||
| { | ||
| timeout: env.SAMPLING_REACTION_TIMEOUT, | ||
| } | ||
| ); |
There was a problem hiding this comment.
With the introduction of the timeout option in server.request using SAMPLING_REACTION_TIMEOUT, the existing client-side timeout using Promise.race and REACTION_TIMEOUT_MS in addDynamicReaction appears to be redundant. Having two timeout mechanisms for the same operation can be confusing and hard to maintain.
Consider refactoring to use only the SAMPLING_REACTION_TIMEOUT. This would simplify the code in addDynamicReaction by removing the Promise.race, and would also allow for removing the REACTION_TIMEOUT_MS configuration variable.
Changes