Repository navigation
refactor(gateway): separate streaming and plain request timeouts #1590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,37 +16,77 @@ export function getGatewayTimeoutMs(): number { | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * Gets the AI API request timeout - the maximum time for upstream provider calls. | ||||||||||||||||||||||||||||||||||||||||
| * Gets the AI API request timeout for streaming requests - the maximum time for upstream provider calls. | ||||||||||||||||||||||||||||||||||||||||
| * Should be shorter than gateway timeout to allow for error handling. | ||||||||||||||||||||||||||||||||||||||||
| * Default: 4 minutes (240000ms) or 80% of gateway timeout, whichever is smaller | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| export function getAIRequestTimeoutMs(): number { | ||||||||||||||||||||||||||||||||||||||||
| const envValue = Number(process.env.AI_REQUEST_TIMEOUT_MS); | ||||||||||||||||||||||||||||||||||||||||
| export function getStreamingTimeoutMs(): number { | ||||||||||||||||||||||||||||||||||||||||
| const envValue = Number(process.env.AI_STREAMING_TIMEOUT_MS); | ||||||||||||||||||||||||||||||||||||||||
| if (envValue > 0) { | ||||||||||||||||||||||||||||||||||||||||
| return envValue; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| // Default: 4 minutes or 80% of gateway timeout, whichever is smaller | ||||||||||||||||||||||||||||||||||||||||
| return Math.min(240000, getGatewayTimeoutMs() * 0.8); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * Gets the AI API request timeout for non-streaming (plain) requests. | ||||||||||||||||||||||||||||||||||||||||
| * Non-streaming requests have a shorter default timeout since they don't benefit | ||||||||||||||||||||||||||||||||||||||||
| * from incremental responses and long waits are usually indicative of issues. | ||||||||||||||||||||||||||||||||||||||||
| * Default: 80 seconds (80000ms) | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| export function getTimeoutMs(): number { | ||||||||||||||||||||||||||||||||||||||||
| const envValue = Number(process.env.AI_TIMEOUT_MS); | ||||||||||||||||||||||||||||||||||||||||
| if (envValue > 0) { | ||||||||||||||||||||||||||||||||||||||||
| return envValue; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| // Default: 80 seconds for non-streaming requests | ||||||||||||||||||||||||||||||||||||||||
| return 80000; | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+36
to
+44
|
||||||||||||||||||||||||||||||||||||||||
| * Default: 80 seconds (80000ms) | |
| */ | |
| export function getTimeoutMs(): number { | |
| const envValue = Number(process.env.AI_TIMEOUT_MS); | |
| if (envValue > 0) { | |
| return envValue; | |
| } | |
| // Default: 80 seconds for non-streaming requests | |
| return 80000; | |
| * Default: 80 seconds (80000ms) or 80% of gateway timeout, whichever is smaller | |
| */ | |
| export function getTimeoutMs(): number { | |
| const envValue = Number(process.env.AI_TIMEOUT_MS); | |
| if (envValue > 0) { | |
| // Ensure configured timeout does not exceed a safe fraction of the gateway timeout | |
| return Math.min(envValue, getGatewayTimeoutMs() * 0.8); | |
| } | |
| // Default: 80 seconds or 80% of gateway timeout, whichever is smaller | |
| return Math.min(80000, getGatewayTimeoutMs() * 0.8); |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The export name AI_TIMEOUT_MS is ambiguous compared to AI_STREAMING_TIMEOUT_MS. It's not immediately clear that this constant is for non-streaming requests. While marked as legacy, maintaining clear naming even in backwards compatibility exports helps prevent confusion. Consider renaming to AI_PLAIN_TIMEOUT_MS or AI_NONSTREAMING_TIMEOUT_MS for consistency.
| export const AI_TIMEOUT_MS = getTimeoutMs(); | |
| export const AI_PLAIN_TIMEOUT_MS = getTimeoutMs(); | |
| // Legacy alias for non-streaming timeout; prefer AI_PLAIN_TIMEOUT_MS in new code. | |
| export const AI_TIMEOUT_MS = AI_PLAIN_TIMEOUT_MS; |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function name createTimeoutSignal() is too generic and doesn't clearly indicate it's for non-streaming requests. This creates ambiguity with createStreamingTimeoutSignal(). Consider renaming to createNonStreamingTimeoutSignal() or createPlainTimeoutSignal() to maintain naming consistency and clarity throughout the codebase.
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function name createCombinedSignal() is ambiguous since there's also createStreamingCombinedSignal(). The naming pattern is inconsistent - this function handles non-streaming requests but doesn't indicate that in its name. Consider renaming to createNonStreamingCombinedSignal() or createPlainCombinedSignal() to maintain clear distinction and naming consistency with the streaming variant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function name
getTimeoutMs()is too generic and ambiguous. It doesn't clearly indicate that it's specifically for non-streaming/plain requests. Consider renaming togetNonStreamingTimeoutMs()orgetPlainRequestTimeoutMs()to match the clarity ofgetStreamingTimeoutMs()and make the distinction between the two timeout types immediately obvious.