Skip to content

Fix stale model cleanup and prevent deleted discovered models from reappearing#263

Merged
KilimiaoSix merged 3 commits into
qxcnm:mainfrom
mozi1924:fix/aggregate-api-model-cleanup
May 24, 2026
Merged

Fix stale model cleanup and prevent deleted discovered models from reappearing#263
KilimiaoSix merged 3 commits into
qxcnm:mainfrom
mozi1924:fix/aggregate-api-model-cleanup

Conversation

@mozi1924
Copy link
Copy Markdown
Contributor

@mozi1924 mozi1924 commented May 23, 2026

变更摘要

  • 修复聚合 API 提供商失效(禁用/删除)后,自动并入的孤儿模型未被清理的问题。
  • 修复来源模型同步仅“新增/更新”不“清理陈旧项”的问题,避免模型在管理页删除后因残留路由再次出现。

改动范围

  • Frontend
  • Desktop / Tauri
  • Service
  • Gateway / Protocol Adapter
  • Docs / Governance
  • Workflow / Release

主要文件

  • crates/service/src/apikey/apikey_models.rs
  • crates/core/src/storage/model_sources.rs
  • crates/core/tests/storage.rs

验证

  • pnpm -C apps run test
  • pnpm -C apps run build
  • pnpm -C apps run test:ui
  • cargo test --workspace
  • 其他本地验证已说明

已执行的实际验证:

cargo test -p codexmanager-service bootstrap_aggregate_routes_ -- --nocapture
cargo test -p codexmanager-service aggregate_bootstrap_prunes_stale_source_routes -- --nocapture
cargo test -p codexmanager-core upsert_discovered_source_models_prunes_stale_discovered_routes -- --nocapture
cargo test -p codexmanager-service account_pool_bootstrap_ -- --nocapture

未执行的验证与原因:

pnpm -C apps run test / build / test:ui:本次改动不涉及前端与 Tauri。
cargo test --workspace:本次为定向修复,已执行 service/core 相关回归测试;未在本轮执行全量工作区测试。

风险与影响面

  • upsert_discovered_model_source_models 由“仅上插”调整为“同步语义(会清理同 source 同 discovery_kind 的陈旧项)”,可能影响依赖旧行为(保留历史 discovered 项)的场景。
  • 清理陈旧 discovered source model 时会同步删除对应 model_source_mappings,以避免删除后模型被残留路由重建;该行为符合“同步结果应收敛到当前发现集”的预期。

备注

  • 提交前已确认未包含敏感 token、cookie、API key。

@mozi1924 mozi1924 force-pushed the fix/aggregate-api-model-cleanup branch from 0194808 to efecfd3 Compare May 23, 2026 12:28
@KilimiaoSix
Copy link
Copy Markdown
Collaborator

CodeX 审查意见:当前不建议直接合并。

PR 已覆盖 disabled/deleted aggregate source 的清理路径,但仍遗漏 active aggregate API 同步时“单个模型从上游消失”的场景。

具体风险:第一次同步发现 vendor-old 时,会自动创建 source model、mapping 和 catalog model。第二次同步如果上游只返回 vendor-new,本 PR 会删除 vendor-old 对应的 source model/mapping,但不会删除自动创建的 catalog model,导致 vendor-old 仍显示为可用平台模型,却没有有效来源路由。

建议合并前补充:

  1. aggregate 同步前记录该 source 的旧 upstream model 集合。
  2. 同步后计算 disappeared slugs。
  3. 对这些 slugs 复用 cleanup_orphan_auto_catalog_models 清理孤儿自动 catalog model。
  4. 增加测试覆盖 active aggregate API 中单个模型下线的场景。

我已用临时边界测试验证该问题可以复现,因此建议修复后再合并。

@KilimiaoSix KilimiaoSix self-requested a review May 23, 2026 15:58
Copy link
Copy Markdown
Collaborator

@KilimiaoSix KilimiaoSix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed current head 56bddfe. Previous aggregate cleanup concern has been addressed and targeted regression tests pass. Approving.

@KilimiaoSix KilimiaoSix merged commit a0b66cd into qxcnm:main May 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.

2 participants