fix(im): remove pipeline-level timeout that kills multi-round agent reasoning
The IM service applied a hard 120s deadline (`qaTimeout`) to the entire QA pipeline context. Multi-round ReAct agents easily exceed this — when the deadline fires mid-stream the LLM provider returns "context deadline exceeded" which leaks into the user-visible answer (fixes #1000). Changes: - Replace `context.WithTimeout(ctx, qaTimeout)` with `context.WithCancel(ctx)` in both `handleMessageStream` and `runQA`, matching the web handler's approach. Each agent round still has its own per-call LLMCallTimeout (default 120s) which is sufficient. - Filter `ResponseTypeError` stream chunks in `streamLLMToEventBus` so error messages (e.g. "context deadline exceeded") are never appended to the LLM content. Instead they are captured in `StreamError` and surfaced as a Go error when no usable content was produced. - Bump Redis inflight mapping TTL from qaTimeout+30s to 10 minutes to accommodate longer agent runs. - Remove the now-unused `qaTimeout` constant.
This commit is contained in:
@@ -19,6 +19,7 @@ type streamLLMResult struct {
|
||||
ToolCalls []types.LLMToolCall
|
||||
Usage *types.TokenUsage
|
||||
FinishReason string // actual finish_reason from LLM (captured from last stream chunk)
|
||||
StreamError string // error message from stream (e.g., timeout), kept separate from Content
|
||||
}
|
||||
|
||||
// streamLLMToEventBus streams LLM response through EventBus (generic method)
|
||||
@@ -52,6 +53,14 @@ func (e *AgentEngine) streamLLMToEventBus(
|
||||
}
|
||||
responseTypeCounts[string(chunk.ResponseType)]++
|
||||
|
||||
// Capture error messages from the stream (e.g., "context deadline exceeded")
|
||||
// but do NOT append them to result.Content — they would leak to the user
|
||||
// as if they were part of the LLM answer.
|
||||
if chunk.ResponseType == types.ResponseTypeError {
|
||||
result.StreamError = chunk.Content
|
||||
continue
|
||||
}
|
||||
|
||||
if chunk.Content != "" {
|
||||
isExtracted := chunk.Data != nil && chunk.Data["source"] != nil
|
||||
if !isExtracted {
|
||||
@@ -86,6 +95,12 @@ func (e *AgentEngine) streamLLMToEventBus(
|
||||
chunkCount, len(result.Content), len(result.ToolCalls),
|
||||
streamDuration.Milliseconds(), responseTypeCounts)
|
||||
|
||||
// If the stream produced an error and no usable content/tool calls,
|
||||
// surface it as a Go error so the caller can retry or degrade gracefully.
|
||||
if result.StreamError != "" && result.Content == "" && len(result.ToolCalls) == 0 {
|
||||
return result, fmt.Errorf("LLM stream error: %s", result.StreamError)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user