chore: consolidated refactoring and documentation improvements#92
Open
chore: consolidated refactoring and documentation improvements#92
Conversation
This PR consolidates all refactoring and documentation improvements from PRs #77 and #89. ## Refactoring (from PR #77) ### Timeout Constants - Created centralized cortex_common::timeout module with documented constants - Replaced scattered magic numbers with well-documented constants - Added comprehensive documentation for timeout hierarchy ### Code Quality - Used LazyLock for static regex initialization - Extracted subagent timeout values as named constants - Improved compile-time assertions ## Documentation (from PR #89) ### Timeout Hierarchy Documentation - Added detailed header documentation explaining timeout hierarchy - Documented each timeout constant with its purpose and use case - Established naming conventions for constants vs config fields - Added timeout hierarchy table for quick reference ### Timeout Reference Table | Use Case | Module | Constant | Value | Rationale | |-----------------------------|-----------------------------|-----------------------------|-------|-----------| | Health checks | cortex-common/http_client | HEALTH_CHECK_TIMEOUT | 5s | Quick validation | | Standard HTTP requests | cortex-common/http_client | DEFAULT_TIMEOUT | 30s | Normal API calls | | Connection pool idle | cortex-common/http_client | POOL_IDLE_TIMEOUT | 60s | DNS refresh | | LLM Request (non-streaming) | cortex-exec/runner | DEFAULT_REQUEST_TIMEOUT_SECS| 120s | Model inference | | LLM Streaming total | cortex-common/http_client | STREAMING_TIMEOUT | 300s | Long-running streams | ## Files Modified - src/cortex-common/src/timeout.rs (new) - src/cortex-common/src/http_client.rs - src/cortex-app-server/src/config.rs - src/cortex-exec/src/runner.rs - Multiple other files Closes #77, #89
Greptile OverviewGreptile SummaryConsolidated refactoring from PRs #77 and #89 that centralizes timeout constants and improves documentation across the codebase. Key Changes:
Issues Found:
Confidence Score: 3/5
|
| Filename | Overview |
|---|---|
| src/cortex-common/src/timeout.rs | New centralized timeout constants module with comprehensive documentation and tests |
| src/cortex-common/src/http_client.rs | Added detailed timeout hierarchy documentation and new health check client function |
| src/cortex-engine/src/tools/handlers/batch.rs | Changed timeout semantics from batch-level to tool-level, but left unused timeout_secs field causing confusion |
| src/cortex-common/src/config_substitution.rs | Refactored to use LazyLock for static regex initialization improving performance |
| src/cortex-mcp-client/src/transport.rs | Removed unused reconnection logic and test_connection method |
Sequence Diagram
sequenceDiagram
participant User
participant cortex-exec
participant cortex-common
participant cortex-engine
participant cortex-app-server
Note over cortex-common: New timeout module<br/>centralized constants
User->>cortex-exec: Execute CLI command
cortex-exec->>cortex-common: Import DEFAULT_EXEC_TIMEOUT_SECS (600s)
cortex-exec->>cortex-common: Import DEFAULT_REQUEST_TIMEOUT_SECS (120s)
cortex-exec->>cortex-engine: Execute tool batch
cortex-engine->>cortex-common: Import DEFAULT_BATCH_TIMEOUT_SECS (300s)
Note over cortex-engine: Uses tool_timeout_secs (60s)<br/>per individual tool
cortex-exec->>cortex-app-server: HTTP request to LLM
cortex-app-server->>cortex-common: Use http_client factory
alt Streaming Request
cortex-common->>cortex-common: STREAMING_TIMEOUT (300s)
else Standard Request
cortex-common->>cortex-common: DEFAULT_TIMEOUT (30s)
else Health Check
cortex-common->>cortex-common: HEALTH_CHECK_TIMEOUT (5s)
end
Note over cortex-common: All timeouts now documented<br/>in timeout hierarchy table
cortex-app-server-->>cortex-exec: Response
cortex-exec-->>User: Result
Comment on lines
46
to
+51
| /// Optional timeout in seconds for the entire batch (default: 300s). | ||
| #[serde(default)] | ||
| pub timeout_secs: Option<u64>, | ||
| /// Optional timeout in seconds for individual tools (default: 60s). | ||
| /// This prevents a single tool from consuming the entire batch timeout. | ||
| #[serde(default)] |
There was a problem hiding this comment.
timeout_secs parameter is not used in the implementation - only tool_timeout_secs is used (line 341). Either remove this field or implement batch-level timeout enforcement.
Suggested change
| /// Optional timeout in seconds for the entire batch (default: 300s). | |
| #[serde(default)] | |
| pub timeout_secs: Option<u64>, | |
| /// Optional timeout in seconds for individual tools (default: 60s). | |
| /// This prevents a single tool from consuming the entire batch timeout. | |
| #[serde(default)] | |
| /// Optional timeout in seconds for individual tools (default: 60s). | |
| /// This prevents a single tool from consuming the entire batch timeout. | |
| #[serde(default)] | |
| pub tool_timeout_secs: Option<u64>, |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cortex-engine/src/tools/handlers/batch.rs
Line: 46:51
Comment:
`timeout_secs` parameter is not used in the implementation - only `tool_timeout_secs` is used (line 341). Either remove this field or implement batch-level timeout enforcement.
```suggestion
/// Optional timeout in seconds for individual tools (default: 60s).
/// This prevents a single tool from consuming the entire batch timeout.
#[serde(default)]
pub tool_timeout_secs: Option<u64>,
```
How can I resolve this? If you propose a fix, please make it concise.Address Greptile review feedback: The timeout_secs parameter was documented and accepted but never used. Now it properly wraps the entire parallel execution with a batch-level timeout, separate from the per-tool timeout_secs. - Add batch-level timeout wrapper around execute_parallel - Return descriptive error message when batch times out - Add test for batch timeout behavior
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR consolidates all refactoring and documentation improvements from PRs #77 and #89.
Refactoring (from PR #77)
Timeout Constants
Code Quality
Documentation (from PR #89)
Timeout Hierarchy Documentation
Timeout Reference Table
Files Modified
Closes #77, #89