Skip to content

fix(datasource): perform real sync deletions scoped per data source - #2690

Merged
lyingbug merged 9 commits into
Tencent:mainfrom
mdrkrg:feat/ds-sync-deletion
Aug 13, 2026
Merged

fix(datasource): perform real sync deletions scoped per data source #2690
lyingbug merged 9 commits into
Tencent:mainfrom
mdrkrg:feat/ds-sync-deletion

Conversation

@mdrkrg

@mdrkrg mdrkrg commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Description

同步删除 sync_deletions(目前默认开启)在文档里写“源端删除文档时同步删除本地知识”,但此前实现只做了计数,不会删除

本 PR 让删除生效,同时确保删除/更新定位不会跨数据源误删

假如认为同步删除有风险,可以默认关闭同步删除(UI 侧也改掉默认值)

预期行为

  • 数据源条目被删除且 sync_deletions 开启时,同步从知识库移除对应条目。关闭时不删除或计数
  • 删除与更新只作用于本数据源同步的条目,两个数据源出现相同 external_id 时不会覆盖或删除
  • 条目已不在知识库中(手动删除或此前已同步删除)时计为 skipped,不算失败
  • 删除失败的条目计入失败样本并在同步日志中展示,同步结果标记为 partial。失败的删除仅在下一次全量同步时重试
  • 仅 URL 的条目同样纳入按数据源定位,可被同步删除

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📚 Documentation update
  • 🎨 Refactor
  • ⚡ Performance improvement
  • 🧪 Test
  • 🔧 Configuration / Build / CI

Related Issue

部分解决 #2623

注意:用户删除 knowledge 时数据源跳过同步的 PR #2684 使用软删除作为 tombstone 跳过标记。如果先合入,这个分支的同步删除需要补充。

#2684 只对更新路径(delete-for-update)与子条目清理(sweep)追加了硬删除,对 applyFetchedItem 源端删除的情况,需要这个 PR 在 DeleteKnowledge 后追加 HardDeleteKnowledge,否则同步删除会留下 tombstone 标记,数据源如果重新添加同 external_id 条目时将不会重新同步回来

如果 review 通过,推荐先合并 #2684,这个 PR 再加测试“同步删除不留软删除标记”并修改

可能关联与合并冲突:#1643, #2632

Testing

新增测试

  • 开启同步删除:移除匹配条目,且定位按数据源作用域
  • 关闭同步删除:不删除、不计数
  • 条目已不存在时计 skipped
  • 查找失败 / 删除失败计入失败样本与 partial 状态
  • URL 条目创建后携带数据源标识,后续可被同步删除

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, docs/, Swagger annotations, etc.)
  • Breaking changes are clearly called out in the description above

Screenshots / Recordings

mdrkrg added 4 commits August 13, 2026 13:52
- deleted connector items remove the matching KB knowledge, scoped per data
  source via metadata datasource_id + external_id
- SyncDeletions=false neither deletes nor counts
- stream handler classifies deleted/failed items like the batch loop
- applyFetchedItem now performs the KB deletion instead of only counting
- lookup is scoped to datasource_id + external_id so identical external IDs
  from two data sources cannot collide or overwrite each other
- ingestItem update-path lookup uses the same scoped query
- SyncResult.DeletionFailed tracks deletion failures (subset of Failed)
- streaming partial message warns that failed deletions only retry on a full
  sync, since the connector cursor is checkpointed past the deleted item
- raw lookup/delete errors go to server logs only, with full context
- UI samples carry a humanized "see server logs" fallback
- add datasource.syncError.* i18n keys

Note: ko-KR / ru-RU syncError translations were generated without a
native-speaker review.
@mdrkrg
mdrkrg force-pushed the feat/ds-sync-deletion branch from b60d6ae to 7e43b29 Compare August 13, 2026 07:33
Sync-internal deletions now call HardDeleteKnowledge after the soft-delete
cascade so tombstones cannot block re-sync; subtree sweeps and URL metadata
attach failures are handled with datasource scoping and explicit errors.
Install via scripts/install-git-hooks.sh (sets core.hooksPath). Pre-commit
runs whitespace/gofmt/golangci-lint on staged files; pre-push mirrors
app/frontend/cli workflows on the diff since origin/main.
Pre-push now gofmts the full PR diff and runs go vet on all app packages
(like app.yml), not only Go files in the latest commit. Previous pushes
skipped checks via --no-verify and because hook-only commits had no .go files.
Use three-dot diff against the open PR baseRefOid (same as CI) instead of
a two-dot merge-base range; run full go vet on every push with Go PR changes.
@lyingbug
lyingbug merged commit 236d8c0 into Tencent:main Aug 13, 2026
5 checks passed
qbsoft pushed a commit to qbsoft/TeKnowra that referenced this pull request Aug 20, 2026
…encent#2690)

* test(datasource): cover scoped sync deletions

- deleted connector items remove the matching KB knowledge, scoped per data
  source via metadata datasource_id + external_id
- SyncDeletions=false neither deletes nor counts
- stream handler classifies deleted/failed items like the batch loop

* fix(datasource): perform real sync deletions scoped per data source

- applyFetchedItem now performs the KB deletion instead of only counting
- lookup is scoped to datasource_id + external_id so identical external IDs
  from two data sources cannot collide or overwrite each other
- ingestItem update-path lookup uses the same scoped query

* fix(datasource): note failed deletions retry only on full sync

- SyncResult.DeletionFailed tracks deletion failures (subset of Failed)
- streaming partial message warns that failed deletions only retry on a full
  sync, since the connector cursor is checkpointed past the deleted item

* fix(datasource): humanize deletion errors, keep raw detail in logs

- raw lookup/delete errors go to server logs only, with full context
- UI samples carry a humanized "see server logs" fallback
- add datasource.syncError.* i18n keys

Note: ko-KR / ru-RU syncError translations were generated without a
native-speaker review.

* fix(datasource): hard-delete synced rows and tighten deletion scoping

Sync-internal deletions now call HardDeleteKnowledge after the soft-delete
cascade so tombstones cannot block re-sync; subtree sweeps and URL metadata
attach failures are handled with datasource scoping and explicit errors.

* chore: add git hooks aligned with CI and PR checks

Install via scripts/install-git-hooks.sh (sets core.hooksPath). Pre-commit
runs whitespace/gofmt/golangci-lint on staged files; pre-push mirrors
app/frontend/cli workflows on the diff since origin/main.

* fix: gofmt test file; tighten pre-push to match CI app workflow

Pre-push now gofmts the full PR diff and runs go vet on all app packages
(like app.yml), not only Go files in the latest commit. Previous pushes
skipped checks via --no-verify and because hook-only commits had no .go files.

* fix(hooks): align pre-push diff with GitHub PR base via gh

Use three-dot diff against the open PR baseRefOid (same as CI) instead of
a two-dot merge-base range; run full go vet on every push with Go PR changes.

* style: gofumpt datasource_service_test.go

---------

Co-authored-by: wizardchen <wizardchen@tencent.com>
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.

2 participants