fix: persist user model mapping intent across prune/bootstrap cycles (#294)#298
Open
panzeyu2013 wants to merge 2 commits into
Open
fix: persist user model mapping intent across prune/bootstrap cycles (#294)#298panzeyu2013 wants to merge 2 commits into
panzeyu2013 wants to merge 2 commits into
Conversation
…xcnm#294) Add model_source_mapping_preferences tombstone table to record user unlink/disable intent, preventing auto_associate_source_models from recreating deleted mappings and resetting disabled state after source recovery from rate limiting. - New migration 064 for preferences table - 4 CRUD methods in model_sources.rs storage layer - W1: delete_managed writes 'unlinked' before deleting mapping - W2: save_managed writes/clears preference based on enabled state - W3/W4: delete_account/delete_aggregate_api cascade clean preferences - W5: stale model cleanup in upsert_discovered cascades to preferences - W6: prune path preserves preferences (survive temporary unavailability) - W7: specific-source sync path deletes preferences (known inactive) - R1: auto_associate bulk-loads preferences, skips unlinked, disables - RPC enhanced to pass sourceKind/sourceId/upstreamModel alongside id - delete_aggregate_api rewritten with transaction and 3-level cascade - Frontend/Tauri/web transport payload pattern aligned with save command
…5 conflict - Main introduced 064_drop_gateway_error_logs - Renamed model_source_mapping_preferences migration from 064 to 065 - Both migrations registered sequentially in mod.rs
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.
Closes #294
问题
auto_associate_source_models()不感知用户意图——将"从未关联过"和"用户主动解除关联"同等视为"缺失映射"。导致两个 BUG:onSuccess触发reloadManagedRouting→ bootstrap →auto_associate发现映射不存在 → 用新 ID 重建enabled=truelimited→ prune 删全部映射(含已 disabled) → 账户恢复 →auto_associate无状态可查 → 全部重建enabled=true根源:用户意图只存储在
model_source_mappings行中,而prune_stale_*和auto_associate机制无条件删除并重建这些行。方案
引入
model_source_mapping_preferences墓碑表,独立于映射存储用户意图:写入点(7 处)
delete_managed'unlinked'→ DELETE 映射save_managedenabled=false→ INSERT'disabled';true→ DELETE 偏好delete_accountdelete_aggregate_apiupsert_discoveredstaledelete_model_source_routes_for_source(prune)sync_*(特定 source_id)读取点(1 处)
auto_associate_source_models'unlinked'skip /'disabled'enabled=false/ 未命中默认true关键设计决策
modelSourceMappingDelete新增sourceKind/sourceId/upstreamModel参数,前端已持有直接透传,消除数据库反查和竞态auto_associate用一次list_model_source_mapping_preferences构建 HashMap,循环内 O(1) 匹配,避免 N+1delete_aggregate_api补齐:原来只删 3 张 API 表,现改为事务版,补齐model_source_mappings和model_source_models的级联删除withAddr({ payload: params })+ Tauripayload: serde_json::Value+ WebmapParams解包,与 save 命令完全对标改动文件
新增
crates/core/migrations/064_model_source_mapping_preferences.sql修改 Rust 后端(6 个文件):
crates/core/src/storage/mod.rs— struct + migration 注册crates/core/src/storage/model_sources.rs— 表创建 + 4 个 CRUD 方法 + stale 清理追加crates/core/src/storage/accounts.rs— delete_account 级联偏好crates/core/src/storage/aggregate_apis.rs— delete_aggregate_api 重写为事务版 + 补齐 3 层级联crates/service/src/apikey/apikey_models.rs— save/delete/auto_associate 逻辑 + W7 清理点crates/service/src/rpc_dispatch/apikey.rs— RPC 参数扩展修改前端/桌面(5 个文件):
apps/src/lib/api/account-client.ts— 传参扩展apps/src/lib/api/transport-web-commands.ts— mapParamsapps/src/hooks/useManagedModels.ts— 签名 + mutation 类型apps/src/app/models/page.tsx— 调用点传完整 mappingapps/src-tauri/src/commands/apikey.rs— Tauri 命令改为 payload 模式测试修改:
crates/service/src/tests/lib_tests.rs— 测试参数补齐