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(desktop): clear attention for overwritten share sessions

Dante61c068cd176c
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/sessionShareCompaction.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/sessionShareCompaction.test.ts
index 4a95da600c..507682d673 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/sessionShareCompaction.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/sessionShareCompaction.test.ts
@@ -1,6 +1,8 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
const h = vi.hoisted(() => ({
+ owner: 'owner-1',
+ clearSessionAttention: vi.fn(),
handlers: new Map<string, (...args: unknown[]) => unknown>(),
client: { drizzle: {} },
commitShareImport: vi.fn(),
@@ -21,6 +23,9 @@ vi.mock('electron', () => ({
}),
},
}));
+vi.mock('../../../appBadgeService.js', () => ({
+ clearSessionAttention: h.clearSessionAttention,
+}));
vi.mock('../../../logger.js', () => ({
createLogger: () => ({ warn: vi.fn() }),
}));
@@ -42,7 +47,7 @@ vi.mock('../../client/current.js', () => ({
tryGetDbClient: () => h.client,
}));
vi.mock('../../../appSessionState.js', () => ({
- activeOwnerScopeKey: () => 'owner-1',
+ activeOwnerScopeKey: () => h.owner,
isAppSessionBoundaryPending: () => false,
}));
vi.mock('../../../cindy-media/refCompensationJournal.js', () => ({
@@ -60,6 +65,7 @@ vi.mock('../sessions.js', () => ({
describe('session share replacement compaction', () => {
beforeEach(async () => {
vi.clearAllMocks();
+ h.owner = 'owner-1';
h.handlers.clear();
h.commitShareImport.mockResolvedValue({
sessionId: 'replacement',
@@ -72,12 +78,28 @@ describe('session share replacement compaction', () => {
registerSessionShareIpc();
});
+ it('does not clear attention when the replacement transaction fails', async () => {
+ h.commitShareImport.mockRejectedValueOnce(new Error('transaction failed'));
+ await expect(h.handlers.get('local-db:session-share:commit')?.({}, { draftId: 'draft-1', overwrite: true })).rejects.toThrow();
+ expect(h.clearSessionAttention).not.toHaveBeenCalled();
+ });
+
+ it('does not clear the new owner attention if the owner changes after commit', async () => {
+ h.commitShareImport.mockImplementationOnce(async () => {
+ h.owner = 'owner-2';
+ return { sessionId: 'replacement', replacedSessions: [{ id: 'replaced-session' }], fidelity: 'full', notes: [], orcaWorkers: [] };
+ });
+ await expect(h.handlers.get('local-db:session-share:commit')?.({}, { draftId: 'draft-1', overwrite: true })).rejects.toThrow();
+ expect(h.clearSessionAttention).not.toHaveBeenCalled();
+ });
+
it('starts one best-effort compaction after the replaced task is deleted', async () => {
const handler = h.handlers.get('local-db:session-share:commit');
expect(handler).toBeTypeOf('function');
await handler?.({}, { draftId: 'draft-1', overwrite: true });
+ expect(h.clearSessionAttention).toHaveBeenCalledExactlyOnceWith('replaced-session', 'explicit');
expect(h.compactSessionToolResultsBestEffort).toHaveBeenCalledTimes(1);
expect(h.compactSessionToolResultsBestEffort).toHaveBeenCalledWith({
client: h.client,
diff --git a/apps/desktop/src/main/localDb/ipc/session-share.ts b/apps/desktop/src/main/localDb/ipc/session-share.ts
index baa7518a31..bb89669bb2 100644
--- a/apps/desktop/src/main/localDb/ipc/session-share.ts
+++ b/apps/desktop/src/main/localDb/ipc/session-share.ts
@@ -17,6 +17,7 @@ import { BRAND_NAME } from '@cindy/maker-shared/branding';
import { isIpcErrorCode } from '../../../shared/ipc-errors.js';
import { createLogger } from '../../logger.js';
+import { clearSessionAttention } from '../../appBadgeService.js';
import { notifyGhostSessionEvent } from '../../cindy-brain/index.js';
import { requireObject, requireString, throwIpcError } from '../../utils/ipcValidate.js';
import {
@@ -206,6 +207,7 @@ export function registerSessionShareIpc(): void {
// 不直接删除转录或媒体字节:同 resume id/内容的新任务可能复用它们。
for (const replaced of result.replacedSessions) {
if (!isStillCurrent()) break;
+ clearSessionAttention(replaced.id, 'explicit');
broadcastSessionPatched(replaced.id, { status: 'deleted' }, recycleScope.ownerScope);
void compactSessionToolResultsBestEffort({
client: importDbClient,