Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(agentic-rag): deliver the final answer after a budget stop (#21301)

Caobaining1e2401e54947d
diff --git a/internal/service/agentic_pipeline.go b/internal/service/agentic_pipeline.go
index d3509be86c..c82a676a8c 100644
--- a/internal/service/agentic_pipeline.go
+++ b/internal/service/agentic_pipeline.go
@@ -146,11 +146,23 @@ func (s *ChatPipelineService) agenticRag(
runState.Sys["tenant_id"] = chat.TenantID
}
runCtx = runtime.WithState(runCtx, runState)
+ // A result is abandoned only when the CALLER is gone. runCtx is not the
+ // delivery signal: the token budget cancels it precisely so that the
+ // terminating fallback can answer from the evidence already gathered, so
+ // treating that cancellation as "nobody is listening" dropped the very
+ // answer the run had just built and shipped an empty reply. Delivery is
+ // tried first and unconditionally, because out is buffered and the
+ // consumer always drains it.
emitResult := func(result AsyncChatResult) bool {
select {
case out <- result:
return true
- case <-runCtx.Done():
+ default:
+ }
+ select {
+ case out <- result:
+ return true
+ case <-ctx.Done():
return false
}
}