Skip to content

add timeout to env for sampling messages#8

Merged
Royal-lobster merged 1 commit into
mainfrom
fix-add-timeout-to-env-for-sampling-messages
Dec 11, 2025
Merged

add timeout to env for sampling messages#8
Royal-lobster merged 1 commit into
mainfrom
fix-add-timeout-to-env-for-sampling-messages

Conversation

@Royal-lobster

Copy link
Copy Markdown
Member

Changes

- Adds quick fix for: add timeout to env for sampling messages

@Royal-lobster
Royal-lobster merged commit 2b3ac73 into main Dec 11, 2025
1 check passed
@Royal-lobster
Royal-lobster deleted the fix-add-timeout-to-env-for-sampling-messages branch December 11, 2025 08:19
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @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

  • New Environment Variables: Introduced SAMPLING_DEFAULT_TIMEOUT and SAMPLING_REACTION_TIMEOUT in src/config.ts to allow configuration of timeouts for sampling operations.
  • Timeout Application for Reactions: Applied the SAMPLING_REACTION_TIMEOUT to the reaction sending logic within src/sampling.ts.
  • Timeout Application for Responses: Applied the SAMPLING_DEFAULT_TIMEOUT to the message response generation logic within src/sampling.ts.
  • Changelog Entry: Added a changeset entry documenting the addition of these timeout settings for a patch release.
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.

@gemini-code-assist gemini-code-assist 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.

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.

Comment thread src/config.ts
Comment on lines +35 to +42
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'),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

These new timeout configurations could be improved for robustness and clarity.

  1. Missing Defaults: SAMPLING_DEFAULT_TIMEOUT and SAMPLING_REACTION_TIMEOUT are optional but lack default values. If not set, they will be undefined, which could lead to requests hanging if the underlying SDK has no default timeout. This is particularly risky for SAMPLING_DEFAULT_TIMEOUT as there's no other timeout mechanism for the main message sampling.
  2. Misleading Description: The description for SAMPLING_REACTION_TIMEOUT is 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'),

Comment thread src/config.ts
Comment on lines +35 to +42
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'),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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.

Comment thread src/sampling.ts
Comment on lines +190 to 194
z.any(),
{
timeout: env.SAMPLING_REACTION_TIMEOUT,
}
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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.

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.

1 participant