Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix: recheck all session move restrictions before commit
Dasha7965bc0d2c4
diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/moveSession.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/moveSession.test.tsindex 119711c968..b1617631ad 100644--- a/apps/desktop/src/main/mcp-integrations/__tests__/moveSession.test.ts+++ b/apps/desktop/src/main/mcp-integrations/__tests__/moveSession.test.ts@@ -134,6 +134,25 @@ describe('moveSession host', () => {},);+ it.each([false, true])(+ 'rechecks target lifecycle and ownership at commit (project=%s)',+ async (project) => {+ for (const change of ['archived', 'bot-link', 'im']) {+ h.query.mockResolvedValue([{ id: 'target', status: 'active' }]);+ h.botLinks = [];+ h.attached = false;+ h.beforeCommit.mockImplementationOnce(() => {+ if (change === 'archived')+ h.query.mockResolvedValue([{ id: 'target', status: 'archived' }]);+ if (change === 'bot-link') h.botLinks = [{ botId: 'bot' }];+ if (change === 'im') h.attached = true;+ });+ expect(await run(project ? directory : null)).toMatchObject({ ok: false });+ }+ expect(h.saved).not.toHaveBeenCalled();+ },+ );+it.each(['source', 'link'])('rejects Bot %s callers before entering the target update',async (signal) => {@@ -207,32 +226,34 @@ describe('moveSession host', () => {expect(await run('relative')).toMatchObject({ errorCode: 'INVALID_ARGS' });expect(h.saved).not.toHaveBeenCalled();});- it.for(['.cindy-worktrees', '.xdt-worktrees', 'dialogues'])(- 'rejects a %s alias retargeted while waiting for the route lock',- async (managedName, ctx) => {- const ordinary = path.join(directory, 'ordinary');- const managed = path.join(directory, managedName, 'task');- const alias = path.join(directory, 'alias');- await mkdir(ordinary);- await mkdir(managed, { recursive: true });- try {- await symlink(ordinary, alias, process.platform === 'win32' ? 'junction' : 'dir');- } catch (error) {- if (['EPERM', 'EACCES', 'ENOSYS'].includes((error as NodeJS.ErrnoException).code ?? '')) {- ctx.skip();- return;- }- throw error;+ it.for(+ ['.cindy-worktrees', '.xdt-worktrees', 'dialogues'].flatMap((name) =>+ ['lock', 'commit'].map((phase) => [name, phase] as const),+ ),+ )('rejects a %s alias retargeted before %s', async ([managedName, phase], ctx) => {+ const ordinary = path.join(directory, 'ordinary');+ const managed = path.join(directory, managedName, 'task');+ const alias = path.join(directory, 'alias');+ await mkdir(ordinary);+ await mkdir(managed, { recursive: true });+ try {+ await symlink(ordinary, alias, process.platform === 'win32' ? 'junction' : 'dir');+ } catch (error) {+ if (['EPERM', 'EACCES', 'ENOSYS'].includes((error as NodeJS.ErrnoException).code ?? '')) {+ ctx.skip();+ return;}- expect(await run(alias)).toMatchObject({ ok: true, workingDir: alias.replaceAll('\\', '/') });- h.saved.mockClear();- h.enterLock.mockImplementationOnce(async () => {- await rm(alias);- await symlink(managed, alias, process.platform === 'win32' ? 'junction' : 'dir');- });- expect(await run(alias)).toMatchObject({ errorCode: 'INVALID_PARAMS' });- expect(h.saved).not.toHaveBeenCalled();- expect(await run(null)).toMatchObject({ ok: true, workingDir: '/old' });- },- );+ throw error;+ }+ expect(await run(alias)).toMatchObject({ ok: true, workingDir: alias.replaceAll('\\', '/') });+ h.saved.mockClear();+ const checkpoint = phase === 'lock' ? h.enterLock : h.beforeCommit;+ checkpoint.mockImplementationOnce(async () => {+ await rm(alias);+ await symlink(managed, alias, process.platform === 'win32' ? 'junction' : 'dir');+ });+ expect(await run(alias)).toMatchObject({ errorCode: 'INVALID_PARAMS' });+ expect(h.saved).not.toHaveBeenCalled();+ expect(await run(null)).toMatchObject({ ok: true, workingDir: '/old' });+ });});diff --git a/apps/desktop/src/main/mcp-integrations/moveSession.ts b/apps/desktop/src/main/mcp-integrations/moveSession.tsindex bc33a937ad..61bbadb746 100644--- a/apps/desktop/src/main/mcp-integrations/moveSession.ts+++ b/apps/desktop/src/main/mcp-integrations/moveSession.ts@@ -28,27 +28,6 @@ export function createMoveSession(return withLocalProjectContext(callerSessionId, async (context) => {const assertMoveAllowed = async () => {context.assertCurrent();- // Re-read active team membership at each checkpoint, including after- // transcript copying/runtime close. Do not retain the pre-move snapshot.- const workers = await context.client.drizzle- .select({ sessionId: orcaWorkers.sessionId })- .from(orcaWorkers)- .innerJoin(orcaTeams, eq(orcaWorkers.teamId, orcaTeams.id))- .where(and(eq(orcaTeams.leadSessionId, sessionId), eq(orcaTeams.status, 'active')));- context.assertCurrent();- if (- isSessionRunning(sessionId) ||- workers.some((worker) => isSessionRunning(worker.sessionId))- ) {- throwIpcError(- 'PRECONDITION_FAILED',- 'Running tasks or leads with running workers cannot be moved.',- );- }- if (bindingStore.findByTarget(sessionId))- throwIpcError('PRECONDITION_FAILED', 'IM-controlled tasks cannot be moved.');- };- const beforeUpdate = async () => {const [target] = await context.client.drizzle.select().from(sessions)@@ -79,7 +58,25 @@ export function createMoveSession(const physicalDirectory = await validateExistingLocalProjectDirectory(targetDir);if (!physicalDirectory.ok) throwIpcError('INVALID_PARAMS', physicalDirectory.message);}- await assertMoveAllowed();+ // Re-read active team membership at each checkpoint, including after+ // transcript copying/runtime close. Do not retain the pre-move snapshot.+ const workers = await context.client.drizzle+ .select({ sessionId: orcaWorkers.sessionId })+ .from(orcaWorkers)+ .innerJoin(orcaTeams, eq(orcaWorkers.teamId, orcaTeams.id))+ .where(and(eq(orcaTeams.leadSessionId, sessionId), eq(orcaTeams.status, 'active')));+ context.assertCurrent();+ if (+ isSessionRunning(sessionId) ||+ workers.some((worker) => isSessionRunning(worker.sessionId))+ ) {+ throwIpcError(+ 'PRECONDITION_FAILED',+ 'Running tasks or leads with running workers cannot be moved.',+ );+ }+ if (bindingStore.findByTarget(sessionId))+ throwIpcError('PRECONDITION_FAILED', 'IM-controlled tasks cannot be moved.');};const patch =targetDir === null@@ -87,7 +84,7 @@ export function createMoveSession(: { workspaceKind: 'project', workingDir: targetDir };const updated = await updateSessionInDb(sessionId, patch, undefined, {assertCurrent: context.assertCurrent,- beforeUpdate,+ beforeUpdate: assertMoveAllowed,beforeWrite: assertMoveAllowed,});return {