Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(pi): 关闭协同模式后为 active Team 的 Lead/Worker 保留协同 MCP(#4734) (#4741)

FicoWangaa0e62e05043
diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/piEnvironment.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/piEnvironment.test.ts
index de9aa7dd61..09ee125907 100644
--- a/apps/desktop/src/main/mcp-integrations/__tests__/piEnvironment.test.ts
+++ b/apps/desktop/src/main/mcp-integrations/__tests__/piEnvironment.test.ts
@@ -13,6 +13,7 @@
*/
import { afterEach, describe, expect, it, vi } from 'vitest';
+import { PluginRegistry } from '../../maker-host/plugins/plugin-registry';
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { getLiziMcpSessionContext } from '@cindy/mcps';
import { createOrcaWorkerBridgeMcpProvider } from '@cindy/orca-workflow';
@@ -385,6 +386,73 @@ describe('piEnvironment per-session identity', () => {
config?.disposeSessionCtx?.();
});
+ it('keeps collab servers for a session already inside an active Team when the global toggle is off (issue 4734)', async () => {
+ const isEnabled = vi
+ .spyOn(PluginRegistry.prototype, 'isEnabled')
+ .mockImplementation((pluginId) => pluginId !== 'collab');
+ const collabNames = (config: Awaited<ReturnType<typeof getPiExtraSpawnConfig>>) =>
+ (config?.mcpBridge?.servers ?? [])
+ .map((server) => server.name)
+ .filter((name) => name === 'cindy_orca' || name === 'orca_worker_bridge');
+ // 真实的 Worker 通信 server(issue #4734 报的就是它丢了 → send_to_lead UNKNOWN_SERVER)
+ const logger = noopLogger();
+ const providers = [
+ makeProvider(),
+ createOrcaWorkerBridgeMcpProvider({
+ logger,
+ getMaker: () => {
+ throw new Error('not called while registering the MCP server');
+ },
+ persistUserMessage: async () => {},
+ wireSession: () => undefined,
+ }),
+ ];
+ try {
+ // 普通会话: 全局关闭后不再拿到协同 server(后续新建任务不协同)
+ const plain = await getPiExtraSpawnConfig(providers, logger, {
+ sessionId: 'pi-4734-plain',
+ workingDir: '/repo',
+ vendorOptions: {},
+ });
+ expect(collabNames(plain)).toEqual([]);
+ plain?.disposeSessionCtx?.();
+
+ // 已属于 active Team 的 Worker: 下一轮重建描述时仍保留 cindy_orca 与 orca_worker_bridge
+ const worker = await getPiExtraSpawnConfig(providers, logger, {
+ sessionId: 'pi-4734-worker',
+ workingDir: '/repo',
+ vendorOptions: {
+ orcaRole: 'worker',
+ orcaWorkflowId: 'team-1',
+ orcaLeadSessionId: 'lead-1',
+ orcaWorkerId: 'worker-1',
+ orcaWorkerSessionId: 'pi-4734-worker',
+ },
+ });
+ expect(collabNames(worker)).toEqual(['cindy_orca', 'orca_worker_bridge']);
+ worker?.disposeSessionCtx?.();
+
+ const lead = await getPiExtraSpawnConfig(providers, logger, {
+ sessionId: 'pi-4734-lead',
+ workingDir: '/repo',
+ vendorOptions: { orcaRole: 'lead', orcaWorkflowId: 'team-1', orcaLeadSessionId: 'pi-4734-lead' },
+ });
+ expect(collabNames(lead)).toEqual(['cindy_orca', 'orca_worker_bridge']);
+ lead?.disposeSessionCtx?.();
+
+ // 项目级 / 冻结伙伴的显式停用仍优先于 active Team 豁免
+ const frozen = await getPiExtraSpawnConfig(providers, logger, {
+ sessionId: 'pi-4734-frozen',
+ workingDir: '/repo',
+ vendorOptions: { orcaRole: 'worker', [CODEX_DISABLED_BUILTIN_PLUGIN_IDS_KEY]: ['collab'] },
+ });
+ expect(collabNames(frozen)).toEqual([]);
+ frozen?.disposeSessionCtx?.();
+ } finally {
+ isEnabled.mockRestore();
+ }
+ });
+
it('keeps the registered Pi MCP vendorOptions live for start_team Lead activation', async () => {
const vendorOptions: Record<string, unknown> = { source: 'draft' };
const config = await getPiExtraSpawnConfig([makeProvider('custom_probe')], noopLogger(), {
diff --git a/apps/desktop/src/main/mcp-integrations/piEnvironment.ts b/apps/desktop/src/main/mcp-integrations/piEnvironment.ts
index ded648ac4a..39b66e2fd9 100644
--- a/apps/desktop/src/main/mcp-integrations/piEnvironment.ts
+++ b/apps/desktop/src/main/mcp-integrations/piEnvironment.ts
@@ -188,8 +188,18 @@ export async function getPiExtraSpawnConfig(
// orca_worker_bridge),避免禁用后 pi 仍能建队/发消息(R5 配置审计 H-7)。
// 只按名字剥协同 server —— cindy_memory / ghost / 外部 HTTP MCP 与 collab
// 无关,照常注入(CC 的 selectRemoteInjectableServerNames 同语义)。
+ // issue #4734: 全局「协同模式」开关只约束**后续新建** Team / Worker(设置页文案:
+ // 关闭后仅影响后续新建的任务, 不会中止当前 Worker)。已经属于 active Team 的
+ // Lead / Worker(start_team / create_worker 写入 vendorOptions.orcaRole)在每一轮
+ // 重建 Pi MCP 描述时必须保留协同 server —— 否则 Worker 下一轮直接失去
+ // orca_worker_bridge, send_to_lead 报 UNKNOWN_SERVER 而文本回复仍被界面桥接,
+ // 失效不易察觉。只有显式结束 Team(orcaRole 被清)才移除。项目级 / 冻结伙伴的
+ // 显式停用列表仍优先: 那是明确的策略, 不是"以后不再协同"的全局开关。
+ const orcaRole = (sessionCtx?.vendorOptions as Record<string, unknown> | undefined)?.orcaRole;
+ const activeTeamMember = orcaRole === 'lead' || orcaRole === 'worker';
const collabEnabled =
- createPluginRegistry().isEnabled('collab') && !disabledPluginIds.includes('collab');
+ (createPluginRegistry().isEnabled('collab') || activeTeamMember)
+ && !disabledPluginIds.includes('collab');
const capabilityGated = (servers: NonNullable<PiExtraSpawnConfig['mcpBridge']>['servers']) =>
servers.filter((server) => {
if (server.name === 'cindy_memory' && sessionCtx?.memoryEnabled !== true) return false;