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): 修复 start_team 运行时 vendorOptions 更新 (#1768)

Chris Zhang7ccd64de7e36
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 a244d3dc82..137bb6cf87 100644
--- a/apps/desktop/src/main/mcp-integrations/__tests__/piEnvironment.test.ts
+++ b/apps/desktop/src/main/mcp-integrations/__tests__/piEnvironment.test.ts
@@ -70,6 +70,12 @@ function createTestServer(name: string): McpServer {
text: getLiziMcpSessionContext()?.sessionInstanceId ?? 'no-instance',
}],
}));
+ server.tool('current_vendor_options', 'Return the active lizi MCP vendor options.', {}, async () => ({
+ content: [{
+ type: 'text' as const,
+ text: JSON.stringify(getLiziMcpSessionContext()?.vendorOptions ?? {}),
+ }],
+ }));
return server;
}
@@ -175,6 +181,54 @@ describe('piEnvironment per-session identity', () => {
await after.text();
});
+ 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(), {
+ sessionId: 'pi-runtime-lead',
+ workingDir: '/repo',
+ vendorOptions,
+ });
+ const server = config!.mcpBridge!.servers[0]!;
+ const headers = {
+ authorization: `Bearer ${config!.mcpBridge!.token}`,
+ accept: 'application/json, text/event-stream',
+ 'content-type': 'application/json',
+ };
+ const initResp = await fetch(server.url, { method: 'POST', headers, body: INIT_BODY(21) });
+ expect(initResp.status).toBe(200);
+ const mcpSessionId = initResp.headers.get('mcp-session-id');
+ expect(mcpSessionId).toBeTruthy();
+ await initResp.text();
+
+ // 对应 start_team 成功后的 MakerSession.setVendorOptions 原地更新。
+ Object.assign(vendorOptions, {
+ orcaRole: 'lead',
+ orcaWorkflowId: 'team-1',
+ orcaLeadSessionId: 'pi-runtime-lead',
+ });
+ const callResp = await fetch(server.url, {
+ method: 'POST',
+ headers: { ...headers, 'mcp-session-id': mcpSessionId! },
+ body: JSON.stringify({
+ jsonrpc: '2.0',
+ id: 22,
+ method: 'tools/call',
+ params: { name: 'current_vendor_options', arguments: {} },
+ }),
+ });
+ expect(callResp.status).toBe(200);
+ const result = await readRpcText(callResp) as {
+ result?: { content?: Array<{ text?: string }> };
+ };
+ expect(JSON.parse(result.result?.content?.[0]?.text ?? '{}')).toMatchObject({
+ source: 'draft',
+ orcaRole: 'lead',
+ orcaWorkflowId: 'team-1',
+ orcaLeadSessionId: 'pi-runtime-lead',
+ });
+ config!.disposeSessionCtx!();
+ });
+
it('rejects a stale pi instance route after the same business session is rebound', async () => {
const oldConfig = await getPiExtraSpawnConfig([makeProvider()], noopLogger(), {
sessionId: 'pi-rebound',
diff --git a/apps/desktop/src/main/mcp-integrations/piEnvironment.ts b/apps/desktop/src/main/mcp-integrations/piEnvironment.ts
index c696c44580..b91cd1ac28 100644
--- a/apps/desktop/src/main/mcp-integrations/piEnvironment.ts
+++ b/apps/desktop/src/main/mcp-integrations/piEnvironment.ts
@@ -171,6 +171,11 @@ export async function getPiExtraSpawnConfig(
const disabledPluginIds = createPluginRegistry().getDisabledRuntimePluginIds(
sessionCtx?.workingDir ?? '',
);
+ // PiAgent 传入的是该 session 专属的可变副本。这里必须保留同一引用:start_team
+ // 成功后 MakerSession.setVendorOptions 会原地写入 Lead 身份,既有 HTTP MCP handler
+ // 要在下一次 create_worker 调用时立即看到。复制对象会把 bridge 永久冻结在启动态。
+ const vendorOptions = sessionCtx?.vendorOptions ?? {};
+ vendorOptions[CODEX_DISABLED_BUILTIN_PLUGIN_IDS_KEY] = disabledPluginIds;
const liziCtx: LiziMcpSessionContext = {
agentKind: 'pi',
sessionId,
@@ -178,10 +183,7 @@ export async function getPiExtraSpawnConfig(
? { sessionInstanceId: sessionCtx.sessionInstanceId }
: {}),
workingDir: sessionCtx?.workingDir ?? '',
- vendorOptions: {
- ...sessionCtx?.vendorOptions,
- [CODEX_DISABLED_BUILTIN_PLUGIN_IDS_KEY]: disabledPluginIds,
- },
+ vendorOptions,
};
// 同 session 重建(resume/reattach)直接覆盖注册,注册表以 sessionId 为 key,
// 天然不累积。必须在返回(即 spawn)前完成 —— cindy-bridge extension 一起进程
diff --git a/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts b/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts
index fa294c2e22..16de3c1073 100644
--- a/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/pi-auto-review-dispatch.test.ts
@@ -23,6 +23,7 @@ const captured = vi.hoisted(() => ({
requests: [] as Array<Record<string, unknown>>,
sent: [] as Array<Record<string, unknown>>,
proxyRegistration: null as { sessionId: string; token: string } | null,
+ mcpVendorOptions: undefined as Record<string, unknown> | undefined,
failSetModel: false,
rejectSetModel: false,
onAfterSetModel: null as null | (() => void),
@@ -97,6 +98,7 @@ describe('pi auto-review dispatch & spawn config (mocked pi process)', () => {
captured.requests = [];
captured.sent = [];
captured.proxyRegistration = null;
+ captured.mcpVendorOptions = undefined;
captured.failSetModel = false;
captured.rejectSetModel = false;
captured.onAfterSetModel = null;
@@ -137,16 +139,19 @@ describe('pi auto-review dispatch & spawn config (mocked pi process)', () => {
...(mcp?.policy ? { getMcpToolApprovalPolicy: mcp.policy } : {}),
...(mcp?.serverNames
? {
- preparePiExtraSpawnConfig: async () => ({
- mcpBridge: {
- token: 'bridge-token',
- servers: mcp.serverNames!.map((name) => ({
- name,
- url: `http://127.0.0.1:1/${name}`,
- })),
- },
- mcpEnv: {},
- }),
+ preparePiExtraSpawnConfig: async (_providers, context) => {
+ captured.mcpVendorOptions = context.vendorOptions;
+ return {
+ mcpBridge: {
+ token: 'bridge-token',
+ servers: mcp.serverNames!.map((name) => ({
+ name,
+ url: `http://127.0.0.1:1/${name}`,
+ })),
+ },
+ mcpEnv: {},
+ };
+ },
}
: {}),
auth: {
@@ -677,6 +682,21 @@ describe('pi auto-review dispatch & spawn config (mocked pi process)', () => {
expect(review).not.toHaveBeenCalled();
expect(resolverCalls).toBe(0);
expect(captured.sent).toContainEqual({ type: 'extension_ui_response', id: 'r20', confirmed: true });
+
+ // start_team 获批后 host 会把当前 session 切成 Lead。Pi 必须支持运行时原地合并,
+ // 并让启动时交给 MCP bridge 的同一 vendorOptions 引用立即看到新身份;否则
+ // MakerSession.setVendorOptions 抛 not-implemented,或后续 create_worker 仍读到旧 ctx。
+ expect(handle.setVendorOptions).toBeTypeOf('function');
+ await handle.setVendorOptions?.({
+ orcaRole: 'lead',
+ orcaWorkflowId: 'team-1',
+ orcaLeadSessionId: 's1',
+ });
+ expect(captured.mcpVendorOptions).toMatchObject({
+ orcaRole: 'lead',
+ orcaWorkflowId: 'team-1',
+ orcaLeadSessionId: 's1',
+ });
});
it('still asks the user for MCP servers the host policy does not trust', async () => {
diff --git a/packages/maker-core/src/agents/pi/index.ts b/packages/maker-core/src/agents/pi/index.ts
index 8dd2d9e152..44d2352e15 100644
--- a/packages/maker-core/src/agents/pi/index.ts
+++ b/packages/maker-core/src/agents/pi/index.ts
@@ -787,6 +787,10 @@ export class PiAgent extends BaseAgent {
mode === 'bypassPermissions' ? 'bypassPermissions' : mode === 'auto' ? 'auto' : 'ask';
let permissionMode = normalizePermissionMode(opts.permissionMode);
let mutableExtraDirs = [...(opts.extraDirs ?? [])];
+ // 与 Claude / Codex 一致,运行期 Orca 身份更新必须原地落在同一个对象上。
+ // Desktop Pi MCP bridge 在 startSession 时持有这个引用;start_team 成功后 host
+ // 调 setVendorOptions,后续 create_worker 等工具才能立即读到最新 Lead 身份。
+ const mutableVendorOptions: Record<string, unknown> = { ...(opts.vendorOptions ?? {}) };
type PermissionSnapshot = {
mode: 'ask' | 'auto' | 'bypassPermissions';
readOnlyRoots: string[];
@@ -933,7 +937,7 @@ export class PiAgent extends BaseAgent {
sessionId: opts.sessionId,
...(opts.sessionInstanceId ? { sessionInstanceId: opts.sessionInstanceId } : {}),
workingDir: opts.workingDir,
- vendorOptions: opts.vendorOptions,
+ vendorOptions: mutableVendorOptions,
});
mcpBridge = extra?.mcpBridge ?? null;
mcpEnv = extra?.mcpEnv ?? {};
@@ -1792,6 +1796,11 @@ export class PiAgent extends BaseAgent {
});
},
+ async setVendorOptions(patch: Record<string, unknown>): Promise<void> {
+ Object.assign(mutableVendorOptions, patch);
+ deps.logger.debug('pi setVendorOptions', { patchKeys: Object.keys(patch) });
+ },
+
isTurnRunning(): boolean {
// ctx.isStreaming 由 agent_start / agent_settled 翻转(translator 维护)。
return ctx.isStreaming;