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: 同步父分支 Worker 准入修复

Dashed6e99c39875
diff --cc apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
index afc4ea02a0,71efff209b..6d2c3e2f0f
--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
@@@ -2728,6 -2728,15 +2728,15 @@@ describe('SSH remote worker model/provi
});
it('applies plan limit in atomic reservation',async()=>{const {deps,service}=createDeps({validateCreationPlan:vi.fn(async()=>2)});await service.createWorker({leadSessionId:'lead-1',role:'eval',agent:'codex',label:'sample'});expect(deps.reserveWorkerCreation).toHaveBeenCalledWith(expect.objectContaining({hardLimit:2}));});
-it('uses one canonical label at both plan checks without mutating the caller', async () => {
++it('uses one canonical label at all three plan checks without mutating the caller', async () => {
+ const validateCreationPlan = vi.fn(async (_params: OrcaWorkerCreateParams) => 2);
+ const { service } = createDeps({ validateCreationPlan });
+ const params = Object.freeze({ leadSessionId: 'lead-1', teamId: 'team-1', role: 'eval', agent: 'codex' as const, label: ' SAMPLE ', workerPermissionMode: 'auto' as const });
+ await expect(service.createWorkerInTeam(params)).resolves.toMatchObject({ ok: true });
- expect(validateCreationPlan).toHaveBeenCalledTimes(2);
++ expect(validateCreationPlan).toHaveBeenCalledTimes(3);
+ for (const call of validateCreationPlan.mock.calls) expect(call[0]).toMatchObject({ label: 'sample' });
+ expect(params.label).toBe(' SAMPLE ');
+ });
it('rejects invalid plan before reservation',async()=>{const {deps,service}=createDeps({validateCreationPlan:vi.fn(async()=>{throw Error('not pending');})});await expect(service.createWorker({leadSessionId:'lead-1',role:'eval',agent:'codex',label:'sample'})).rejects.toThrow('not pending');expect(deps.reserveWorkerCreation).not.toHaveBeenCalled();expect(deps.bootstrapSession).not.toHaveBeenCalled();});
it('revalidates a plan registered during creation preflight and releases the reservation on rejection', async () => {
let reserved = false;
@@@ -2782,8 -2791,8 +2791,8 @@@ describe('production plugin Auto admiss
});
it.each([
- ...[false, true].flatMap(planned => ['reservation', 'directory', 'receipt', 'final-task', 'task-mode', 'disabled', 'healthy'].map(point => ({ planned, point }))),
- ...['explicit-match', 'canonical-directory', 'different-model', 'different-directory', 'normalized-fast', 'changed-plan'].map(point => ({ planned: true, point })),
- ...[false, true].flatMap(planned => ['reservation', 'directory', 'receipt', 'final-task', 'task-mode', 'disabled', 'healthy', 'archive-first', 'archive-reservation', 'archive-final'].map(point => ({ planned, point }))),
++ ...[false, true].flatMap(planned => ['reservation', 'directory', 'receipt', 'final-task', 'task-mode', 'disabled', 'healthy', 'archive-first', 'archive-admission', 'archive-reservation', 'archive-final'].map(point => ({ planned, point }))),
+ ...['explicit-match', 'canonical-directory', 'different-model', 'different-directory', 'normalized-fast', 'changed-plan', 'normalized-label', 'settled-label'].map(point => ({ planned: true, point })),
...['queued-plan-excludes', 'queued-plan-route', 'queued-plan-matches'].map(point => ({ planned: false, point })),
])('checks $point with planned=$planned before bootstrap', async ({ planned, point }) => {
let reserved = false;
@@@ -2794,14 -2804,13 +2804,14 @@@
let reservedTaskReads = 0;
const epoch = { client: {} };
const revoke = () => { mode = 'acceptEdits'; };
- const task = () => ({ revision: 1, permissionMode: taskMode, workingDir: path.resolve('repo') });
+ const task = () => ({ revision: 1, status: taskStatus, permissionMode: taskMode, workingDir: path.resolve('repo') });
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 payload = () => JSON.stringify(planned ? { teamPlan: { concurrency: 2, items: [planItem] }, settledLabels: point === 'settled-label' ? ['sample'] : [] } : {});
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 structuredClone(receipt); } }),
+ createPluginTaskStore: () => ({ get: async () => { if (++receiptReads === 6 && point === 'receipt') revoke(); return structuredClone(receipt); } }),
pluginTaskServiceForCurrentOwner: () => ({ get: async () => {
if (reserved) ++reservedTaskReads;
if (reservedTaskReads === 3 && point === 'final-task') revoke();
@@@ -2824,7 -2834,7 +2835,10 @@@
PluginTaskError,
};
const validateCreationPlan = new Function(...Object.keys(depsForCallback), js)(...Object.values(depsForCallback));
-- const { deps, service } = createDeps({ validateCreationPlan });
++ const { deps, service } = createDeps({ validateCreationPlan, withLeadSendLock: async (_id, operation) => {
++ if (point === 'archive-admission') taskStatus = 'archived';
++ return operation();
++ } });
if (point === 'normalized-fast') {
const models = deps.getAvailableModels;
deps.getAvailableModels = agent => models(agent).map(model => ({ ...model, supportsFastMode: false }));
@@@ -2845,43 -2856,13 +2860,43 @@@
...(point === 'different-model' ? { model: 'gpt-5.4' } : {}),
...(point === 'normalized-fast' ? { fast: true } : {}),
});
- if (['healthy', 'explicit-match', 'canonical-directory', 'queued-plan-matches'].includes(point)) {
+ if (['healthy', 'explicit-match', 'canonical-directory', 'queued-plan-matches', 'normalized-label'].includes(point)) {
await expect(result).resolves.toMatchObject({ ok: true });
expect(deps.bootstrapSession).toHaveBeenCalledOnce();
- } else if (['different-model', 'different-directory', 'normalized-fast'].includes(point)) {
++ } else if (['different-model', 'different-directory', 'normalized-fast', 'archive-admission'].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' });
++ await expect(result).resolves.toMatchObject({ ok: false, message: point === 'archive-admission' ? 'Archived tasks cannot create Workers' : 'Worker configuration differs from registered plan' });
+ expect(deps.reserveWorkerCreation).not.toHaveBeenCalled();
+ expect(deps.bootstrapSession).not.toHaveBeenCalled();
} else {
- 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' });
+ await expect(result).rejects.toMatchObject({ code: point.startsWith('archive-') ? 'TASK_BUSY' : ['different-model', 'different-directory', 'normalized-fast', 'changed-plan', 'queued-plan-excludes', 'queued-plan-route', 'settled-label'].includes(point) ? 'INVALID_REQUEST' : 'PERMISSION_DENIED' });
expect(deps.bootstrapSession).not.toHaveBeenCalled();
}
- expect(deps.releaseWorkerCreationReservation).toHaveBeenCalledTimes(['archive-first', 'settled-label'].includes(point) ? 0 : 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();
});