Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(plugins): serialize plan admission and retain empty consent boundaries
Dash91e56347a521
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.tsindex 1c0d0ce082..be21624ca7 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts@@ -2744,7 +2744,7 @@ it('revalidates a plan registered during creation preflight and releases the resit('checks the resolved creation directory before bootstrap and releases a rejected reservation', async () => {const resolved = path.resolve('resolved-candidate');const validateCreationPlan = vi.fn(async (_params, directory?: string) => {- if (directory !== undefined) throw new Error('Directory authorization revoked');+ if (directory !== undefined && validateCreationPlan.mock.calls.length >= 3) throw new Error('Directory authorization revoked');return undefined;});const {deps, service} = createDeps({validateCreationPlan, resolveWorkerWorkingDir: vi.fn(async () => resolved)});@@ -2808,3 +2808,28 @@ describe('production plugin Auto admission after reservation', () => {expect(deps.releaseWorkerCreationReservation).toHaveBeenCalledTimes(1);});});+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 --git a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskAuthorshipWiring.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskAuthorshipWiring.test.tsindex f54b534c5c..a1105e6bde 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskAuthorshipWiring.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskAuthorshipWiring.test.ts@@ -97,3 +97,11 @@ it('aborts both internal delegated entry points when authorization history cannoexpect(restore).not.toHaveBeenCalled();}});++it('shares the Lead send lock across whole plan registration and final Worker admission', () => {+ expect(source).toContain("case 'setTeamPlan': return withSendToSessionLock(request.taskId, () => service.setTeamPlan(pluginId, request.taskId, request.plan));");+ const start=source.indexOf('const orcaWorkerCreationService = createOrcaWorkerCreationService({');+ const block=source.slice(start, source.indexOf('getLeadSessionRow:',start));+ expect(block).toContain('withLeadSendLock: withSendToSessionLock');+ expect(block.lastIndexOf('createPluginTaskStore(epoch.client).get')).toBeGreaterThan(block.indexOf('pluginTaskServiceForCurrentOwner!().get'));+});diff --git a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskReviewContext.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskReviewContext.test.tsindex d37aeafd61..9b60d86e61 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskReviewContext.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskReviewContext.test.ts@@ -66,6 +66,16 @@ describe('plugin delegated Auto context', () => {expect(result.userIntent).toBe(text);expect(JSON.stringify(result.userIntent)).not.toContain('Send this');});+ it.each([false, true])('marks tied resource resets and grants ambiguous regardless of flattening order (%s)', async reverse => {+ const s = fixture();+ s.history = [+ {clientId: 'lead-resource', role: 'user', createdAt: 10, content: {files: [{name: 'new.txt'}]}, agentMeta: {autoReviewUserText: '', delivery: 'turn'}},+ {clientId: 'worker-grant', role: 'user', createdAt: 10, content: {text: 'Send this'}, agentMeta: {autoReviewUserText: 'Send this', delivery: 'turn'}},+ ];+ if (reverse) s.history.reverse();+ const result = await createPluginTaskReviewResolver(async () => s)(request);+ expect(result.userIntent).toMatchObject({historyOmitted: true});+ });it('uses only authenticated plan text, never Worker/Lead claims as user intent', async () => {const result = await createPluginTaskReviewResolver(async () => fixture())(request);expect(result.authorizationError).toBeUndefined();diff --git a/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts b/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.tsindex c21ceb3b4a..44268d56e3 100644--- a/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts+++ b/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts@@ -208,6 +208,7 @@ export interface OrcaWorkerCreationDeps {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>;readCollaborationSettings(): { workerSoftLimit: number; workerHardLimit: number };getLeadSessionRow(leadSessionId: string): Promise<OrcaLeadSessionSnapshot | null>;@@ -990,13 +991,23 @@ export function createOrcaWorkerCreationService(deps: OrcaWorkerCreationDeps): O| { 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);+ 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 --git a/apps/desktop/src/main/maker-ipc/pluginTaskReviewContext.ts b/apps/desktop/src/main/maker-ipc/pluginTaskReviewContext.tsindex 7f604cc008..18d5824a10 100644--- a/apps/desktop/src/main/maker-ipc/pluginTaskReviewContext.ts+++ b/apps/desktop/src/main/maker-ipc/pluginTaskReviewContext.ts@@ -36,9 +36,10 @@ export function pluginReviewUserIntent(snapshot: PluginReviewSnapshot): AutoReviconst times = new Set<number>();for (const m of [...snapshot.history].sort((a, b) => eventTime(a) - eventTime(b))) {const receipt = m.agentMeta?.autoReviewUserText;- const text = typeof receipt === 'string' ? receipt- : receipt && typeof receipt === 'object' && 'text' in receipt ? receipt.text : '';- if (text) {+ // Empty authored receipts reset earlier resource consent and need ordering too.+ const authored = typeof receipt === 'string' || (receipt && typeof receipt === 'object'+ && 'text' in receipt && typeof receipt.text === 'string');+ if (authored) {const at = eventTime(m);if (!Number.isFinite(at) || at <= 0 || times.has(at)) omitted = true;times.add(at);diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex f18250d2a8..43467c4327 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -11540,6 +11540,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)};const orcaWorkerCreationService = createOrcaWorkerCreationService({+ withLeadSendLock: withSendToSessionLock,getActiveTeamByLead,listWorkersByLead,isActiveWorkerStatus,@@ -11547,7 +11548,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)validateCreationPlan: async (params, resolvedWorkingDir) => {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');@@ -11563,7 +11564,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)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');+ if (!currentReceipt || currentReceipt.operation !== 'create' || epoch !== getCurrentDbClientSnapshot()) throw new PluginTaskError('PERMISSION_DENIED', 'Task ownership changed');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