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.
This commit is contained in:
ChenRussell
2026-03-26 16:52:00 +08:00
committed by lyingbug
parent d0811898b0
commit 27d4525ba9
+5 -1
View File
@@ -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])
}
}
}
}