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(teammates): keep an archived lane when its resume fails transiently

zqchrise99e456cfb83
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
index 6ae6bb0874..5fdea9bc43 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
@@ -2060,10 +2060,18 @@ describe('Bot canonical Session lifecycle', () => {
await expect(ensureBotChannelLaneSession({ botId: 'bot-1', routeKey, title: 'ignored' }))
.resolves.toEqual({ ok: true, sessionId: first.sessionId, created: false });
// The owner archived the lane from the task list: the next message resumes it, not a second lane.
+ // Restoring re-reads the task row with its tags, as in the production schema.
+ h.sqlite!.exec(`CREATE TABLE IF NOT EXISTS task_tags(id TEXT PRIMARY KEY,name TEXT,color TEXT,favorite_order INTEGER,sort_order INTEGER,revision INTEGER,name_customized INTEGER NOT NULL DEFAULT 0);
+ CREATE TABLE IF NOT EXISTS session_task_tags(session_id TEXT,tag_id TEXT);`);
h.sqlite!.prepare("UPDATE sessions SET status = 'archived' WHERE id = ?").run(first.sessionId);
await expect(ensureBotChannelLaneSession({ botId: 'bot-1', routeKey, title: 'ignored' }))
.resolves.toEqual({ ok: true, sessionId: first.sessionId, created: false });
expect(h.sqlite!.prepare('SELECT status FROM sessions WHERE id = ?').get(first.sessionId)).toEqual({ status: 'active' });
+ // A restore failure other than deletion must surface for retry, never replace the lane.
+ h.sqlite!.prepare("UPDATE sessions SET status = 'archived', orca_role = 'worker' WHERE id = ?").run(first.sessionId);
+ await expect(ensureBotChannelLaneSession({ botId: 'bot-1', routeKey, title: 'ignored' }))
+ .rejects.toThrow(/Restore the managed task/);
+ h.sqlite!.prepare("UPDATE sessions SET status = 'active', orca_role = NULL WHERE id = ?").run(first.sessionId);
expect(emitSessionCreated).toHaveBeenCalledExactlyOnceWith(first.sessionId);
await expect(findBotChannelLaneSession('bot-1', routeKey)).resolves.toBe(first.sessionId);
const canonical = h.sqlite!.prepare(
diff --git a/apps/desktop/src/main/localDb/ipc/bots.ts b/apps/desktop/src/main/localDb/ipc/bots.ts
index b819931eb2..a6185a5bd2 100644
--- a/apps/desktop/src/main/localDb/ipc/bots.ts
+++ b/apps/desktop/src/main/localDb/ipc/bots.ts
@@ -40,6 +40,7 @@ import {
import { assertTrustedAppRendererEvent } from '../../security/trustedAppRenderer.js';
import { isDeviceLinkInvoke } from '../../device-link/invoke-context.js';
import { requireObject, requireString, throwIpcError } from '../../utils/ipcValidate.js';
+import { isIpcError } from '../../../shared/ipc-errors.js';
import { isBotVisibleRemotely } from './botRemoteVisibility.js';
import { readRemoteBotSessionAccess, readRemoteBotSessionAccessBatch } from './botRemoteSessionAccess.js';
import { setRemoteBotSessionLookup } from '../../device-link/remoteBotSessionBoundary.js';
@@ -475,7 +476,8 @@ async function findBotOwnedLaneSession(
/**
* The owner can archive these lanes from the task list. Like an archived automation
* target, the next trigger resumes the same Session (and its context) instead of
- * starting another one; a lane deleted meanwhile falls through to a new Session.
+ * starting another one. Only a lane deleted meanwhile falls through to a new Session;
+ * any other failure propagates so the caller retries rather than losing the context.
*/
async function resumeArchivedBotOwnedLaneSession(
botId: string,
@@ -487,7 +489,8 @@ async function resumeArchivedBotOwnedLaneSession(
try {
await restoreArchivedSessionForSend(archived);
} catch (error) {
- log.warn('archived bot lane could not be resumed; starting a new one', { sessionId: archived, error: String(error) });
+ if (!(isIpcError(error) && error.code === 'NOT_FOUND')) throw error;
+ log.warn('archived bot lane was deleted before it resumed; starting a new one', { sessionId: archived });
return null;
}
return archived;