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。

merge: resolve session cleanup conflicts with current main

Dante9a4643c1ebd2
diff --cc apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
index 605069baf2,964683cb31..8267a649c2
--- a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
@@@ -160,12 -160,8 +169,13 @@@ import
setSessionRuntimeCleanup,
setSessionWorktreeRecycle,
updateSessionInDb,
+ touchUserSendInDb,
} from '../sessions';
+import {
+ clearAllSessionAttention,
+ getAttentionCount,
+ markSessionNeedsAttention,
+} from '../../../appBadgeService';
import { retireDeletedPiSubagentState } from '../piSubagentDeletion';
import { setSessionRouteLockImplementation } from '../../sessionRouteLock';
import { assertTrustedAppRendererEvent } from '../../../security/trustedAppRenderer.js';
@@@ -338,80 -332,40 +348,114 @@@ afterEach(async () =>
});
describe('local-db:sessions:update handler wiring', () => {
+ it.each([invokeUpdate, invokePatchMeta])(
+ 'clears only the deleted task from event-backed app attention (%#)',
+ async (update) => {
+ // These tasks have not entered a renderer catalog projection yet.
+ markSessionNeedsAttention('cc-local');
+ markSessionNeedsAttention('codex-local');
+ expect(getAttentionCount()).toBe(2);
+
+ await update('cc-local', { status: 'deleted' });
+ expect(getAttentionCount()).toBe(1);
+ await update('codex-local', { status: 'deleted' });
+ expect(getAttentionCount()).toBe(0);
+ if (process.platform !== 'win32') expect(h.setBadgeCount).toHaveBeenLastCalledWith(0);
+ },
+ );
+
+ it.each([invokeUpdate, invokePatchMeta])(
+ 'retains attention when deletion fails or the task is missing (%#)',
+ async (update) => {
+ markSessionNeedsAttention('cc-local');
+ markSessionNeedsAttention('missing');
+ h.sqlite!.exec(`CREATE TRIGGER reject_delete BEFORE UPDATE OF status ON sessions
+ WHEN NEW.status = 'deleted' BEGIN SELECT RAISE(ABORT, 'write failed'); END`);
+ await expect(update('cc-local', { status: 'deleted' })).rejects.toThrow('PRECONDITION_FAILED');
+ expect(h.sqlite!.prepare('SELECT status FROM sessions WHERE id = ?').get('cc-local'))
+ .toEqual({ status: 'active' });
+ await expect(update('missing', { status: 'deleted' })).rejects.toThrow('NOT_FOUND');
+ expect(getAttentionCount()).toBe(2);
+ },
+ );
+
+ it.each([invokeUpdate, invokePatchMeta])(
+ "does not clear a new owner's attention after an in-flight deletion (%#)",
+ async (update) => {
+ markSessionNeedsAttention('cc-local');
+ h.captureOwnerScope = true;
+ h.routeLock.mockImplementationOnce(async (_sessionId, task) => {
+ const result = await task();
+ h.ownerCurrent = false;
+ return result;
+ });
+ await update('cc-local', { status: 'deleted' });
+ expect(getAttentionCount()).toBe(1);
+ },
+ );
+
+ it('clears deleted Bot task attention only after its transaction succeeds', async () => {
+ markSessionNeedsAttention('bot-task');
+ markSessionNeedsAttention('other-task');
+ h.commitBotProfileDeletion.mockRejectedValueOnce(new Error('write failed'));
+ await expect(deleteBotProfileAndDetachSessionsInDb('bot', ['bot-task'], false))
+ .rejects.toThrow('write failed');
+ expect(getAttentionCount()).toBe(2);
+
+ h.commitBotProfileDeletion.mockResolvedValueOnce({ sessionIds: ['bot-task'], status: 'deleted' });
+ await deleteBotProfileAndDetachSessionsInDb('bot', ['bot-task'], false);
+ expect(getAttentionCount()).toBe(1);
+ });
+
+ it('preserves attention when Bot history is retained or the owner changes', async () => {
+ markSessionNeedsAttention('bot-task');
+ h.commitBotProfileDeletion.mockResolvedValueOnce({ sessionIds: ['bot-task'], status: 'archived' });
+ await deleteBotProfileAndDetachSessionsInDb('bot', ['bot-task'], true);
+ expect(getAttentionCount()).toBe(1);
+
+ h.captureOwnerScope = true;
+ h.commitBotProfileDeletion.mockImplementationOnce(async () => {
+ h.ownerCurrent = false;
+ return { sessionIds: ['bot-task'], status: 'deleted' };
+ });
+ await deleteBotProfileAndDetachSessionsInDb('bot', ['bot-task'], false);
+ expect(getAttentionCount()).toBe(1);
+ });
+
+ it('rechecks window trust for both movement broadcasts after navigation', async () => {
+ const trusted = {
+ trusted: true,
+ isDestroyed: vi.fn(() => false),
+ webContents: { send: vi.fn() },
+ };
+ const auxiliary = {
+ trusted: false,
+ isDestroyed: vi.fn(() => false),
+ webContents: { send: vi.fn() },
+ };
+ h.windows = [trusted, auxiliary];
+ await invokeUpdate('codex-local', { workingDir: '/new/dir', workspaceKind: 'project' });
+ expect(trusted.webContents.send).toHaveBeenCalledWith('local-db:recent-workdirs:changed', {
+ path: '/new/dir',
+ });
+ expect(trusted.webContents.send).toHaveBeenCalledWith(
+ 'local-db:sessions:patched',
+ expect.objectContaining({ sessionId: 'codex-local' }),
+ );
+ expect(auxiliary.webContents.send).not.toHaveBeenCalled();
+
+ trusted.webContents.send.mockClear();
+ trusted.trusted = false;
+ await invokeUpdate('codex-local', { workingDir: '/another/dir', workspaceKind: 'project' });
+ await invokeUpdate('codex-local', { workspaceKind: 'dialogue' });
+ expect(trusted.webContents.send).not.toHaveBeenCalled();
+ expect(auxiliary.webContents.send).not.toHaveBeenCalled();
+ expect(h.tapWindowBroadcast).toHaveBeenCalledWith(
+ 'local-db:sessions:patched',
+ expect.objectContaining({ sessionId: 'codex-local' }),
+ );
+ });
+
it('isolates device-link and renderer failures while broadcasting a session patch', () => {
const failedWindowSend = vi.fn(() => {
throw new Error('window closed');
diff --cc apps/desktop/src/main/localDb/ipc/sessions.ts
index 7de954ec70,03ee45b1dd..10dceb2936
--- a/apps/desktop/src/main/localDb/ipc/sessions.ts
+++ b/apps/desktop/src/main/localDb/ipc/sessions.ts
@@@ -27,11 -27,16 +27,17 @@@ import { getDbClient } from '../client/
import * as currentDb from '../client/current';
import type { DbClient } from '../client/DbClient';
import { sessions, messages } from '../schema';
+import { clearSessionAttention } from '../../appBadgeService';
+ import {
+ selectSessionListRows,
+ selectSessionWithCount,
+ selectSessionsByIds,
+ flattenSessionReadRow,
+ projectSessionReadResult,
+ type SessionListRow,
+ } from '../sessionQueries';
import { commitBotProfileDeletion } from '../botProfileDeletionStore.js';
import {
- LIST_PREVIEW_EXTRACT_SQL,
- LATEST_VISIBLE_PREVIEW_FILTER_SQL,
persistSessionListProjectionBatch,
type SessionListProjectionBackfillItem,
} from '../sessionListProjection';
@@@ -2058,26 -2072,8 +2076,11 @@@ export async function patchSessionMetaI
row.summary = null;
}
cleanupSessionRuntimeForTerminalStatus(sessionId, patch.status);
- return { updated: sessionToCamel(row), source: row.source };
+ return sessionToCamel(row);
});
+ if (updated.status === 'deleted' && isOwnerScopeCurrent(ownerScope)) {
+ clearSessionAttention(sessionId, 'explicit');
+ }
- if (
- (patch.status === 'deleted' || patch.status === 'archived') &&
- updated.workspaceKind === 'project' &&
- updated.workingDir &&
- !updated.remoteHostId &&
- isRetainableProjectSessionSource(source)
- ) {
- const touched = await upsertRecentWorkdir(
- updated.workingDir,
- Date.now(),
- process.platform,
- dbClient,
- );
- if (touched) broadcastRecentWorkdirsChanged(updated.workingDir, ownerScope);
- }
notifyAgentIslandSessionPatch(updated.id, {
status: updated.status,
title: updated.title,