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): keep retained tasks usable after uninstall

Dashb8b403498034
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaLifecycleService.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaLifecycleService.test.ts
index 8458a02124..faf0951f04 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaLifecycleService.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaLifecycleService.test.ts
@@ -1,3 +1,6 @@
+import { readFileSync } from 'node:fs';
+import ts from 'typescript';
+import { PluginTaskError } from '../pluginTaskService.js';
import type { AgentKind } from '@cindy/maker-core';
import { describe, expect, it, vi } from 'vitest';
@@ -1004,3 +1007,31 @@ describe('host-scoped Worker permissions', () => {
expect(deps.setWorkerPermissionMode).not.toHaveBeenCalled();
});
});
+
+
+describe('retained tasks after explicit plugin uninstall', () => {
+ const source = readFileSync(new URL('../register.ts', import.meta.url), 'utf8');
+ 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)('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,
+ createPluginTaskStore: () => ({ get: async () => ({ operation: 'create', pluginId: 'plugin', payload: JSON.stringify({ ownershipRevoked: true }) }) }),
+ pluginTaskServiceForCurrentOwner: () => ({ get }), isPluginTaskAuthorized: () => false,
+ readGhostErrandConfig: () => ({ permissionMode: 'auto' }),
+ };
+ const override = new Function(...Object.keys(callbacks), js)(...Object.values(callbacks));
+ const { deps, service } = createDeps({
+ getWorkerPermissionModeOverride: override,
+ getWorkerPermissionMode: () => 'bypassPermissions',
+ 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' });
+ await expect(result).resolves.toMatchObject({ ok: true });
+ expect(get).not.toHaveBeenCalled();
+ if (action !== 'startTeam') expect(deps.createWorkerInTeam).toHaveBeenCalledWith(expect.objectContaining({ workerPermissionMode: 'bypassPermissions' }));
+ });
+});
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 ef072557d2..4bafe00b92 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaWorkerCreationService.test.ts
@@ -2761,6 +2761,26 @@ describe('production plugin Auto admission after reservation', () => {
const callback = source.slice(source.indexOf(' validateCreationPlan: async (params, resolvedWorkingDir, resolvedRoute) => {'), source.indexOf(' getLeadSessionRow: async (leadSessionId) => {'));
const js = ts.transpileModule(`${helper}\nreturn ({${callback}}).validateCreationPlan;`, { compilerOptions: { target: ts.ScriptTarget.ES2022 } }).outputText;
+ it.each(['uninstalled', 'reinstalled', 'malformed'])('keeps ordinary Worker creation separate from %s plugin receipts', async state => {
+ const epoch = { client: {} }, get = vi.fn(async () => { throw new PluginTaskError('TASK_NOT_FOUND', 'Not owned'); });
+ const callbackDeps = { getCurrentDbClientSnapshot: () => epoch, PluginTaskError,
+ createPluginTaskStore: () => ({ get: async () => ({ operation: 'create', pluginId: 'plugin', payload: state === 'malformed' ? '{' : JSON.stringify({ ownershipRevoked: true, teamPlan: { items: [] } }) }) }),
+ pluginTaskServiceForCurrentOwner: () => ({ get }), isPluginTaskAuthorized: () => state === 'reinstalled',
+ readGhostErrandConfig: () => ({ permissionMode: 'auto' }),
+ };
+ const validateCreationPlan = new Function(...Object.keys(callbackDeps), js)(...Object.values(callbackDeps));
+ const { deps, service } = createDeps({ validateCreationPlan });
+ const result = service.createWorker({ leadSessionId: 'lead-1', role: 'worker', label: 'sample', agent: 'codex' });
+ if (state === 'malformed') {
+ await expect(result).rejects.toMatchObject({ code: 'TASK_NOT_FOUND' });
+ expect(deps.bootstrapSession).not.toHaveBeenCalled();
+ } else {
+ await expect(result).resolves.toMatchObject({ ok: true });
+ expect(get).not.toHaveBeenCalled();
+ expect(deps.bootstrapSession).toHaveBeenCalledOnce();
+ }
+ });
+
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 })),
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index 8cdbac7e3b..634df5cca9 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -11862,6 +11862,13 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
}
};
+ // Uninstall keeps the historical receipt, but ordinary Orca belongs to the user.
+ // Malformed receipts still go through the service's fail-closed ownership check.
+ const hasRevokedPluginTaskOwnership = (receipt: { payload: string }): boolean => {
+ try { return JSON.parse(receipt.payload)?.ownershipRevoked === true; }
+ catch { return false; }
+ };
+
const orcaWorkerCreationService = createOrcaWorkerCreationService({
getActiveTeamByLead,
listWorkersByLead,
@@ -11871,7 +11878,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
const epoch = getCurrentDbClientSnapshot();
if (!epoch) throw new PluginTaskError('HOST_NOT_READY','Task storage unavailable');
const receipt = await createPluginTaskStore(epoch.client).get(params.leadSessionId);
- if (!receipt || receipt.operation !== 'create') return undefined;
+ if (!receipt || receipt.operation !== 'create' || hasRevokedPluginTaskOwnership(receipt)) return undefined;
const task = await pluginTaskServiceForCurrentOwner!().get(receipt.pluginId,params.leadSessionId);
if (epoch !== getCurrentDbClientSnapshot()) throw new PluginTaskError('PERMISSION_DENIED','Account changed');
assertPluginWorkerAutoAuthorized(receipt.pluginId, task);
@@ -12013,7 +12020,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
const epoch = getCurrentDbClientSnapshot();
if (!epoch) throw new PluginTaskError('HOST_NOT_READY', 'Task storage unavailable', true);
const receipt = await createPluginTaskStore(epoch.client).get(leadSessionId);
- if (!receipt || receipt.operation !== 'create') return undefined;
+ if (!receipt || receipt.operation !== 'create' || hasRevokedPluginTaskOwnership(receipt)) return undefined;
const task = await pluginTaskServiceForCurrentOwner!().get(receipt.pluginId, leadSessionId);
if (epoch !== getCurrentDbClientSnapshot()) throw new PluginTaskError('PERMISSION_DENIED', 'Account changed');
// Plugin tasks never inherit an unrelated global Full access preference.