Uh oh!
There was an error while loading. Please reload this page.
feat: consolidated streaming and timeout improvements - #90
Conversation
## Summary This PR consolidates **3 feature PRs** for streaming and timeout improvements. ### Included PRs: - #25: Add per-chunk timeout for SSE streaming to prevent hangs - #29: Add early JSON validation for tool call arguments - #34: Add per-tool timeout in batch execution ### Key Changes: - Added CHUNK_TIMEOUT_SECS constant for SSE streaming (60s) - Wrapped SSE event iteration with tokio::time::timeout - Added validate_arguments() method to StreamToolCall - Added is_valid_complete() helper and complete_tool_call_validated() method - Added DEFAULT_TOOL_TIMEOUT_SECS constant (60 seconds) for batch - Added tool_timeout_secs field to BatchToolArgs for configuration - Applied individual timeout to each tool execution in execute_parallel() ### Files Modified: - src/cortex-engine/src/client/cortex.rs - src/cortex-engine/src/streaming.rs - src/cortex-engine/src/tools/handlers/batch.rs - src/cortex-engine/src/tools/unified_executor.rs Closes#25, #29, #34
Greptile OverviewGreptile SummaryThis PR consolidates three streaming and timeout improvements from PRs #25, #29, and #34. The changes add per-chunk timeout for SSE streaming (60s), JSON validation methods for tool call arguments, and per-tool timeout for batch execution (60s). Key improvements:
Issues found:
Recommendations:
Confidence Score: 3/5
|
| Filename | Overview |
|---|---|
| src/cortex-engine/src/client/cortex.rs | Added per-chunk timeout (60s) to SSE streaming to prevent indefinite hangs when connections stall |
| src/cortex-engine/src/streaming.rs | Added validation methods for tool call arguments including validate_arguments(), is_valid_complete(), and complete_tool_call_validated() |
| src/cortex-engine/src/tools/handlers/batch.rs | Added per-tool timeout (60s) for batch execution to prevent single tools from blocking others; renamed parameter from batch timeout to tool timeout |
| src/cortex-engine/src/tools/unified_executor.rs | Added extraction of tool_timeout_secs parameter from batch arguments to support individual tool timeouts |
Sequence Diagram
sequenceDiagram
participant Client
participant CortexClient
participant SSEStream
participant BatchHandler
participant ToolExecutor
Note over CortexClient,SSEStream: SSE Streaming with Per-Chunk Timeout
Client->>CortexClient: create_completion_stream()
CortexClient->>SSEStream: Start SSE stream
loop For each chunk (max 60s wait)
CortexClient->>SSEStream: timeout(60s, stream.next())
alt Chunk received in time
SSEStream-->>CortexClient: Ok(Some(event))
CortexClient->>Client: Send event
else No chunk within 60s
SSEStream-->>CortexClient: Err(Elapsed)
CortexClient->>Client: BackendError("SSE chunk timeout")
CortexClient->>SSEStream: Close stream
end
end
Note over BatchHandler,ToolExecutor: Batch Execution with Per-Tool Timeout
Client->>BatchHandler: execute(BatchToolArgs)
BatchHandler->>BatchHandler: Validate calls
BatchHandler->>BatchHandler: Set tool_timeout (60s default)
par Execute tools in parallel
BatchHandler->>ToolExecutor: timeout(60s, execute_tool("tool1"))
alt Tool completes in time
ToolExecutor-->>BatchHandler: Ok(ToolResult)
else Tool times out
ToolExecutor-->>BatchHandler: Err(Elapsed)
BatchHandler->>BatchHandler: Create timeout error
end
and
BatchHandler->>ToolExecutor: timeout(60s, execute_tool("tool2"))
alt Tool completes in time
ToolExecutor-->>BatchHandler: Ok(ToolResult)
else Tool times out
ToolExecutor-->>BatchHandler: Err(Elapsed)
BatchHandler->>BatchHandler: Create timeout error
end
end
BatchHandler->>BatchHandler: Aggregate results
BatchHandler-->>Client: BatchResult
| // Determine per-tool timeout (prevents single tool from blocking others) | ||
| let tool_timeout_secs = args.tool_timeout_secs.unwrap_or(DEFAULT_TOOL_TIMEOUT_SECS); | ||
| let tool_timeout = Duration::from_secs(tool_timeout_secs); |
There was a problem hiding this comment.
The timeout_secs parameter is no longer used but still documented and accepted. This could be confusing for users who expect it to control the overall batch timeout. Either:
- Remove
timeout_secsentirely if it's not needed - Or implement it as an overall batch timeout in addition to per-tool timeouts
The original PRs merged here indicate #34 specifically addressed "per-tool timeout in batch execution", so this may be intentional, but the timeout_secs field and documentation should be removed if it's not functional.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cortex-engine/src/tools/handlers/batch.rs
Line: 343:345
Comment:
The `timeout_secs` parameter is no longer used but still documented and accepted. This could be confusing for users who expect it to control the overall batch timeout. Either:
1. Remove `timeout_secs` entirely if it's not needed
2. Or implement it as an overall batch timeout in addition to per-tool timeouts
The original PRs merged here indicate #34 specifically addressed "per-tool timeout in batch execution", so this may be intentional, but the `timeout_secs` field and documentation should be removed if it's not functional.
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
Uh oh!
There was an error while loading. Please reload this page.
Summary
This PR consolidates 3 feature PRs for streaming and timeout improvements.
Included PRs:
Key Changes:
Files Modified:
Closes#25, #29, #34