|
| 1 | +//! Centralized timeout constants for the Cortex CLI. |
| 2 | +//! |
| 3 | +//! This module provides consistent timeout values used throughout the codebase. |
| 4 | +//! Centralizing these values ensures uniformity and makes it easier to adjust |
| 5 | +//! timeouts across the application. |
| 6 | +
|
| 7 | +/// Default timeout for the entire execution in seconds (10 minutes). |
| 8 | +/// |
| 9 | +/// This is the maximum time allowed for a complete headless execution, |
| 10 | +/// including all LLM requests and tool executions. |
| 11 | +pub const DEFAULT_EXEC_TIMEOUT_SECS: u64 = 600; |
| 12 | + |
| 13 | +/// Default timeout for a single LLM request in seconds (2 minutes). |
| 14 | +/// |
| 15 | +/// This is the maximum time to wait for a single completion request |
| 16 | +/// to the LLM provider. |
| 17 | +pub const DEFAULT_REQUEST_TIMEOUT_SECS: u64 = 120; |
| 18 | + |
| 19 | +/// Default timeout for streaming responses in seconds (5 minutes). |
| 20 | +/// |
| 21 | +/// Extended timeout for LLM streaming requests where responses are |
| 22 | +/// delivered incrementally over time. |
| 23 | +pub const DEFAULT_STREAMING_TIMEOUT_SECS: u64 = 300; |
| 24 | + |
| 25 | +/// Default timeout for health check requests in seconds (5 seconds). |
| 26 | +/// |
| 27 | +/// Short timeout used for quick health check endpoints. |
| 28 | +pub const DEFAULT_HEALTH_CHECK_TIMEOUT_SECS: u64 = 5; |
| 29 | + |
| 30 | +/// Default timeout for graceful shutdown in seconds (30 seconds). |
| 31 | +/// |
| 32 | +/// Maximum time to wait for in-flight operations to complete during |
| 33 | +/// shutdown before forcing termination. |
| 34 | +pub const DEFAULT_SHUTDOWN_TIMEOUT_SECS: u64 = 30; |
| 35 | + |
| 36 | +/// Default timeout for batch execution in seconds (5 minutes). |
| 37 | +/// |
| 38 | +/// Maximum time allowed for executing a batch of parallel tool calls. |
| 39 | +pub const DEFAULT_BATCH_TIMEOUT_SECS: u64 = 300; |
| 40 | + |
| 41 | +/// Default timeout for individual read operations in seconds (30 seconds). |
| 42 | +/// |
| 43 | +/// Timeout for individual read operations to prevent hangs when |
| 44 | +/// Content-Length doesn't match actual body size. |
| 45 | +pub const DEFAULT_READ_TIMEOUT_SECS: u64 = 30; |
| 46 | + |
| 47 | +#[cfg(test)] |
| 48 | +mod tests { |
| 49 | + use super::*; |
| 50 | + |
| 51 | + #[test] |
| 52 | + fn test_timeout_values_are_reasonable() { |
| 53 | + // Exec timeout should be greater than request timeout |
| 54 | + assert!(DEFAULT_EXEC_TIMEOUT_SECS > DEFAULT_REQUEST_TIMEOUT_SECS); |
| 55 | + |
| 56 | + // Streaming timeout should be greater than request timeout |
| 57 | + assert!(DEFAULT_STREAMING_TIMEOUT_SECS > DEFAULT_REQUEST_TIMEOUT_SECS); |
| 58 | + |
| 59 | + // Health check should be short |
| 60 | + assert!(DEFAULT_HEALTH_CHECK_TIMEOUT_SECS <= 10); |
| 61 | + |
| 62 | + // Batch timeout should be reasonable |
| 63 | + assert!(DEFAULT_BATCH_TIMEOUT_SECS >= 60); |
| 64 | + } |
| 65 | +} |
0 commit comments