Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(memory): dedupe episode write on duplicate streaming Done
Andy Yang3d94a476bf79
diff --git a/internal/application/service/chat_pipeline/memory.go b/internal/application/service/chat_pipeline/memory.goindex c2429d6d6..0fdd11b95 100644--- a/internal/application/service/chat_pipeline/memory.go+++ b/internal/application/service/chat_pipeline/memory.go@@ -3,6 +3,7 @@ package chatpipelineimport ("context""fmt"+ "sync""github.com/Tencent/WeKnora/internal/event""github.com/Tencent/WeKnora/internal/logger"@@ -118,6 +119,7 @@ func (p *MemoryPlugin) handleStorage(// If streaming, subscribe to eventsif chatManage.EventBus != nil {var fullResponse string+ var storeOnce sync.OnceuserID := chatManage.UserIDsessionID := chatManage.SessionIDbgCtx := context.WithoutCancel(ctx)@@ -129,15 +131,19 @@ func (p *MemoryPlugin) handleStorage(}fullResponse += data.Contentif data.Done {- messages := []types.Message{- {Role: "user", Content: chatManage.Query},- {Role: "assistant", Content: fullResponse},- }- go func() {- if err := p.memoryService.AddEpisode(bgCtx, userID, sessionID, messages); err != nil {- logger.Errorf(bgCtx, "failed to add episode: %v", err)+ // Stream layer may emit Done:true twice (e.g. finish_reason chunk + EOF sentinel).+ // qa.go dedupes with completionHandled; keep memory writes consistent with one episode only.+ storeOnce.Do(func() {+ messages := []types.Message{+ {Role: "user", Content: chatManage.Query},+ {Role: "assistant", Content: fullResponse},}- }()+ go func() {+ if err := p.memoryService.AddEpisode(bgCtx, userID, sessionID, messages); err != nil {+ logger.Errorf(bgCtx, "failed to add episode: %v", err)+ }+ }()+ })}return nil})