Skip to content

fix(orca): 协同新建 Worker 默认跟随上次模型与当前主任务模型 - #15925

Open
dashhuang wants to merge 1 commit into
mainfrom
cindy/lively-kalam
Open

dashhuang wants to merge 1 commit into
mainfrom
cindy/lively-kalam

Conversation

@dashhuang

@dashhuang dashhuang commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

这次改了什么

摘要

修复协同模式「创建新 Worker」弹窗在未记忆内置模型时默认落到 Grok 4.7 等首个可用 Codex 模型的问题。

原先存在三处叠加缺口:

  1. 未跟随当前主任务(Lead)模型:没有上次 Worker 模型记录时,表单固定从 codex + codex/gpt-5.5 起步;若当前账号未连接提供该模型的默认 OpenAI 渠道,收敛逻辑会回退到 activeModels[0](按内置供应商序可能落到 xAI 的 xai/grok-4.7)。
  2. 自定义智能路由未被记住且污染内置槽:选择自定义智能路由创建 Worker 后未写入 modelSelectionByHost,反而把底层未生效的旧内置模型写进 workerCreationPrefs,重开时又清空了 modelGroup。
  3. 插件引擎(ACP)与合并来源路由未被记住:onAttach 挂载合并来源路由(src:...)时会清空已选 pluginEngine,且提交插件引擎时直接返回未落盘/未同步角色与宿主机记忆。

本次在桌面端、移动端与 @cindy/device-link 跨端同步链路统一补齐:

  • 上次提交的 Worker 模型记忆完整覆盖三类路线:内置模型(含合并供应商路由)、插件引擎(ACP,含合并来源路由)、自定义智能路由,且非内置路线不再覆盖污染旧版逐 Agent 槽位。
  • 当前账号与宿主机尚无已保存的 Worker 模型记忆时,默认跟随当前主任务(Lead)正在使用的模型(含内置模型、插件引擎与智能路由);无 Lead 信息时收敛优先选模型声明的默认项(newSessionDefault),而非盲取列表首项。
  • 保留「未改动默认提交继续跟随 Lead」与「已保存模型失效时不静默切模型、展示不可用提示」的既有不变量,同时修复远程 Lead 能力/插件目录加载竞态与权限同步细节。

变更类型

  • feat 新功能
  • fix 缺陷修复
  • refactor / perf 重构或性能优化
  • docs / test / chore 文档、测试或工程维护
  • 其他:

范围

  • 关联 Issue / 需求:无
  • 本 PR 包含:
    • packages/device-link/src/orcaWorkerRoles.ts:向后兼容地追加 pluginEngine、modelGroup 与 model.modelGroup 协议字段,并校验单条目/单次提交路线互斥。
    • 桌面端:workerCreationPrefs.ts、CreateWorkerPopover.tsx、usePluginEngines.ts、usePickerPluginEngines.ts,以及 CCAgentSessionView.tsx、OrcaWorkerPanel.tsx、OrcaWorkersTabBody.tsx、NewMakerDraftRoute.tsx 传入当前 Lead 模型默认值。
    • 移动端:orcaWorkerPrefs.ts、orcaWorkerRoles.ts、useSessionOrcaCollab.ts、apps/mobile/app/sessions/new.tsx 同步对齐三类路线记忆与 Lead 默认跟随。
    • 配套单元测试与回归覆盖。
  • 明确不包含:服务端改动、UI 布局/视觉/文案改动、MCP create_workers 非内置模型工具默认值扩展(readLocalWorkerCreationSelection 仅继续输出归一化后的内置模型路线)。
  • 用户可见变化:打开「创建新 Worker」或「开启协同」时,模型默认记住上次创建的 Worker 模型(含插件引擎与自定义智能路由);首次使用或尚未保存过 Worker 模型时,默认跟随当前主任务正在使用的模型,不再意外回落到 Grok。
  • 是否存在 breaking change:无

UI 变化

不涉及。

  • 引用的设计规范:不涉及:仅修改协同新建 Worker 弹窗与手机端协同表单的默认模型解析、记忆持久化及跨端同步逻辑,未改动 UI 布局、样式、动效或文案。

怎么验证的

自动验证

pnpm --filter @cindy/device-link exec tsc --noEmit && pnpm --filter @cindy/device-link exec vitest run src/__tests__/orcaWorkerRoles.test.ts
结果:PASS — 1 file, 7/7 tests (782ms)

cd apps/desktop && pnpm exec vitest run src/renderer/state/workerCreationPrefs.test.ts src/renderer/hooks/__tests__/usePickerPluginEngines.test.tsx src/renderer/features/cc-agent/__tests__/CreateWorkerPopover.test.tsx src/renderer/features/cc-agent/__tests__/OrcaWorkerPanel.test.tsx src/renderer/features/right-sidebar/plugins/orca-workers/__tests__/OrcaWorkersTabBody.mergeBack.test.tsx src/renderer/__tests__/remoteWorkerCreationContext.test.ts src/renderer/__tests__/orcaWorkflowRoute.test.ts src/main/maker-ipc/__tests__/workerCreationPrefsSyncHandler.test.ts
结果:PASS — 8 files, 224/224 tests (8.96s;其中 CreateWorkerPopover.test.tsx 5.09s,workerCreationPrefs.test.ts 5ms,usePickerPluginEngines.test.tsx 9ms)

cd apps/desktop && pnpm exec vitest run src/renderer/components/new-chat/__tests__/PluginEnginesSection.test.tsx src/renderer/features/plugin/__tests__/PluginEngineRemoteUse.test.tsx src/renderer/hooks/__tests__/usePickerPluginEngines.test.tsx
结果:PASS — 3 files, 68/68 tests (7.52s)

cd apps/mobile && pnpm exec vitest run src/__tests__/useOrcaWorkerForm.test.tsx src/__tests__/OrcaWorkerFormView.test.tsx
结果:PASS — 2 files, 65/65 tests (4.15s;其中 useOrcaWorkerForm.test.tsx 219ms)

pnpm --filter desktop typecheck && pnpm mobile:typecheck
结果:PASS(Desktop 全部 4 个分片 12308 文件 + Mobile 全量类型检查均 0 错误)

pnpm check:test-hygiene && pnpm check:engineering-guards && pnpm check:dco origin/main..HEAD
结果:PASS(test-hygiene 472 文件在基线内;engineering-guards 12 条严格规则 0 违规;DCO 签名通过)

新增/更新单测价值与实测耗时(engineering-conventions.md §3.2):

  • packages/device-link/src/__tests__/orcaWorkerRoles.test.ts(单文件实测 782ms,unit):生产入口 parseOrcaWorkerRoles / parseOrcaWorkerRolesMutation;验证追加的 pluginEngine、modelGroup、model.modelGroup 跨端往返与路线互斥拒收,防止协议字段静默丢弃或写入冲突路线。
  • apps/desktop/src/renderer/state/workerCreationPrefs.test.ts(单文件实测 5ms,unit/jsdom):生产入口 applyWorkerRolesMutation / toRemoteWorkerRoles / readLocalWorkerCreationSelection;验证三类路线持久化、跨端往返、非内置路线不污染旧槽、不泄漏至 MCP 工具默认路由,以及仅更新权限的 choice 语义。
  • apps/desktop/src/renderer/features/cc-agent/__tests__/CreateWorkerPopover.test.tsx(单文件实测 5.09s,unit/jsdom):生产入口 CreateWorkerPopover;覆盖无保存模型时跟随 Lead(内置/插件引擎/自定义路由)且忽略旧污染槽、newSessionDefault 优先收敛、提交插件引擎(含 onAttach 合并来源路由)与自定义智能路由后重开恢复,以及已保存路线失效阻断 vs Lead 路线失效安全回退。
  • apps/desktop/src/renderer/hooks/__tests__/usePickerPluginEngines.test.tsx(单文件实测 9ms,unit/jsdom):生产入口 usePickerPluginEngines;验证 enabled=false 时不再触发 usePluginEnginesSettled 订阅。
  • apps/mobile/src/__tests__/useOrcaWorkerForm.test.tsx(单文件实测 219ms,unit):生产入口 useOrcaWorkerForm;覆盖移动端无宿主记忆时跟随 Lead 三类模型、提交插件引擎(含 onAttach 不清空 acp)与自定义路由写回宿主机并重开恢复,以及旧宿主不支持 supportsOrcaWorkerAgentDevice 时省略 agentDeviceId。

读写与订阅开销说明(engineering-conventions.md §8):

  • 新增 usePluginEnginesSettled(enabled) 严格受 enabled && !hostDeviceId 门控,弹窗关闭或处于远端控制时不建立额外订阅、不发额外 IPC;DeviceCatalogue.isSettled() 仅在首次失败/不支持状态跃迁时触发一次本地订阅者通知,不增加任何新的远程调用或轮询。
  • 跨端读写复用既有 maker:worker-roles:get / maker:worker-roles:apply 单次调用,单条角色或 defaults 仅增加可选 pluginEngine / modelGroup 字段(推导增量 < 200 字节/条目),无新增通道与额外往返。

手工验证

不涉及(已通过桌面端与移动端核心交互单测及类型检查覆盖完整状态机;未启动真实 Electron / iOS 模拟器手工点测)。

未执行的验证

未执行真实 Electron 客户端界面与 iOS/Android 真机/模拟器端到端手工联调(本任务在隔离 worktree 中完成代码与自动化回归验证,等待 PR CI 流水线进一步校验)。

风险

风险分类

  • 无已知风险
  • SQLite / migration
  • system prompt
  • 协议兼容
  • 权限 / 安全 / 用户数据
  • 存量插件兼容(批准状态 / 指纹 / manifest 校验 / 安装布局 / 包格式)
  • 插件引擎(ACP)与插件模型影响面(新任务 / 模型选择器 / 权限 / 多端 / 引擎枚举分支)
  • 原生层 / fingerprint / OTA
  • 跨平台差异
  • 其他:

影响与回滚

  • 影响范围:桌面端与移动端的协同开启 / 创建新 Worker 弹窗的默认模型恢复与记忆写入,以及 @cindy/device-link maker:worker-roles:get / apply 可选字段解析。
  • 协议兼容与降级方式:所有新增字段(pluginEngine、modelGroup、model.modelGroup)均为可选追加字段。新控制端连旧宿主机时,choice.agent 仍携带合法内置 Agent,旧宿主机忽略未知字段且不报错;旧控制端连新宿主机时,旧端忽略新增可选字段并沿用原有内置回退行为。
  • 回滚方式:直接 revert 本 PR 单个提交即可无损恢复旧行为,不涉及数据库迁移、本地存储不可逆格式变更或移动端原生指纹变化。

提交前检查

  • 已 review 完整 diff
  • 每个 commit 都带 DCO 签名(git commit -s,见 DCO)
  • UI 改动已在「UI 变化」注明引用的设计规范章节(不涉及 UI 则跳过)
  • 未提交凭证、令牌或授权文件
  • 已核对受影响的文档,行为变化涉及的旧结论已同步修订(不涉及则无需修改文档)
  • 已确认测试结果或说明未执行原因
  • 涉及数据读取、通知后刷新、界面频繁写入或常驻组件时,已在「怎么验证的」写明:每个用户动作和每次通知触发几次 list/扫描/IPC/写事务(读远程数据再写远程调用次数和回包字节),以及隐藏或卸载后是否停止
  • 如用户操作、界面入口或报错发生变化,已同步 apps/docs 或说明自动同步会从哪些来源更新(本次无新入口或文案变化)。

Assisted-by: Cindy (https://cindy.app)


Note

Medium Risk
Touches cross-platform Orca worker creation, optional device-link role sync fields, and ACP/model-group state machines; regressions could mis-default models or block create, but behavior is guarded by tests and backward-compatible optional protocol fields.

Overview
Creates new Worker and enable collab flows now default the model picker to the Lead task’s current model (built-in, plugin engine, or smart route) when there is no saved per-host Worker route, instead of falling back to stale per-agent prefs or the first Codex entry (e.g. Grok).

Persistence and restore are extended so submitted routes are stored and synced as a single discriminated shape: built-in (optional merged src: route), ACP plugin engine (including merged source routes without clearing the engine on onAttach), and custom model-group-only routes. Non-built-in choices do not overwrite legacy lastAgent / per-agent slots; invalid saved routes block submit with saved model unavailable, while invalid Lead-inherited routes fall back cleanly.

Wiring passes leadModel from session/draft into CreateWorkerPopover / OrcaWorkerPanel (desktop) and useOrcaWorkerForm (mobile). usePickerPluginEngines exposes isDeviceSettled so restore does not treat loading catalogs as “engine missing.”

Reviewed by Cursor Bugbot for commit 7d5d02a. Bugbot is set up for automated code reviews on this repo. Configure here.

修复创建新 Worker 弹窗默认落回 Grok 等首个可用 Codex 模型的问题:
- 桌面端、移动端与 @cindy/device-link 跨端同步均完整记忆上次提交的 Worker 模型路线,覆盖内置模型(含合并供应商路由)、插件引擎(ACP,含合并来源路由)与自定义智能路由,不再因非内置路线覆盖污染旧版逐 Agent 槽位。
- 当前账号与宿主机尚无已保存的 Worker 模型记忆时,弹窗默认跟随当前主任务(Lead)正在使用的模型(内置模型、插件引擎或自定义智能路由),并在无 Lead 信息回退收敛时优先使用模型声明的默认项。
- 修正合并供应商来源路由(onAttach)清空已选插件引擎的问题,以及远程 Lead 能力/插件目录加载竞态与不可用路由回退细节。

Assisted-by: Cindy (https://cindy.app)
Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
@dashhuang
dashhuang requested a review from a team as a code owner December 5, 2026 23:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-05T23:37:29.750023Z 7d5d02a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@zqchris zqchris left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Auto-approved by Chris’s trusted-author rule for makecindy/cindy. This is an automated approval.

@greptile-apps

greptile-apps Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5RetriggerView in Greptile

[Medium impact] The changes affect Worker creation and route memory across desktop, mobile, and linked devices.

应先修复已保存 ACP 模型失效时的静默替换,再合并。

Findings

  1. P1 已保存模型被静默替换 ▶
Fix with agent prompt
### Issue 1
apps/desktop/src/renderer/features/cc-agent/CreateWorkerPopover.tsx:1042-1046
用户上次保存了 ACP 模型 `pro`,但插件后来只列出 `basic` 时,`resolveActivePluginEngine` 会返回 `modelId: 'default'`,而不是空值。这里的 `!activePluginEngine` 因此为假,不会显示模型不可用提示,提交按钮也保持可用。提交还会把原先保存的 `pro` 覆盖为 `default`。

这违背了本次修复承诺的“已保存模型失效时不静默切模型”。请检查恢复的具体模型是否仍可用;失效时保留原选择、提示不可用并阻止提交。用户明确选择的 `default` 则继续允许。

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

本次补齐桌面端和手机端的 Worker 模型记忆,并在没有保存记录时跟随 Lead。

  • Desktop Worker creation follows the Lead and remembers the full model route.
  • Mobile Worker creation follows the Lead and remembers plugin and smart routes.
  • Device Link role memory can carry plugin and smart model routes.

Diagram

%%{init: {'theme': 'neutral', 'htmlLabels': false}}%%
flowchart TD
  A[打开 Worker 表单] --> B{是否保存过模型}
  B -->|是| C[恢复内置模型、ACP 或智能路由]
  B -->|否| D[跟随 Lead 模型]
  C --> E[检查是否可用]
  D --> E
  E --> F[提交创建并更新记忆]
  C --> G[ACP 插件仍在,但具体模型已下架]
  G --> H[现有解析返回 default]
  H --> F
Loading

Reviews (1) · Last reviewed commit: "fix(orca): 协同新建 Worker 默认跟随上次模型与当前主任务模型" · Reviewed by Greptile

Comment on lines +1042 to +1046
const restoredPluginEngineUnavailable =
pluginEngineOrigin === 'restored'
&& pluginEngine !== null
&& !activePluginEngine
&& !pluginEngineLoading;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 已保存模型被静默替换

用户上次保存了 ACP 模型 pro,但插件后来只列出 basic 时,resolveActivePluginEngine 会返回 modelId: 'default',而不是空值。这里的 !activePluginEngine 因此为假,不会显示模型不可用提示,提交按钮也保持可用。提交还会把原先保存的 pro 覆盖为 default。

这违背了本次修复承诺的“已保存模型失效时不静默切模型”。请检查恢复的具体模型是否仍可用;失效时保留原选择、提示不可用并阻止提交。用户明确选择的 default 则继续允许。

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/renderer/features/cc-agent/CreateWorkerPopover.tsx
Line: 1042-1046

Comment:
**已保存模型被静默替换**

用户上次保存了 ACP 模型 `pro`,但插件后来只列出 `basic` 时,`resolveActivePluginEngine` 会返回 `modelId: 'default'`,而不是空值。这里的 `!activePluginEngine` 因此为假,不会显示模型不可用提示,提交按钮也保持可用。提交还会把原先保存的 `pro` 覆盖为 `default`。

这违背了本次修复承诺的“已保存模型失效时不静默切模型”。请检查恢复的具体模型是否仍可用;失效时保留原选择、提示不可用并阻止提交。用户明确选择的 `default` 则继续允许。

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 4 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7d5d02a. Configure here.

if (remoteCatalogues.get(key) !== null && remoteCatalogues.get(key) !== undefined) return true;
const peer = selectableDevices.find((device) => device.deviceId === target);
return peer !== undefined && !peer.online;
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Lead plugin engine dropped early

High Severity

isDeviceSettled treats a plugin-engine device as settled when it is not yet in remoteSources. On open, the peer list is often still empty, so a Lead or restored engine on another computer looks missing. The Lead fallback then clears pluginEngine and does not restore it after the catalogue arrives, so the worker is created with the built-in model instead.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7d5d02a. Configure here.

setModel(fallbackPrefs.model);
setEffort(fallbackPrefs.effort);
setFast(fallbackPrefs.fast);
setProviderSource((leadDeviceId && !prefsFromHost) || leadLocation ? null : fallbackPrefs.providerId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unavailable Lead engine keeps stale model

Medium Severity

When the Lead model is an ACP engine, the built-in fallback is taken from stored[stored.lastAgent], which can still be the old per-agent slot such as xai/grok-4.7. If that engine is missing or not allowed, clearing pluginEngine leaves that stale model in place instead of the Lead model or the newSessionDefault model.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7d5d02a. Configure here.

deviceId: ctx.deviceLinkDeviceId,
agentDeviceId: leadSession ? (leadSession.agentDeviceId ?? null) : undefined,
leadPermissionMode: leadSession?.permissionMode ?? null,
leadModel: leadModelDefaultFromSession(leadSession),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sidebar ignores effective Lead binding

Medium Severity

The session view follows the Lead model from effectiveManagedBinding, but the sidebar worker panel calls leadModelDefaultFromSession(leadSession) with the raw session binding. When the managed binding differs, creating a worker from the sidebar does not follow the model the main task is actually using.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7d5d02a. Configure here.

name: binding.routeName?.trim() || binding.selection.id.trim(),
...(binding.isSourceRoute ? { isSourceRoute: true } : {}),
}
: null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Mobile Lead route ignores device

Medium Severity

orcaLeadModelDefaultFromSession treats any route binding as a local Lead model group. Unlike the desktop helper, it does not ignore bindings that carry another computer's deviceId, so the worker form can follow a cross-device route that does not exist on the task host.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7d5d02a. Configure here.

This branch has not been deployed

No deployments
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.

3 participants