From 13260b831c72b5bc5420547097d6fbd0c4b823cf Mon Sep 17 00:00:00 2001 From: wizardchen Date: Tue, 28 Apr 2026 16:51:52 +0800 Subject: [PATCH] Fix wiki ingest silent data loss from malformed JSON in Redis queue Two critical fixes to the peekPendingList function: 1. Add error logging for JSON unmarshal failures (line 303) - Previously: Malformed JSON items were silently skipped with no indication - Now: Each failure is logged with the error and raw item content (first 100 chars) - This makes data loss visible and debuggable 2. Fix trim count mismatch (line 325) - Previously: Returned len(result) - the count of raw Redis items peeked - Now: Returns len(ops) - the count of successfully parsed items - Impact: Malformed items now stay in Redis for retry instead of being discarded - This prevents silent data loss when JSON encoding issues occur Root cause of the reported issue: - When 8 files are uploaded in a batch, if one has encoding issues that cause JSON.Unmarshal to fail, it was silently dropped from processing - The file was trimmed from Redis without being processed - Result: Only 7 of 8 files appeared in the Wiki Fix approach: - Make unmarshal failures visible in logs - Retry malformed items in the next batch instead of discarding them - Admin can see the errors and take corrective action Co-Authored-By: Claude Opus 4.6 (1M context) --- .gitignore | 2 ++ internal/application/service/wiki_ingest.go | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2808f312..b1043e38 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,8 @@ frontend/chrome-extension/ WeKnora-Chrome-Extension packages/protoc-3.19.4-linux-x86_64.zip +Claude.md + # 本地测试脚本 configure-ollama.sh fix-docker.sh \ No newline at end of file diff --git a/internal/application/service/wiki_ingest.go b/internal/application/service/wiki_ingest.go index b620eb64..603c77b6 100644 --- a/internal/application/service/wiki_ingest.go +++ b/internal/application/service/wiki_ingest.go @@ -299,6 +299,8 @@ func (s *wikiIngestService) peekPendingList(ctx context.Context, kbID string) ([ var op WikiPendingOp if err := json.Unmarshal([]byte(item), &op); err == nil { ops = append(ops, op) + } else { + logger.Warnf(ctx, "wiki ingest: failed to unmarshal pending op: %v, raw_item: %.100s", err, item) } } @@ -320,7 +322,7 @@ func (s *wikiIngestService) peekPendingList(ctx context.Context, kbID string) ([ unique = append(unique, reversedUnique[i]) } - return unique, len(result) + return unique, len(ops) } // trimPendingList removes the first `count` items from the Redis pending list.