Commit Graph

2 Commits (22cbcdfa5789b33dbb8d47532c21b24da2fdf5aa)

Author SHA1 Message Date
wizardchen 079e96ae64 fix(knowledge): make in-place file replacement race-safe
Queued ProcessDocument tasks still held the old FilePath, and a crash
between the source UPDATE and reparse could leave completed knowledge
pointing at a new file. Dequeue first, flip pending in the same write,
and skip stale worker Saves when the stored path has moved.
2026-09-16 14:54:47 +08:00
ZHE MA 419ff2507c feat(knowledge): add in-place file replacement primitive
Add KnowledgeService.ReplaceKnowledgeFile, which replaces the stored
source file of an existing file knowledge while preserving its knowledge
ID, then re-parses it through ReparseKnowledge. It is groundwork for the
local folder data source (#2873); no existing API, handler or connector
behavior changes.

Object storage is not transactional, so the steps are ordered to keep the
row pointing at an existing file: save the new file, update the source
columns in one UPDATE, reparse, and only then delete the old file. A
failed column update discards the new file; a failed reparse restores the
previous source columns (marked failed, since cleanup may already have
removed the old index) and discards the new file. The row is re-read
before a replacement file is deleted, so a write that committed despite
reporting an error never leaves the knowledge referencing a deleted file.

Identical content under the same name and folder is not re-parsed: changed
metadata is persisted and a DuplicateKnowledgeError is returned, matching
CreateKnowledgeFromFile's duplicate contract. Metadata is merged so
entries such as process overrides survive, and stored overrides are
re-validated against the new file type.
2026-09-16 14:54:47 +08:00