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) <noreply@anthropic.com>
This commit is contained in:
wizardchen
2026-04-28 16:51:52 +08:00
committed by lyingbug
parent b1fc0e18d9
commit 13260b831c
2 changed files with 5 additions and 1 deletions
+2
View File
@@ -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
+3 -1
View File
@@ -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.