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(cindy-make): allow version switching during active tasks (#4882)

Lizi1375c3cd96a2
diff --git a/apps/desktop/src/main/cindy-make/__tests__/versionService.test.ts b/apps/desktop/src/main/cindy-make/__tests__/versionService.test.ts
index fd19792132..ac43c9d64d 100644
--- a/apps/desktop/src/main/cindy-make/__tests__/versionService.test.ts
+++ b/apps/desktop/src/main/cindy-make/__tests__/versionService.test.ts
@@ -7,7 +7,6 @@ const h = vi.hoisted(() => ({
currentId: 'original',
selectedId: 'original',
current: true,
- busy: false,
switching: false,
handoff: vi.fn(),
quit: vi.fn(),
@@ -18,9 +17,6 @@ vi.mock('../../device-link/broadcast-tap.js', () => ({
captureDataOwnerBroadcastScope: () => ({}),
isDataOwnerBroadcastScopeCurrent: () => h.current,
}));
-vi.mock('../../relaunchBusyActivityIpc.js', () => ({
- readRelaunchBlockingActivity: async () => ({ busy: h.busy }),
-}));
vi.mock('../../logger', () => ({
createLogger: () => ({ info: vi.fn(), debug: vi.fn(), warn: vi.fn(), error: vi.fn() }),
}));
@@ -65,7 +61,6 @@ beforeEach(async () => {
h.currentId = 'original';
h.selectedId = 'original';
h.current = true;
- h.busy = false;
h.switching = false;
const executable = path.join(h.profile, 'original.exe');
await writeFile(executable, 'original');
@@ -87,7 +82,7 @@ afterEach(async () => {
await rm(h.profile, { recursive: true, force: true });
});
describe('version management main boundary', () => {
- it('allows switching and returning to original after preparation settles in the real manager', async () => {
+ it('allows switching and returning to original while preparation is still running', async () => {
setPersonal();
const manager = new CindyMakeManager();
configureCindyVersions(() => manager.hasActiveWork());
@@ -113,12 +108,11 @@ describe('version management main boundary', () => {
onError: () => {},
},
);
- await expect(actCindyVersion('switch', id)).rejects.toThrow('busy');
+ await actCindyVersion('switch', id);
+ expect(h.handoff).toHaveBeenCalledWith(id, expect.any(Function));
release();
await manager.waitForTask('version-prepare');
expect(manager.taskReport('version-prepare')?.status).toBe('completed');
- await actCindyVersion('switch', id);
- expect(h.handoff).toHaveBeenCalledWith(id, expect.any(Function));
h.currentId = id;
await actCindyVersion('switch', 'original');
expect(h.handoff).toHaveBeenLastCalledWith('original', expect.any(Function));
@@ -138,8 +132,8 @@ describe('version management main boundary', () => {
await actCindyVersion('switch', 'original');
expect(h.handoff).toHaveBeenCalledWith('original', expect.any(Function));
expect(manager.getState().upstreamMerge).toEqual(conflict);
- h.busy = true;
- await expect(actCindyVersion('switch', 'original')).rejects.toThrow('busy');
+ await actCindyVersion('switch', 'original');
+ expect(h.handoff).toHaveBeenLastCalledWith('original', expect.any(Function));
});
it('projects Dev as the original without creating a registry on a read', async () => {
expect(await getCindyVersions()).toMatchObject({
@@ -180,14 +174,14 @@ describe('version management main boundary', () => {
await expect(actCindyVersion(action, target)).rejects.toMatchObject({ code: 'INVALID_PARAMS' });
expect(h.handoff).not.toHaveBeenCalled();
});
- it('blocks switching during build or other running work and never quits on a failed handoff', async () => {
+ it('allows switching during build or other running work and never quits on a failed handoff', async () => {
setPersonal();
configureCindyVersions(() => true);
- await expect(actCindyVersion('switch', id)).rejects.toThrow('busy');
+ await actCindyVersion('switch', id);
+ expect(h.handoff).toHaveBeenCalledWith(id, expect.any(Function));
configureCindyVersions(() => false);
- h.busy = true;
- await expect(actCindyVersion('switch', id)).rejects.toThrow('busy');
- h.busy = false;
+ await actCindyVersion('switch', id);
+ expect(h.handoff).toHaveBeenLastCalledWith(id, expect.any(Function));
h.handoff.mockRejectedValueOnce(
Object.assign(new Error('incompatible'), { code: 'incompatible' }),
);
@@ -220,6 +214,9 @@ describe('version management main boundary', () => {
writeVersionJson(path.join(versionsRoot(h.profile), 'selected.json'), { id });
await expect(actCindyVersion('remove', id)).rejects.toThrow('busy');
writeVersionJson(path.join(versionsRoot(h.profile), 'selected.json'), { id: 'original' });
+ configureCindyVersions(() => true);
+ await expect(actCindyVersion('remove', id)).rejects.toThrow('busy');
+ configureCindyVersions(() => false);
await actCindyVersion('remove', id);
await expect(access(path.join(directory, 'runtime'))).rejects.toThrow();
await expect(access(path.join(directory, 'version.json'))).resolves.toBeUndefined();
diff --git a/apps/desktop/src/main/cindy-make/versionService.ts b/apps/desktop/src/main/cindy-make/versionService.ts
index 9c51ba038f..0b6571c72c 100644
--- a/apps/desktop/src/main/cindy-make/versionService.ts
+++ b/apps/desktop/src/main/cindy-make/versionService.ts
@@ -13,7 +13,6 @@ import {
captureDataOwnerBroadcastScope,
isDataOwnerBroadcastScopeCurrent,
} from '../device-link/broadcast-tap.js';
-import { readRelaunchBlockingActivity } from '../relaunchBusyActivityIpc.js';
import {
describeOriginalVersion,
getCurrentCindyVersionId,
@@ -93,22 +92,22 @@ export async function actCindyVersion(action: unknown, id: unknown): Promise<Cin
const current = () =>
isDataOwnerBroadcastScopeCurrent(scope) && app.getPath('userData') === profile;
try {
- if (makeBusy() || isCindyVersionSwitching()) throwIpcError('PRECONDITION_FAILED', 'busy');
+ // An explicit switch may interrupt active work. Normal quit preserves Agent turn
+ // markers for continuing after startup; background jobs are not replayed.
+ // Removing the personal version still requires the busy guard below.
+ if ((action === 'remove' && makeBusy()) || isCindyVersionSwitching())
+ throwIpcError('PRECONDITION_FAILED', 'busy');
if (action === 'switch') {
// Old completion cards carry generation UUIDs. They now address the same personal
// slot instead of resurrecting the application built for that historical task.
const targetId = id === 'original' ? id : personalVersionId(profile);
if (!targetId) throwIpcError('PRECONDITION_FAILED', 'unavailable');
if (getCurrentCindyVersionId() === targetId) return getCindyVersions();
- if ((await readRelaunchBlockingActivity()).busy || !current())
- throwIpcError('PRECONDITION_FAILED', 'busy');
await startVersionHandoff(
targetId,
async () =>
current() &&
- !makeBusy() &&
- (targetId === 'original' || personalVersionId(profile) === targetId) &&
- !(await readRelaunchBlockingActivity()).busy,
+ (targetId === 'original' || personalVersionId(profile) === targetId),
);
if (!current()) throwIpcError('PRECONDITION_FAILED', 'busy');
// Normal quit awaits the existing Maker, plugin, credential and DB disposers.
diff --git a/apps/desktop/src/renderer/__tests__/cindyMakeInlineEntry.test.ts b/apps/desktop/src/renderer/__tests__/cindyMakeInlineEntry.test.ts
index 1a2c2bb2c8..4edeb36161 100644
--- a/apps/desktop/src/renderer/__tests__/cindyMakeInlineEntry.test.ts
+++ b/apps/desktop/src/renderer/__tests__/cindyMakeInlineEntry.test.ts
@@ -53,10 +53,14 @@ describe('Cindy Make composer presentation', () => {
}
expect(sessionView).toContain('if (cindyMakeInputLocked) return false;');
expect(sessionView).not.toContain('CindyMakeResumeCard');
- const recovery = sessionView.indexOf(') : cindyMakeRecoveryId && session ? (');
- expect(recovery).toBeGreaterThan(mask);
- expect(recovery).toBeLessThan(input);
- expect(sessionView.slice(recovery, input)).toContain('<CindyMakeTestCard');
- expect(sessionView.slice(recovery, input)).toContain(') : (');
+ const testCard = sessionView.indexOf('<CindyMakeTestCard', mask);
+ expect(testCard).toBeGreaterThan(mask);
+ expect(testCard).toBeLessThan(input);
+ // Continued editing keeps the composer; recovery actions live inside its top slot.
+ const recovery = sessionView.indexOf('topSlot={cindyMakeRecoveryId && session ? (');
+ expect(recovery).toBeGreaterThan(input);
+ const recoverySlot = sessionView.slice(recovery, sessionView.indexOf('onSend=', recovery));
+ expect(recoverySlot).toContain('<CindyMakeEditingActions');
+ expect(recoverySlot).toContain(') : undefined}');
});
});
diff --git a/apps/desktop/src/renderer/components/cindy-make/CindyMakeTestCard.tsx b/apps/desktop/src/renderer/components/cindy-make/CindyMakeTestCard.tsx
index 00835c36c2..788148bfac 100644
--- a/apps/desktop/src/renderer/components/cindy-make/CindyMakeTestCard.tsx
+++ b/apps/desktop/src/renderer/components/cindy-make/CindyMakeTestCard.tsx
@@ -210,6 +210,8 @@ export function CindyMakeTestCard({
};
const switching = !!versions.pending || versions.state?.switching === true;
const personalVersion = versions.state?.versions.find((version) => version.kind === 'personal');
+ const switchesPersonal =
+ personal?.status === 'ready' && !!personal.versionId && !!personalVersion;
const generatesPersonal =
personal?.status !== 'ready' || (!!personal.versionId && !!versions.state && !personalVersion);
const usingPersonal =
@@ -313,16 +315,14 @@ export function CindyMakeTestCard({
<Button
variant="secondary"
disabled={
- !!pending ||
- building ||
- starting ||
+ (!switchesPersonal && (!!pending || building || starting)) ||
switching ||
usingPersonal ||
(generatesPersonal && sourceMergePending) ||
!meta.commit ||
(personal?.status === 'ready' && !!personal.versionId && !versions.state)
}
- loading={building || switching || pending === 'open-build'}
+ loading={switching || (!switchesPersonal && (building || pending === 'open-build'))}
onClick={() => {
if (personal?.status === 'ready' && personal.versionId) {
if (personalVersion) void versions.act('switch', personalVersion.id);
diff --git a/apps/desktop/src/renderer/components/cindy-make/CindyMakeVersionsPanel.tsx b/apps/desktop/src/renderer/components/cindy-make/CindyMakeVersionsPanel.tsx
index 2d08780245..d292783038 100644
--- a/apps/desktop/src/renderer/components/cindy-make/CindyMakeVersionsPanel.tsx
+++ b/apps/desktop/src/renderer/components/cindy-make/CindyMakeVersionsPanel.tsx
@@ -25,7 +25,8 @@ export function CindyMakeVersionsPanel({
const { confirm } = useConfirmDialog();
const [expanded, setExpanded] = useState(false);
const listId = useId();
- const disabled = busy || !!versions.pending || versions.state?.switching;
+ const switchDisabled = !!versions.pending || versions.state?.switching;
+ const removeDisabled = busy || switchDisabled;
const supported = typeof window.electronAPI.getCindyVersions === 'function';
useEffect(() => onState?.(versions.state), [onState, versions.state]);
const current =
@@ -39,7 +40,7 @@ export function CindyMakeVersionsPanel({
: t('cindyMake.versions.personal');
const personal = versions.state?.versions.find((version) => version.kind === 'personal');
const switchBlockedReason = (version: CindyVersionInfo) => {
- if (disabled) return 'busy' as const;
+ if (switchDisabled) return 'busy' as const;
if (!version.available) return 'unavailable' as const;
if (!version.compatible) return 'incompatible' as const;
return undefined;
@@ -183,7 +184,9 @@ export function CindyMakeVersionsPanel({
{version.kind === 'personal' && (
<Button
variant="secondary"
- disabled={disabled || versions.state?.selectedId === version.id}
+ disabled={
+ removeDisabled || versions.state?.selectedId === version.id
+ }
onClick={async () => {
if (
await confirm({
diff --git a/apps/desktop/src/renderer/components/cindy-make/__tests__/CindyMakeTestCard.test.tsx b/apps/desktop/src/renderer/components/cindy-make/__tests__/CindyMakeTestCard.test.tsx
index 911fd63e5a..c58b9806aa 100644
--- a/apps/desktop/src/renderer/components/cindy-make/__tests__/CindyMakeTestCard.test.tsx
+++ b/apps/desktop/src/renderer/components/cindy-make/__tests__/CindyMakeTestCard.test.tsx
@@ -651,6 +651,45 @@ describe('completion card in the input area', () => {
await waitFor(() => expect(switchVersion).toHaveBeenCalledWith('switch', 'personal'));
expect(h.api.mock.calls.some(([, , action]) => action === 'open-build')).toBe(false);
});
+ it('keeps switching to an updated personal version available while an isolated test is starting', async () => {
+ const switchVersion = vi.fn().mockResolvedValue({
+ currentId: 'original',
+ selectedId: 'original',
+ versions: [],
+ switching: true,
+ });
+ vi.stubGlobal('electronAPI', {
+ cindyMakeTest: h.api,
+ getCindyVersions: vi.fn().mockResolvedValue({
+ currentId: 'original',
+ selectedId: 'original',
+ personalUpdateAvailable: true,
+ switching: false,
+ versions: [
+ { id: 'original', kind: 'original', available: true, compatible: true },
+ { id: 'personal', kind: 'personal', available: true, compatible: true },
+ ],
+ }),
+ actCindyVersion: switchVersion,
+ });
+ render(
+ <CindyMakeTestCard
+ sessionId="session"
+ completionId="completion"
+ meta={{
+ ...meta,
+ test: { status: 'starting', step: 'dependencies' },
+ personal: { status: 'ready', versionId: 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' },
+ }}
+ />,
+ );
+ const update = await screen.findByRole('button', {
+ name: 'cindyMake.versions.updatePersonal',
+ });
+ expect((update as HTMLButtonElement).disabled).toBe(false);
+ fireEvent.click(update);
+ await waitFor(() => expect(switchVersion).toHaveBeenCalledWith('switch', 'personal'));
+ });
it('offers regeneration after the personal version was deleted instead of reviving a historical build', async () => {
vi.stubGlobal('electronAPI', {
cindyMakeTest: h.api,
diff --git a/apps/desktop/src/renderer/components/cindy-make/__tests__/CindyMakeVersionsPanel.test.tsx b/apps/desktop/src/renderer/components/cindy-make/__tests__/CindyMakeVersionsPanel.test.tsx
index b1d131dd17..8e1113386f 100644
--- a/apps/desktop/src/renderer/components/cindy-make/__tests__/CindyMakeVersionsPanel.test.tsx
+++ b/apps/desktop/src/renderer/components/cindy-make/__tests__/CindyMakeVersionsPanel.test.tsx
@@ -160,7 +160,7 @@ describe('Cindy Make local versions', () => {
expect((update as HTMLButtonElement).disabled).toBe(true);
expect(update.getAttribute('title')).toBe('cindyMake.versions.unavailable');
});
- it('shows the busy reason while another Make operation blocks switching', async () => {
+ it('keeps switching available while another Make operation is running', async () => {
h.get.mockResolvedValue({
...versions,
currentId: 'personal',
@@ -169,9 +169,13 @@ describe('Cindy Make local versions', () => {
});
render(<CindyMakeVersionsPanel busy />);
const update = await screen.findByRole('button', {
- name: 'cindyMake.versions.errors.busy',
+ name: 'cindyMake.versions.updatePersonal',
});
- expect((update as HTMLButtonElement).disabled).toBe(true);
- expect(update.getAttribute('title')).toBe('cindyMake.versions.errors.busy');
+ expect((update as HTMLButtonElement).disabled).toBe(false);
+ fireEvent.click(update);
+ await waitFor(() => expect(h.act).toHaveBeenCalledWith('switch', 'personal'));
+ fireEvent.click(screen.getByRole('button', { name: 'cindyMake.overview.switchVersion' }));
+ const remove = await screen.findByRole('button', { name: 'cindyMake.versions.remove' });
+ expect((remove as HTMLButtonElement).disabled).toBe(true);
});
});
diff --git a/apps/desktop/src/renderer/components/settings/__tests__/CindyMakeSection.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/CindyMakeSection.test.tsx
index 1a19573ad8..6815fe3416 100644
--- a/apps/desktop/src/renderer/components/settings/__tests__/CindyMakeSection.test.tsx
+++ b/apps/desktop/src/renderer/components/settings/__tests__/CindyMakeSection.test.tsx
@@ -732,7 +732,7 @@ describe('Settings > Cindy Make', () => {
expect(h.api.cindyMakeMerge).toHaveBeenCalledTimes(1);
},
);
- it('allows version switching with retained conflicts but disables it during active work', async () => {
+ it('allows version switching with retained conflicts and during active work', async () => {
const history = { busy: true, activeWork: false };
const h = harness(history);
const versions = {
@@ -769,7 +769,7 @@ describe('Settings > Cindy Make', () => {
await waitFor(() => expect(switchVersion).toHaveBeenCalledWith('switch', 'original'));
history.activeWork = true;
await h.pushState({ source, upstreamMerge: { ...conflict } });
- await waitFor(() => expect(button.hasAttribute('disabled')).toBe(true));
+ await waitFor(() => expect(button.hasAttribute('disabled')).toBe(false));
history.activeWork = false;
await h.pushState({ source, upstreamMerge: { ...conflict } });
await waitFor(() => expect(button.hasAttribute('disabled')).toBe(false));
diff --git a/docs/cindy-make-upstream.md b/docs/cindy-make-upstream.md
index cb6bb5e8e1..5646d2e61c 100644
--- a/docs/cindy-make-upstream.md
+++ b/docs/cindy-make-upstream.md
@@ -122,8 +122,9 @@ Settings 的手动“同步最新源码”继续可用。创建制作任务前
源码准备失败或停止时保留结果和原因,按钮为「重试准备」;更新失败或冲突时显示原因及处理入口。
源码更新操作共用一个位置:正常显示“同步最新源码”,待处理冲突时替换为“处理冲突”,
已有处理任务时在同处提供查看入口;底部只显示状态与原因,不重复摆放操作按钮。
- 待处理冲突禁止生成个人版,但不阻止切换已经生成的应用版本;版本切换仅沿用正在执行的
- 准备、构建、测试及其它运行工作的重启保护。制作任务卡与设置页均遵守此边界。
+ 待处理冲突禁止生成个人版,但不阻止切换已经生成的应用版本;版本切换不要求当前没有
+ 正在执行的任务,切换会正常退出当前进程,目标版本启动后可按既有中断恢复继续任务。制作任务卡
+ 与设置页均遵守此边界;删除个人版仍保留运行中任务保护。
更新成功只提示一次,随后显示个人版与 main 的版本差距,不再常驻「源码改动已合入」或
「个人版源码已准备好」。旧更新回执不遮挡后续源码准备与重试;仍有未处理更新工作区时保留冲突处理入口。
卡片进入页面即显示,先发布本机保存的源码摘要,再补 Git 版本与联网查询结果;
@@ -269,8 +270,10 @@ Settings 的手动“同步最新源码”继续可用。创建制作任务前
`original.json` 刷新与选择落盘推迟到取得单实例锁之后):紧随其后加载的
bootstrap-electron 必须在 Electron ready 之前注册特权协议与 ready 监听,分流阶段一旦
让出事件循环,原版就会在启动时直接失败。只有以 `app.exit()` 收尾的交接路径可以等待 I/O。
-- 切换先核验完整应用与数据兼容性、检查在途工作,再由独立的无窗口 Electron 交接进程
- 等待旧进程正常退出并启动目标。返回 Dev 复用既有开发 runner 和 PTY;不以裸 Electron
+- 切换先核验完整应用与数据兼容性、交接状态和目标版本可用性;运行中的任务不阻止切换。
+ 独立的无窗口 Electron 交接进程等待旧进程正常退出并启动目标。中断的 Agent 任务可按原流程
+ 继续;后台 Bash、插件作业等随正常退出停止,不保证自动续接或重跑。
+ 返回 Dev 复用既有开发 runner 和 PTY;不以裸 Electron
重启替代 Forge/Vite。只有既有窗口+认证/数据库就绪合同成功后才记住新选择,失败
停止本次启动并尝试上一版本。登录回调、文件入口只在进程间临时转交,不写版本记录。
- 个人版对已有数据库只进行严格兼容核对,不迁移其 schema;不兼容的版本拒绝切换,
@@ -283,8 +286,9 @@ Settings 的手动“同步最新源码”继续可用。创建制作任务前
- 失败或取消时不发送需求;显式重试复用原任务和分支。取消单个任务不会取消共享的
环境/源码准备;历史页重试由 Main 恢复原记录中的来源身份,显式冲突的身份仍拒绝。
全局准备的停止入口仍在 Settings。重复点击、打开已有任务不会再次派发。
- 准备与清理的实际执行完全结束后释放忙碌状态;保留的完成、失败、取消记录不阻止合入、
- 生成或版本切换,但取消后的进程收尾与最终持久化完成前仍保持占用。
+- 准备与清理的实际执行完全结束后释放忙碌状态;保留的完成、失败、取消记录不阻止合入、
+ 生成或版本切换。版本切换不要求等待任务自然完成,但仍走正常退出收尾;合入、生成和
+ 删除个人版仍在进程收尾与最终持久化完成前保持占用。
- 应用进程重启不静默重放请求。未完成的持久准备卡按已中断显示,用户可显式重试;不能仅凭
已保存的用户消息推断 Agent 已成功执行。已确认完成的准备不会再次自动派发。
清空任务立即取消本任务准备并使旧请求、旧卡片失效;清空前排队的首次请求不得再发送。