Repository navigation
fix(knowledge): check parser engine before reparse deletes existing content - #5377
Merged
Merged
Conversation
…ontent Signed-off-by: Ryo Kusnadi <ryokusnadi@gmail.com>
… check fails Signed-off-by: Ryo Kusnadi <ryokusnadi@gmail.com>
6 of 10 tasks
8 of 11 tasks
komorebi-c9
pushed a commit
to komorebi-c9/WeKnora
that referenced
this pull request
Nov 17, 2026
ybochuan
pushed a commit
to ybochuan/LanRAG-Next
that referenced
this pull request
Nov 24, 2026
…ontent (Tencent#5377) (cherry picked from commit 60eafa7)
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
Replaces #5097 (closed by me; its fork branch was deleted, so it couldn't be reopened).
Check the parser engine before a reparse deletes anything, so an unavailable engine no longer leaves a document empty.
Problem: If the parser engine is missing or the docreader service is unreachable, "reparse" deletes the document's old chunks and vectors, then the background parse fails. The document ends up with no old and no new content.
How it happens:
knowledgeService.reparseKnowledge(knowledge_process.go) callscleanupKnowledgeResourcesfor file, file-URL and URL documents, then enqueues the parse. The worker only finds out the engine is unusable later, inresolveDocReader. Batch reparse calls the same function.Cause: Nothing checked engine availability before the cleanup step.
Fix: New
preflightReparseEngineruns just before cleanup. It resolves the engine and overrides the same way the worker does (KB parser rules, tenant overrides, per-upload overrides) and callsresolveDocReader, which wrapsdocparser.NewReader. If no reader can be built, the request fails with a 400 that says the engine is unavailable and the content is kept. Manual knowledge is skipped because it does not use a parser engine.resolveDocReadernow also tolerates a nil tenant service, which the test harness uses.Scope: This checks that a reader can be created (engine registered, docreader connected). It does not ping the remote service, so a docreader that is connected but fails during the parse is not covered. I left that as it needs a network call per reparse.
Type of Change
Related Issue
Fixes #5094
Testing
Added the case
parser engine unavailabletoTestReparseKnowledgeRejectedLeavesPreviousRunUntouched: a PDF with no docreader configured, and a chunk repo whose delete fails. The test expects the preflight error, no queued work, no status change, and thatDeleteChunksByKnowledgeIDwas never called (so no chunks are deleted when the preflight fails). Vector deletion is in the same cleanup step, after the preflight, so it is covered by the same check.Error "database unavailable" does not contain "is not available", meaning cleanup ran first and tried to delete).internal/application/servicepackage also passes (3132 tests).Commands:
go test ./internal/application/service/(full package),go test ./internal/application/service/ -run TestReparseKnowledge,go vet ./internal/application/service/,gofmt -l internal/application/service,golangci-lint run --new-from-rev=origin/main ./internal/application/service/(0 issues),git diff --check origin/main...HEAD. Not run: the full repo suite, a real docreader.Environment: main @ cbdceba plus this branch, go1.27.1 (go.mod says 1.26.0), darwin/arm64.
Checklist
git diff --check origin/main...HEADpassesgolangci-lint run --new-from-rev=origin/main ./...)website-docs/, Swagger annotations, etc.)