Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(plugins): 统一 Worker 标签并拒绝归档任务创建
Dash6cf17b2bf794
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaLifecycleService.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaLifecycleService.test.tsindex faf0951f04..3a82d05e89 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaLifecycleService.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaLifecycleService.test.ts@@ -1014,6 +1014,29 @@ describe('retained tasks after explicit plugin uninstall', () => {const helper = source.slice(source.indexOf(' const assertPluginWorkerAutoAuthorized ='), source.indexOf(' const orcaWorkerCreationService ='));const callback = source.slice(source.indexOf(' getWorkerPermissionModeOverride: async (leadSessionId) => {'), source.indexOf(' setWorkerPermissionMode: applyWorkerPermissionModePreference,'));const js = ts.transpileModule(`${helper}\nreturn ({${callback}}).getWorkerPermissionModeOverride;`, { compilerOptions: { target: ts.ScriptTarget.ES2022 } }).outputText;+ it.each(['enableTeam', 'startTeam', 'createWorker'] as const)('requires an active plugin task for %s', async action => {+ for (const status of ['active', 'archived']) {+ const epoch = { client: {} };+ const callbacks = { getCurrentDbClientSnapshot: () => epoch, PluginTaskError,+ createPluginTaskStore: () => ({ get: async () => ({ operation: 'create', pluginId: 'plugin', payload: '{}' }) }),+ pluginTaskServiceForCurrentOwner: () => ({ get: async () => ({ status, permissionMode: 'auto' }) }),+ isPluginTaskAuthorized: () => true, readGhostErrandConfig: () => ({ permissionMode: 'auto' }),+ };+ const override = new Function(...Object.keys(callbacks), js)(...Object.values(callbacks));+ const { deps, service } = createDeps({ getWorkerPermissionModeOverride: override,+ getActiveTeamByLead: vi.fn(async () => action === 'createWorker' ? activeTeam() : null),+ });+ const result = action === 'enableTeam' ? service.enableTeam({ leadSessionId: 'lead-1', workerAgent: 'codex', role: 'worker', label: 'sample' })+ : action === 'startTeam' ? service.startTeam({ leadSessionId: 'lead-1' })+ : service.createWorker({ leadSessionId: 'lead-1', agent: 'codex', role: 'worker', label: 'sample' });+ if (status === 'active') await expect(result).resolves.toMatchObject({ ok: true });+ else {+ await expect(result).rejects.toMatchObject({ code: 'TASK_BUSY' });+ expect(deps.createWorkerInTeam).not.toHaveBeenCalled();+ expect(deps.createActiveTeam).not.toHaveBeenCalled();+ }+ }+ });it.each(['enableTeam', 'startTeam', 'createWorker'] as const)('uses ordinary permissions for %s with a retained revoked receipt', async action => {const epoch = { client: {} }, get = vi.fn(async () => { throw new PluginTaskError('TASK_NOT_FOUND', 'Revoked'); });const callbacks = { getCurrentDbClientSnapshot: () => epoch, PluginTaskError,diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.tsindex 4bafe00b92..71efff209b 100644--- 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 @@ describe('SSH remote worker model/provider compatibility gate (R23 P2)', () => {});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 () => {+ 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);+ 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,21 +2791,22 @@ 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 })),+ ...[false, true].flatMap(planned => ['reservation', 'directory', 'receipt', 'final-task', 'task-mode', 'disabled', 'healthy', 'archive-first', '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;let mode = 'auto';let taskMode = 'auto';+ let taskStatus = point === 'archive-first' ? 'archived' : 'active';let enabled = true;let receiptReads = 0;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 = {getCurrentDbClientSnapshot: () => epoch,@@ -2805,6 +2815,7 @@ describe('production plugin Auto admission after reservation', () => {if (reserved) ++reservedTaskReads;if (reservedTaskReads === 3 && point === 'final-task') revoke();if (reservedTaskReads === 3 && point === 'task-mode') taskMode = 'plan';+ if (reservedTaskReads === 3 && point === 'archive-final') taskStatus = 'archived';// 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-')) {@@ -2833,24 +2844,25 @@ describe('production plugin Auto admission after reservation', () => {const result = await reserve(input); reserved = true;if (point === 'reservation') revoke();if (point === 'disabled') enabled = false;+ if (point === 'archive-reservation') taskStatus = 'archived';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',+ const result = service.createWorker({ leadSessionId: 'lead-1', role: 'eval', agent: 'codex', label: ['normalized-label', 'settled-label'].includes(point) ? ' SAMPLE ' : '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', '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 {- 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(1);+ expect(deps.releaseWorkerCreationReservation).toHaveBeenCalledTimes(['archive-first', 'settled-label'].includes(point) ? 0 : 1);});});diff --git a/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts b/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.tsindex 9549f2e5a6..5a87382045 100644--- a/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts+++ b/apps/desktop/src/main/maker-ipc/orcaWorkerCreationService.ts@@ -620,6 +620,7 @@ export function createOrcaWorkerCreationService(deps: OrcaWorkerCreationDeps): O}const label = normalizeOrcaWorkerLabel(params.label);if (!label.ok) return { ok: false, errorCode: 'INVALID_PARAMS', message: label.message };+ params = { ...params, label: label.value };const existing = await deps.listWorkersByLead(params.leadSessionId);if (existing.some((worker) => worker.label?.toLowerCase() === label.value)) {diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex 634df5cca9..d94948db49 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -11856,7 +11856,10 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)getCatalog: getActiveCatalog,});- const assertPluginWorkerAutoAuthorized = (pluginId: string, task: { permissionMode?: string }) => {+ const assertPluginWorkerAutoAuthorized = (pluginId: string, task: { status: string; permissionMode?: string }) => {+ if (task.status !== 'active') {+ throw new PluginTaskError('TASK_BUSY', 'Archived tasks cannot create Workers');+ }if (!isPluginTaskAuthorized(pluginId) || task.permissionMode !== 'auto' || readGhostErrandConfig(pluginId).permissionMode !== 'auto') {throw new PluginTaskError('PERMISSION_DENIED', 'Authorize Auto for the plugin coordinator before creating Workers');}