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。

merge: sync published plugin task runtime fixes

Dash2e7caa4ed787
diff --cc apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
index 4362b2cde3,ef072557d2..12384bc532
--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
@@@ -2778,13 -2779,20 +2779,21 @@@ describe('production plugin Auto admiss
const payload = () => JSON.stringify(planned ? { teamPlan: { concurrency: 2, items: [planItem] } } : {});
const receipt = { pluginId: 'plugin', operation: 'create', payload: payload() };
const depsForCallback = {
+ readPluginTaskPlanReceipt: JSON.parse,
getCurrentDbClientSnapshot: () => epoch,
- createPluginTaskStore: () => ({ get: async () => { if (++receiptReads === 6 && point === 'receipt') revoke(); return receipt; } }),
- createPluginTaskStore: () => ({ get: async () => { if (++receiptReads === 4 && point === 'receipt') revoke(); return structuredClone(receipt); } }),
++ createPluginTaskStore: () => ({ get: async () => { if (++receiptReads === 6 && point === 'receipt') revoke(); return structuredClone(receipt); } }),
pluginTaskServiceForCurrentOwner: () => ({ get: async () => {
- ++taskReads;
- if (taskReads === 6 && point === 'final-task') revoke();
- if (taskReads === 6 && point === 'task-mode') taskMode = 'plan';
+ if (reserved) ++reservedTaskReads;
+ if (reservedTaskReads === 3 && point === 'final-task') revoke();
+ if (reservedTaskReads === 3 && point === 'task-mode') taskMode = 'plan';
+ // A registration already past its reservation check commits while the
+ // post-reservation service read drains the existing receipt queue.
+ if (reservedTaskReads === 2 && point.startsWith('queued-plan-')) {
+ receipt.payload = JSON.stringify({ teamPlan: { concurrency: 2, items: [{ ...planItem,
+ label: point === 'queued-plan-excludes' ? 'other' : 'sample',
+ route: { ...planItem.route, model: point === 'queued-plan-route' ? 'gpt-5.4' : 'gpt-5.5' },
+ }] } });
+ }
return task();
} }),
readGhostErrandConfig: () => ({ permissionMode: mode, workingDir: path.resolve('repo') }),
@@@ -2816,43 -2824,13 +2825,43 @@@
...(point === 'different-model' ? { model: 'gpt-5.4' } : {}),
...(point === 'normalized-fast' ? { fast: true } : {}),
});
- if (['healthy', 'explicit-match', 'canonical-directory'].includes(point)) {
+ if (['healthy', 'explicit-match', 'canonical-directory', 'queued-plan-matches'].includes(point)) {
await expect(result).resolves.toMatchObject({ ok: true });
expect(deps.bootstrapSession).toHaveBeenCalledOnce();
+ } else if (['different-model', 'different-directory', 'normalized-fast'].includes(point)) {
+ // The child PR checks under the Lead send lock before reserving too.
+ await expect(result).resolves.toMatchObject({ ok: false, message: 'Worker configuration differs from registered plan' });
+ expect(deps.reserveWorkerCreation).not.toHaveBeenCalled();
+ expect(deps.bootstrapSession).not.toHaveBeenCalled();
} else {
- await expect(result).rejects.toMatchObject({ code: point === 'changed-plan' ? 'INVALID_REQUEST' : 'PERMISSION_DENIED' });
+ await expect(result).rejects.toMatchObject({ code: ['different-model', 'different-directory', 'normalized-fast', 'changed-plan', 'queued-plan-excludes', 'queued-plan-route'].includes(point) ? 'INVALID_REQUEST' : 'PERMISSION_DENIED' });
expect(deps.bootstrapSession).not.toHaveBeenCalled();
}
- expect(deps.releaseWorkerCreationReservation).toHaveBeenCalledTimes(1);
+ expect(deps.releaseWorkerCreationReservation).toHaveBeenCalledTimes(reserved ? 1 : 0);
});
});
+it('rechecks a newly registered plan under the Lead send lock before reserving', async () => {
+ let locked = false, limit: number | undefined;
+ const {deps,service}=createDeps({
+ validateCreationPlan: vi.fn(async () => limit),
+ withLeadSendLock: async (_id, operation) => {
+ limit = 1; locked = true;
+ try { return await operation(); } finally { locked = false; }
+ },
+ });
+ vi.mocked(deps.reserveWorkerCreation).mockImplementation(async input => {
+ expect(locked).toBe(true);expect(input.hardLimit).toBe(1);
+ return {ok:true,occupiedSlotsBefore:0};
+ });
+ const bootstrap=deps.bootstrapSession;
+ deps.bootstrapSession=vi.fn(async (opts: MakerSessionCreateOpts) => {expect(locked).toBe(false);return bootstrap(opts);});
+ await service.createWorker({leadSessionId:'lead-1',role:'eval',agent:'codex',label:'sample'});
+ expect(deps.validateCreationPlan).toHaveBeenCalledTimes(3);
+ expect(deps.reserveWorkerCreation).toHaveBeenCalledOnce();
+});
+it('rejects a plan changed during preparation without reserving or bootstrapping', async () => {
+ const validate=vi.fn().mockResolvedValueOnce(undefined).mockRejectedValueOnce(new Error('not pending'));
+ const {deps,service}=createDeps({validateCreationPlan:validate,withLeadSendLock:async (_id, operation)=>operation()});
+ const result=await service.createWorker({leadSessionId:'lead-1',role:'eval',agent:'codex',label:'sample'});
+ expect(result.ok).toBe(false);expect(deps.reserveWorkerCreation).not.toHaveBeenCalled();expect(deps.bootstrapSession).not.toHaveBeenCalled();
+});
diff --cc apps/desktop/src/main/maker-ipc/register.ts
index f2b812af2c,9d03d9548b..71a41eaf45
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@@ -11853,10 -11845,14 +11878,14 @@@ export function registerMakerIpc(maker
});
const directory = await resolveAuthorizedDirectory(params.workingDir ?? task.workingDir ?? '');
if (resolvedWorkingDir !== undefined && directory !== await resolveAuthorizedDirectory(resolvedWorkingDir)) throw new PluginTaskError('PERMISSION_DENIED','Worker directory changed during creation');
- // get() waits behind plan registration in the existing receipt queue.
+ // Drain plan registration before taking the receipt snapshot. Waiting only
+ // after this read leaves a stale no-plan payload even when get() sees the
+ // newly persisted plan. Keep the final task check after directory awaits.
+ await pluginTaskServiceForCurrentOwner!().get(receipt.pluginId,params.leadSessionId);
+ if (epoch !== getCurrentDbClientSnapshot()) throw new PluginTaskError('PERMISSION_DENIED','Account changed');
const currentReceipt = await createPluginTaskStore(epoch.client).get(params.leadSessionId);
- if (!currentReceipt) throw new PluginTaskError('TASK_NOT_FOUND', 'Task not found');
- const data = JSON.parse(currentReceipt.payload);
+ if (!currentReceipt || currentReceipt.operation !== 'create' || epoch !== getCurrentDbClientSnapshot()) throw new PluginTaskError('PERMISSION_DENIED', 'Task ownership changed');
+ const data = readPluginTaskPlanReceipt(currentReceipt.payload);
const item = data.teamPlan?.items.find((x: {label:string})=>x.label===params.label);
const plannedDirectory = item && resolvedRoute
? await resolveAuthorizedDirectory(item.workingDir) : undefined;