From 27d4525ba93d449868100ca483416f21a34c9176 Mon Sep 17 00:00:00 2001 From: ChenRussell <792608290@qq.com> Date: Thu, 26 Mar 2026 16:52:00 +0800 Subject: [PATCH] fix(app): prevent UTF-8 truncation in summary fallback When LLM summary generation fails, the fallback logic truncates the first chunk content to 500 characters. Previously used byte-based slicing (summary[:500]) which could cut multi-byte UTF-8 characters in half, causing PostgreSQL to reject invalid byte sequences. Changed to rune-based truncation to ensure valid UTF-8 after truncation. Fixes: Documents stuck in "Generating summary" status when containing Chinese/emoji characters and summary generation fails. --- internal/application/service/knowledge.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/application/service/knowledge.go b/internal/application/service/knowledge.go index 3a6b8947..595836d6 100644 --- a/internal/application/service/knowledge.go +++ b/internal/application/service/knowledge.go @@ -2082,7 +2082,11 @@ func (s *knowledgeService) ProcessSummaryGeneration(ctx context.Context, t *asyn if len(textChunks) > 0 { summary = textChunks[0].Content if len(summary) > 500 { - summary = summary[:500] + // Use rune-based truncation to avoid cutting UTF-8 multi-byte characters + runes := []rune(summary) + if len(runes) > 500 { + summary = string(runes[:500]) + } } } }