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(plugins): drain plan registration before worker admission snapshot

Dashe8139153b874
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
index c1d038b577..ef072557d2 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
@@ -2764,13 +2764,14 @@ describe('production plugin Auto admission after reservation', () => {
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 })),
+ ...['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;
let mode = 'auto';
let taskMode = 'auto';
let enabled = true;
let receiptReads = 0;
- let taskReads = 0;
+ let reservedTaskReads = 0;
const epoch = { client: {} };
const revoke = () => { mode = 'acceptEdits'; };
const task = () => ({ revision: 1, permissionMode: taskMode, workingDir: path.resolve('repo') });
@@ -2779,11 +2780,19 @@ describe('production plugin Auto admission after reservation', () => {
const receipt = { pluginId: 'plugin', operation: 'create', payload: payload() };
const depsForCallback = {
getCurrentDbClientSnapshot: () => epoch,
- createPluginTaskStore: () => ({ get: async () => { if (++receiptReads === 4 && point === 'receipt') revoke(); return receipt; } }),
+ createPluginTaskStore: () => ({ get: async () => { if (++receiptReads === 4 && point === 'receipt') revoke(); return structuredClone(receipt); } }),
pluginTaskServiceForCurrentOwner: () => ({ get: async () => {
- ++taskReads;
- if (taskReads === 4 && point === 'final-task') revoke();
- if (taskReads === 4 && 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') }),
@@ -2815,11 +2824,11 @@ describe('production plugin Auto admission after reservation', () => {
...(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 {
- 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: ['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);
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index 95dc104e6f..9d03d9548b 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -11845,7 +11845,11 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
});
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);