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。

保护移动会话时的运行时资源

nothingyuancando6e785c614e49
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
index cff66da128..2b6b693cf0 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
@@ -40,6 +40,9 @@ const h = vi.hoisted(() => ({
isSessionAlive: (id: string) => boolean;
closeSession: (id: string) => Promise<void>;
} | null => null),
+ withRehydrateCloseSuppressed: vi.fn(
+ async (_sessionId: string, task: () => Promise<void>) => task(),
+ ),
setPinnedSectionCardMode: vi.fn(),
upsertRecentWorkdir: vi.fn(async () => undefined),
routeLock: vi.fn(async <T>(_sessionId: string, task: () => Promise<T>): Promise<T> =>
@@ -101,6 +104,7 @@ vi.mock('../../../maker-host/claude-transcript-relocation.js', () => ({
// the whole Host.
vi.mock('../../../maker-host/index.js', () => ({
getMakerIfReady: h.getMakerIfReady,
+ withRehydrateCloseSuppressed: h.withRehydrateCloseSuppressed,
}));
// delete 路径的 removeHookAttachmentDir 会真删 turn change-set;归档路径动态
// import cindy-brain(重副作用模块)。两者都 mock 掉,本文件只断言广播行为。
@@ -218,6 +222,8 @@ beforeEach(() => {
h.clearPiSubagentDeletedTombstone.mockClear();
h.clearPiSubagentDeletedTombstone.mockImplementation(async () => undefined);
h.getMakerIfReady.mockReset();
+ h.withRehydrateCloseSuppressed.mockClear();
+ h.withRehydrateCloseSuppressed.mockImplementation(async (_sessionId, task) => task());
h.getMakerIfReady.mockReturnValue({ isSessionAlive: () => false, closeSession: h.closeSession });
h.userDataDir = mkdtempSync(path.join(os.tmpdir(), 'cindy-sessions-update-'));
createDb();
@@ -695,6 +701,10 @@ describe('local-db:sessions:update handler wiring', () => {
await invokeUpdate('codex-local', { workingDir: '/new/dir' });
expect(h.closeSession).toHaveBeenCalledWith('codex-local');
+ expect(h.withRehydrateCloseSuppressed).toHaveBeenCalledWith(
+ 'codex-local',
+ expect.any(Function),
+ );
});
it('does not reacquire the route lock for a combined workingDir and status patch', async () => {
diff --git a/apps/desktop/src/main/localDb/ipc/sessions.ts b/apps/desktop/src/main/localDb/ipc/sessions.ts
index d23d6941e6..3985c09696 100644
--- a/apps/desktop/src/main/localDb/ipc/sessions.ts
+++ b/apps/desktop/src/main/localDb/ipc/sessions.ts
@@ -1418,7 +1418,9 @@ export function registerSessionIpc(
// runtime with the moved session's cwd instead of continuing in the old one.
if (movingLocalNonClaudeSession) {
const makerHost = await import('../../maker-host/index.js');
- await makerHost.getMakerIfReady()?.closeSession(sid);
+ await makerHost.withRehydrateCloseSuppressed(sid, async () => {
+ await makerHost.getMakerIfReady()?.closeSession(sid);
+ });
}
// 只有纯设置字段(model/effort 等)才跳过 bump;凡带 activity 字段
// (clearedAt / sdkSessionId / status / token 用量等)仍需更新 updatedAt,