fix(knowledge): retry document processing after transient indexing failures - #3915
Open
yeliheng-010 wants to merge 1 commit into
Open
yeliheng-010 wants to merge 1 commit into
yeliheng-010 wants to merge 1 commit into
Conversation
…ilures processChunks marked the knowledge failed and returned nil when BatchIndex failed, so ProcessDocument acked the task and the configured document-task retries never ran. A short embedding or vector-store outage left the row permanently failed; unchanged data-source syncs did not reprocess it. While attempts remain, still clean up the partial chunks and vectors but keep the row processing and return the error to the queue. The final attempt (or a caller without a retry loop) records the failure as before.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When
BatchIndexfails insideprocessChunks, the knowledge row is markedfailedand the function returnsnil.ProcessDocumenttherefore acks thedocument:processtask, so its configured retries (MaxRetry(3)) never run. A short embedding-provider or vector-store outage that outlasts the indexer's in-process backoff (5 attempts, ~6 s) leaves the document permanently failed until someone reparses it by hand. For data-source documents the sync cursor has already moved past the item, so an unchanged incremental sync does not reprocess it either.This change keeps the existing cleanup but defers the terminal status to the last attempt:
summaryTaskWillRetry, which already reads both asynq and Lite executor retry metadata), the partial chunks and vectors are still removed, the row staysprocessing, and the error is returned so the queue re-runs the idempotent parse.failedexactly as before andnilis returned, so dead-letter handling is unchanged.No schema, API, config or dependency changes.
Type of Change
Related Issue
No existing issue. Related but different scope: #3005 (closed, resumable embedding across vendor files), #2593 (sub-batch pacing/retry inside the embedding client), #1348 (cleanup context after timeout), #3656 (chunk cleanup on quota failure). None of them propagate the
BatchIndexerror to the task queue.Testing
Regression tests (
knowledge_process_index_retry_test.go):TestProcessChunksRetriesBatchIndexFailureBeforeLastAttemptfails onmain(An error is expected but got nil) and passes with the fix.TestProcessChunksFailsKnowledgeOnLastBatchIndexAttemptchecks the final attempt still recordsfailedand cleans up.Real backend run: native Lite server (SQLite + lite vector store, Lite task executor), real Ollama
bge-m3behind a local proxy that returns 503 for embedding requests while a fault flag is set, and an RSS data source served by a local HTTP feed. This exercises the shared ingest/queue path, not an external SaaS connector.main(bccb4b1)failedafter the first attempt; 0 chunks / 0 vectors; no task retry; a later unchanged sync creates/updates nothing and the row staysfailedprocessingafter the first attempt, the task retries automatically, endscompletedwith 1 chunk / 1 vector containing the source text; a later unchanged sync writes nothingfailedwith the 503 message after the retries (20 rejected embedding requests, ~46 s); no further requests after it settlesChecks:
git diff --check origin/main...HEADgofmt -lon changed files (clean)go vet ./internal/application/servicego test -race -count=1 -run 'TestProcessChunks|TestSummaryTaskWillRetry' ./internal/application/servicegolangci-lint run --new-from-rev=origin/main ./internal/application/service/...(0 issues)go build -tags sqlite_fts5 ./cmd/serverLOG_FORMAT= go test -count=1 ./internal/application/service ./internal/routeron bothmainand this branch: the same 21 tests fail on both in this Windows environment (sandbox/symlink/data-source schedule tests); the failure sets are identical, no new failures. The full repository suite was not run; checks covered the changed package and the task router.Not covered: the Redis/asynq worker path was not run end to end here (the Lite executor was); the retry decision uses the same asynq retry metadata as the existing summary retry path.
Prepared with AI assistance.
Checklist
git diff --check origin/main...HEADpassesgolangci-lint run --new-from-rev=origin/main ./...)website-docs/, Swagger annotations, etc.)