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 worker default validation

Dash01ce8c3b7f14
diff --cc apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
index 5031b22b66,e38c88c6e4..0c048beba1
--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
@@@ -2771,15 -2774,16 +2774,17 @@@ describe('production plugin Auto admiss
const epoch = { client: {} };
const revoke = () => { mode = 'acceptEdits'; };
const task = () => ({ revision: 1, permissionMode: taskMode, workingDir: path.resolve('repo') });
- const receipt = { pluginId: 'plugin', operation: 'create', payload: JSON.stringify(planned ? { teamPlan: { concurrency: 2, items: [{ label: 'sample', route: { agentKind: 'codex' } }] } } : {}) };
+ const planItem = { label: 'sample', workingDir: path.resolve(point === 'canonical-directory' ? 'alias' : point === 'different-directory' ? 'other' : 'repo'), route: { agentKind: 'codex', model: 'gpt-5.5', providerId: 'xd', effort: 'medium', fastMode: point === 'normalized-fast' } };
+ 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 === 4 && point === 'receipt') revoke(); return receipt; } }),
+ createPluginTaskStore: () => ({ get: async () => { if (++receiptReads === 6 && point === 'receipt') revoke(); return receipt; } }),
pluginTaskServiceForCurrentOwner: () => ({ get: async () => {
++taskReads;
- if (taskReads === 4 && point === 'final-task') revoke();
- if (taskReads === 4 && point === 'task-mode') taskMode = 'plan';
+ if (taskReads === 6 && point === 'final-task') revoke();
+ if (taskReads === 6 && point === 'task-mode') taskMode = 'plan';
return task();
} }),
readGhostErrandConfig: () => ({ permissionMode: mode, workingDir: path.resolve('repo') }),
@@@ -2796,41 -2804,24 +2805,54 @@@
const result = await reserve(input); reserved = true;
if (point === 'reservation') revoke();
if (point === 'disabled') enabled = false;
+ if (point === 'changed-plan') {
+ planItem.route.model = 'gpt-5.4';
+ receipt.payload = payload();
+ }
return result;
});
- const result = service.createWorker({ leadSessionId: 'lead-1', role: 'eval', agent: 'codex', label: 'sample', workerPermissionMode: 'auto' });
- if (point === 'healthy') {
+ const result = service.createWorker({ leadSessionId: 'lead-1', role: 'eval', agent: 'codex', label: 'sample', workerPermissionMode: 'auto',
+ ...(point === 'explicit-match' ? { model: 'gpt-5.5', providerId: 'xd', effort: 'medium', fast: false, workingDir: path.resolve('repo') } : {}),
+ ...(point === 'different-model' ? { model: 'gpt-5.4' } : {}),
+ ...(point === 'normalized-fast' ? { fast: true } : {}),
+ });
+ if (['healthy', 'explicit-match', 'canonical-directory'].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: 'PERMISSION_DENIED' });
- await expect(result).rejects.toMatchObject({ code: ['different-model', 'different-directory', 'normalized-fast', 'changed-plan'].includes(point) ? 'INVALID_REQUEST' : 'PERMISSION_DENIED' });
++ await expect(result).rejects.toMatchObject({ code: point === 'changed-plan' ? '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/orcaWorkerCreationService.ts
index 44268d56e3,9549f2e5a6..2897ce81ea
--- a/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts
+++ b/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts
@@@ -208,8 -208,8 +208,9 @@@ export interface OrcaWorkerCreationDep
getActiveTeamByLead(leadSessionId: string): Promise<OrcaTeamSnapshot | null>;
listWorkersByLead(leadSessionId: string): Promise<OrcaWorkerListSnapshot[]>;
isActiveWorkerStatus(status: OrcaWorkerStatus): boolean;
+ withLeadSendLock?<T>(leadSessionId: string, operation: () => Promise<T>): Promise<T>;
- validateCreationPlan?(params: OrcaWorkerCreateInTeamParams, resolvedWorkingDir?: string): Promise<number | null | undefined>;
+ validateCreationPlan?(params: OrcaWorkerCreateInTeamParams, resolvedWorkingDir?: string,
+ resolvedRoute?: { model: string; providerId: string | null; effort: string | null; fastMode: boolean }): Promise<number | null | undefined>;
readCollaborationSettings(): { workerSoftLimit: number; workerHardLimit: number };
getLeadSessionRow(leadSessionId: string): Promise<OrcaLeadSessionSnapshot | null>;
getWorkerDefaults(agent: AgentKind): OrcaWorkerDefaultsSnapshot;
@@@ -991,23 -991,13 +992,23 @@@ export function createOrcaWorkerCreatio
| { ok: true; occupiedSlotsBefore: number }
| { ok: false; errorCode: 'DUPLICATE_LABEL' | 'WORKER_CREATION_IN_PROGRESS' | 'WORKER_LIMIT_HARD_EXCEEDED' };
try {
- reservation = await deps.reserveWorkerCreation({
- reservationId: workerId,
- teamId: params.teamId,
- label: label.value,
- hardLimit: settings.workerHardLimit,
- leaseMs: ORCA_WORKER_CREATION_RESERVATION_LEASE_MS,
- });
+ const admit = async () => {
+ // Preparation may await providers or remote state. Re-read the plan at
+ // the final admission boundary shared with plan registration and input.
- const latestLimit = await deps.validateCreationPlan?.(params, workingDir);
++ const latestLimit = await deps.validateCreationPlan?.(params, workingDir, resolved);
+ settings.workerHardLimit = deps.readCollaborationSettings().workerHardLimit;
+ if (latestLimit != null) settings.workerHardLimit = Math.min(settings.workerHardLimit, latestLimit);
+ return deps.reserveWorkerCreation({
+ reservationId: workerId,
+ teamId: params.teamId,
+ label: label.value,
+ hardLimit: settings.workerHardLimit,
+ leaseMs: ORCA_WORKER_CREATION_RESERVATION_LEASE_MS,
+ });
+ };
+ reservation = deps.withLeadSendLock
+ ? await deps.withLeadSendLock(params.leadSessionId, admit)
+ : await admit();
} catch (err) {
return toInternalFailure(err);
}
diff --cc apps/desktop/src/main/maker-ipc/register.ts
index 2c4e777263,d8f04f85e6..2d35262834
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@@ -11724,10 -11691,10 +11724,10 @@@ export function registerMakerIpc(maker
listWorkersByLead,
isActiveWorkerStatus,
readCollaborationSettings,
- validateCreationPlan: async (params, resolvedWorkingDir) => {
+ validateCreationPlan: async (params, resolvedWorkingDir, resolvedRoute) => {
const epoch = getCurrentDbClientSnapshot();
if (!epoch) throw new PluginTaskError('HOST_NOT_READY','Task storage unavailable');
- const receipt = await createPluginTaskStore(epoch.client).get(params.leadSessionId);
+ let receipt = await createPluginTaskStore(epoch.client).get(params.leadSessionId);
if (!receipt || receipt.operation !== 'create') return undefined;
const task = await pluginTaskServiceForCurrentOwner!().get(receipt.pluginId,params.leadSessionId);
if (epoch !== getCurrentDbClientSnapshot()) throw new PluginTaskError('PERMISSION_DENIED','Account changed');
@@@ -11743,7 -11710,11 +11743,11 @@@
if (resolvedWorkingDir !== undefined && directory !== await realpathWorkingDirectory(resolvedWorkingDir)) throw new PluginTaskError('PERMISSION_DENIED','Worker directory changed during creation');
// get() waits behind plan registration in the existing receipt queue.
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 realpathWorkingDirectory(item.workingDir) : undefined;
const currentTask = await pluginTaskServiceForCurrentOwner!().get(receipt.pluginId,params.leadSessionId);
if (epoch !== getCurrentDbClientSnapshot() || currentTask.revision !== task.revision) throw new PluginTaskError('STALE_REVISION','Task changed during directory validation');
// Last admission check also covers no-plan plugin tasks and revocation