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(bots): 自动重试用完后,下一条推送或重新打开群聊立即重新读取

Dash6a4e1f083c33
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServerThreads.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServerThreads.test.ts
index 85f6039096..68e84fd914 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServerThreads.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServerThreads.test.ts
@@ -270,6 +270,12 @@ describe('recovering from a failed read in a quiet room', () => {
// 5 automatic retries with doubling gaps, then it waits for a push or a reopen.
expect(io.threadPage).toHaveBeenCalledTimes(6);
expect(gaps).toEqual([30_000, 60_000, 120_000, 240_000, 480_000]);
+ // Once it has given up, the next push or reopening reads again at once.
+ io.threadPage.mockResolvedValue([reply('r1', rootB)]);
+ projection.previews(room, [root], fullWindow([]));
+ await projection.settled();
+ expect(io.threadPage).toHaveBeenCalledTimes(7);
+ expect(projection.previews(room, [root], fullWindow([])).get(rootB)?.map(item => item.id)).toEqual(['r1']);
});
it.each(['dispose', 'reset'] as const)('cancels a pending retry on %s', async (stop) => {
diff --git a/apps/desktop/src/main/maker-ipc/chatServerThreads.ts b/apps/desktop/src/main/maker-ipc/chatServerThreads.ts
index ff8b90dce9..65ab0bbc66 100644
--- a/apps/desktop/src/main/maker-ipc/chatServerThreads.ts
+++ b/apps/desktop/src/main/maker-ipc/chatServerThreads.ts
@@ -78,10 +78,10 @@ export function createThreadProjection<M extends ThreadMessage>(io: {
function scheduleRetry(roomId: string, cacheKey: string) {
const attempt = (failures.get(cacheKey) ?? 0) + 1;
failures.set(cacheKey, attempt);
- const at = Date.now() + RETRY_MS * 2 ** Math.min(attempt - 1, RETRY_ATTEMPTS - 1);
+ // After the last automatic attempt the next push or reopening retries at once.
+ if (attempt > RETRY_ATTEMPTS) { retryAt.delete(cacheKey); return; }
+ const at = Date.now() + RETRY_MS * 2 ** (attempt - 1);
retryAt.set(cacheKey, at);
- // After the last automatic attempt only a later read (a push or reopening) retries.
- if (attempt > RETRY_ATTEMPTS) return;
const pending = pendingRetries.get(roomId) ?? new Map<string, number>();
pending.set(cacheKey, at); pendingRetries.set(roomId, pending);
armRetry(roomId);