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): 数据库清理后归档任务显示「历史内容已清除」占位

Battleplus9fc5216a1111
diff --git a/apps/desktop/src/main/localDb/__tests__/dbSlimmingMaintenance.test.ts b/apps/desktop/src/main/localDb/__tests__/dbSlimmingMaintenance.test.ts
index f2c45fed48..4b2ad09742 100644
--- a/apps/desktop/src/main/localDb/__tests__/dbSlimmingMaintenance.test.ts
+++ b/apps/desktop/src/main/localDb/__tests__/dbSlimmingMaintenance.test.ts
@@ -366,7 +366,7 @@ describe('runDbSlimmingMaintenance', () => {
list_message_count: null,
context_tokens: 100,
context_window: 200,
- cleared_at: null,
+ cleared_at: 2_000,
summary: 'summary',
codex_plan_json: '{}',
codex_history_has_product_prompt: 1,
@@ -392,6 +392,43 @@ describe('runDbSlimmingMaintenance', () => {
}
});
+ it('stamps cleared_at on archived tasks whose history was purged (#3709)', async () => {
+ createCleanupFixture();
+
+ await runDbSlimmingMaintenance({
+ userDataDir: tmpDir,
+ dbFilePath,
+ request: request({ beforeBytes: estimateDbFilesBytes(dbFilePath) }),
+ now: () => 3_000,
+ log,
+ });
+
+ const db = createBetterSqliteDatabase(dbFilePath, { fileMustExist: true });
+ try {
+ // The archived task fell inside the scan window and had its messages purged, so it
+ // must carry cleared_at (and stay archived) for the renderer to show the
+ // "history cleared" placeholder instead of a blank pane.
+ expect(
+ db.prepare("SELECT status, cleared_at FROM sessions WHERE id = 'archived-boundary'").get(),
+ ).toEqual({ status: 'archived', cleared_at: 2_000 });
+ expect(
+ db
+ .prepare("SELECT count(*) AS count FROM messages WHERE session_id = 'archived-boundary'")
+ .get(),
+ ).toEqual({ count: 0 });
+ // Archived tasks outside the window, or without messages, are not stamped.
+ expect(
+ db.prepare("SELECT cleared_at FROM sessions WHERE id = 'archived-new'").get(),
+ ).toEqual({ cleared_at: null });
+ // Active tasks are only touched when includeActiveTasks is set.
+ expect(db.prepare("SELECT cleared_at FROM sessions WHERE id = 'active-old'").get()).toEqual({
+ cleared_at: 50,
+ });
+ } finally {
+ db.close();
+ }
+ });
+
it('removes cleaned active tasks from lists and keeps every recent status intact', async () => {
createCleanupFixture();
const cleanedTurnChangeSetDir = path.join(tmpDir, 'turn-change-sets', 'active-old');
diff --git a/apps/desktop/src/main/localDb/dbSlimmingMaintenance.ts b/apps/desktop/src/main/localDb/dbSlimmingMaintenance.ts
index acd78abbe4..cab4a613be 100644
--- a/apps/desktop/src/main/localDb/dbSlimmingMaintenance.ts
+++ b/apps/desktop/src/main/localDb/dbSlimmingMaintenance.ts
@@ -711,6 +711,23 @@ function compactWorkingCopy(
WHERE id IN (SELECT id FROM temp.db_slimming_targets)`,
);
}
+ // Archived tasks stay visible after their history is purged, so they need the same
+ // cleared_at boundary as active tasks. Without it the renderer cannot tell
+ // "history cleared by maintenance" from "history failed to load" and shows a blank
+ // pane instead of the cleared placeholder (#3709). This runs before the
+ // includeActiveTasks block so archived tasks are stamped even when active tasks are
+ // excluded, and it only touches the archived targets in the current scan window.
+ if (sessionColumns.has('cleared_at')) {
+ activeDb
+ .prepare(
+ `UPDATE sessions
+ SET cleared_at = MAX(COALESCE(cleared_at, 0), ?)
+ WHERE id IN (
+ SELECT id FROM temp.db_slimming_targets WHERE status = 'archived'
+ )`,
+ )
+ .run(Math.floor(request.scannedAt));
+ }
if (request.includeActiveTasks === true) {
if (tableExists(activeDb, 'session_goals')) {
activeDb.exec(