refactor: consolidated code quality improvements - constants, lazy init, and documentation#77
Closed
refactor: consolidated code quality improvements - constants, lazy init, and documentation#77
Conversation
…it, and documentation This PR consolidates the following refactoring changes: - #27: Centralize timeout constants - #43: Replace magic numbers with documented named constants - #67: Use LazyLock for static regex initialization - #68: Extract subagent timeout values as named constants Key changes: - Created centralized timeout module with documented constants - Replaced scattered magic numbers with well-documented constants - Improved static initialization using LazyLock for regexes - Added comprehensive documentation for timeout hierarchy
This was referenced Feb 4, 2026
Greptile OverviewGreptile SummaryThis PR consolidates four refactoring efforts into a cohesive code quality improvement that centralizes timeout constants, replaces magic numbers, and optimizes static initialization patterns. Key Improvements
Issues Found
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| src/cortex-common/src/timeout.rs | new centralized timeout module with well-documented constants and unit tests |
| src/cortex-common/src/config_substitution.rs | replaced instance regex with static LazyLock patterns for better performance |
| src/cortex-common/src/http_client.rs | added comprehensive timeout hierarchy documentation table |
| src/cortex-engine/src/tools/handlers/batch.rs | added tool_timeout_secs parameter for individual tool timeouts, but timeout_secs is now unused |
| src/cortex-tui/src/runner/event_loop/streaming.rs | replaced magic numbers with named constants for streaming timeouts |
| src/cortex-tui/src/runner/event_loop/subagent.rs | replaced magic numbers with named constants for subagent timeouts |
Sequence Diagram
sequenceDiagram
participant Client as Client/Tool Executor
participant Batch as BatchToolHandler
participant Tools as Individual Tools
participant Timeout as timeout module
Note over Client,Timeout: Centralized Timeout Architecture
Client->>Timeout: Import timeout constants
Timeout-->>Client: DEFAULT_BATCH_TIMEOUT_SECS (300s)
Client->>Batch: execute(BatchToolArgs)
Note over Batch: Parse tool_timeout_secs<br/>(default: 60s)
par Parallel Tool Execution
Batch->>Tools: execute_tool_1() with timeout
Batch->>Tools: execute_tool_2() with timeout
Batch->>Tools: execute_tool_N() with timeout
end
alt Tool completes in time
Tools-->>Batch: Success result
else Tool times out after 60s
Tools-->>Batch: Timeout error
end
Batch-->>Client: BatchResult (aggregated)
Note over Client,Timeout: LazyLock Pattern for Regex
Client->>cortex_common: config_substitution
activate cortex_common
Note over cortex_common: ENV_REGEX & FILE_REGEX<br/>initialized once via LazyLock
cortex_common-->>Client: Compiled patterns (shared)
deactivate cortex_common
Comment on lines
46
to
48
| /// Optional timeout in seconds for the entire batch (default: 300s). | ||
| #[serde(default)] | ||
| pub timeout_secs: Option<u64>, |
There was a problem hiding this comment.
timeout_secs parameter is no longer used after switching to per-tool timeouts. The code now only uses tool_timeout_secs (line 341), making this parameter obsolete.
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. |
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:48
Comment:
`timeout_secs` parameter is no longer used after switching to per-tool timeouts. The code now only uses `tool_timeout_secs` (line 341), making this parameter obsolete.
```suggestion
/// Optional timeout in seconds for individual tools (default: 60s).
/// This prevents a single tool from consuming the entire batch timeout.
```
How can I resolve this? If you propose a fix, please make it concise.
Additional Comments (1)
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/cortex-engine/src/tools/handlers/batch.rs
Line: 391:396
Comment:
`timeout_secs` is no longer used in the code and should be removed from the tool definition schema to avoid confusion.
```suggestion
"tool_timeout_secs": {
"type": "integer",
"description": "Optional timeout in seconds for individual tool execution (default: 60). Prevents a single tool from consuming the entire batch timeout.",
"minimum": 1,
"maximum": 300
```
How can I resolve this? If you propose a fix, please make it concise. |
Contributor
Author
|
Closing this PR to consolidate into a single mega-PR combining all refactoring and documentation changes. |
echobt
added a commit
that referenced
this pull request
Feb 4, 2026
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
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 4 refactoring PRs into a single, cohesive change.
Included PRs:
Key Changes:
cortex_common::timeoutmodule with documented constantsLazyLockfor regex patternsFiles Modified:
src/cortex-common/src/timeout.rs(new)src/cortex-common/src/config_substitution.rssrc/cortex-app-server/src/auth.rssrc/cortex-app-server/src/streaming.rssrc/cortex-engine/src/tools/handlers/batch.rssrc/cortex-engine/src/tools/handlers/grep.rssrc/cortex-engine/src/tools/unified_executor.rssrc/cortex-exec/src/runner.rssrc/cortex-tui/src/runner/event_loop/subagent.rssrc/cortex-tui/src/runner/event_loop/streaming.rsCloses #27, #43, #67, #68