fix(codex): 向导编辑已有 MultiRouter 时 subagentV2 原样直通,profile 键与重建后的别名目录错位
现象
通过 MultiRouter 向导编辑已有方案后,子 Agent 的 profile 键与重建后的投影目录可见名错位,产生孤儿/孪生 profile(同一模型两个键,旧的不可路由且无清理入口),需手工到数据库删除。#74 的 preview 断链正是这个窗口的产物。
机理
src/lib/codexMultiRouterWizard.ts::buildCodexMultiRouterWizardPlan(约 1248-1388 行):
- 重建 routes/聚合目录时,模型源经
resolveWizardModelNameCollisions消歧改名(可见名 =模型-来源后缀),subagentV2却原样直通(约 1348 行):const routing: CodexRoutingConfigV2 = { ...(existingRoutingV2 ?? {}), schemaVersion: 2, ... subagentV2: existingRouting?.subagentV2, // ← 键名仍是旧可见名 routes, }; - 向导保存时还会把消歧后的源 provider 目录(含别名可见名)写回各源 provider(
CodexMultiRouterWizard.tsx约 1555-1566 行providersApi.update(source, "codex"))。 - 结果:投影目录可见名已变,
subagentV2.profiles的键/model还是旧名 → 编译 Unroutable;SyncCatalog 随后按新目录补种一个新键 profile(enabled=false 默认问卷)→ 一旧一新孪生并存。 spawnAgentModels在 1349-1351 行按selectedVisibleModels过滤,改名后的旧条目会被静默丢弃而不是重定向。
对照:新建方案没有此问题——保存后走 codexSubagentV2Api.initializeProviderConfig(plan.id) 按新目录全新播种(键名一致);编辑分支没有任何 reconcile/初始化调用。
建议修复
在 buildCodexMultiRouterWizardPlan 构建路由后、组装 routing 前,对 existingRouting?.subagentV2.profiles 做名字重定向(与后端 reconcile_codex_subagent_v2_for_candidate SyncCatalog 迁移同构):
- 旧
profile.model经 旧 routes[].aliases + 旧目录 upstreamModel 求出 upstream 身份; - 再在 新 resolvedSources 目录 + 新 routes[].aliases 中把 upstream 身份映射回新可见名;
- 重写 profile 的键与
model字段;新身份已被其他 profile 占用时不迁移(与后端语义一致); spawnAgentModels同样经该映射重定向后再按可见集过滤;- 无关联(模型已下架)条目原样保留,交由既有的 unroutable 呈现与清理入口兜底。
或者在向导的编辑分支保存 plan 后也调用一次 SyncCatalog reconcile(当前仅新建分支调 initializeProviderConfig)。
复现
- 向导创建 MultiRouter,启用两个含同名模型的源(触发消歧改名);
- 保存后再进向导调整任意设置并保存;
- 子 Agent 页可见旧名 profile(不可路由)与别名键新 profile 并存。
Resolved in v3.19.2-25 by cc7a7b17. Wizard edits now migrate profile keys, profile.model, and spawnAgentModels through stable upstream identity and the rebuilt visible alias catalog, with occupied targets preserved.