Skip to content

fix(knowledge): check parser engine before reparse deletes existing content - #5377

Merged
lyingbug merged 2 commits into
Tencent:mainfrom
RyoKusnadi:fix/reparse-engine-preflight
Nov 16, 2026
Merged

lyingbug merged 2 commits into
Tencent:mainfrom
RyoKusnadi:fix/reparse-engine-preflight

Conversation

@RyoKusnadi

Copy link
Copy Markdown
Contributor

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) calls cleanupKnowledgeResources for file, file-URL and URL documents, then enqueues the parse. The worker only finds out the engine is unusable later, in resolveDocReader. Batch reparse calls the same function.

Cause: Nothing checked engine availability before the cleanup step.

Fix: New preflightReparseEngine runs just before cleanup. It resolves the engine and overrides the same way the worker does (KB parser rules, tenant overrides, per-upload overrides) and calls resolveDocReader, which wraps docparser.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. resolveDocReader now 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

  • 🐛 Bug fix

Related Issue

Fixes #5094

Testing

Added the case parser engine unavailable to TestReparseKnowledgeRejectedLeavesPreviousRunUntouched: 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 that DeleteChunksByKnowledgeID was 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.

  • Before the fix (preflight disabled): fails (Error "database unavailable" does not contain "is not available", meaning cleanup ran first and tried to delete).
  • After the fix: passes. The whole internal/application/service package 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...HEAD passes
  • Changed source files are formatted
  • Targeted tests for the changed packages/components pass
  • Diff-scoped lint passes where applicable (for Go: golangci-lint run --new-from-rev=origin/main ./...)
  • Full-repository checks were run, or any unrelated/environment-dependent failures are documented above
  • Self-reviewed the code
  • Added/updated tests covering the change
  • Updated related documentation (README, website-docs/, Swagger annotations, etc.)
  • Breaking changes are clearly called out in the description above

…ontent

Signed-off-by: Ryo Kusnadi <ryokusnadi@gmail.com>
… check fails

Signed-off-by: Ryo Kusnadi <ryokusnadi@gmail.com>
@lyingbug
lyingbug merged commit 60eafa7 into Tencent:main Nov 16, 2026
4 checks passed
@RyoKusnadi
RyoKusnadi deleted the fix/reparse-engine-preflight branch November 16, 2026 15:29
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Fix] Verify the parser engine before a reparse deletes existing chunks and vectors

2 participants