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): keep history mirror deferred after view publish

Leng Jingxu21ac69dec503
diff --git a/apps/desktop/src/main/device-link/__tests__/historyScanFallback.test.ts b/apps/desktop/src/main/device-link/__tests__/historyScanFallback.test.ts
index 0c927d04d6..c876c86d7f 100644
--- a/apps/desktop/src/main/device-link/__tests__/historyScanFallback.test.ts
+++ b/apps/desktop/src/main/device-link/__tests__/historyScanFallback.test.ts
@@ -21,14 +21,15 @@ const mobile = readFileSync(fileURLToPath(new URL('../../../../../mobile/app/ses
describe.each(['\n', '\r\n'])('automatic scan budget fallback owners (%j)', (newline) => {
const desktopSource = desktop.replace(/\r?\n/g, newline);
const mobileSource = mobile.replace(/\r?\n/g, newline);
- it.each([true, false])('Desktop refills only the current active view (active=%s)', (active) => {
+ it.each([true, false])('Desktop refills only the current active view (active=%s)', async (active) => {
const reconcile = vi.fn(async () => true);
const view = { isActive: () => active, getSnapshot: () => ({ ready: false, error: new Error('[UNSUPPORTED_CAPABILITY] History view scan budget exceeded') }) };
for (const current of [true, false]) {
reconcile.mockClear();
callback(desktopSource, ' view.subscribe(() => {', '\n });\n void view.restoreCachedView',
- ['isCurrent', 'sessions', 'sessionId', 'view', 'isHistoryViewUnavailable', 'reconcileRemoteMessages', 'persistTimer', 'writeCache', 'setState'],
- [() => current, new Set(['s']), 's', view, isHistoryViewUnavailable, reconcile, undefined, undefined, vi.fn()]);
+ ['isCurrent', 'sessions', 'sessionId', 'view', 'isHistoryViewUnavailable', 'reconcileRemoteMessages', 'persistTimer', 'writeCache', 'setState', 'mirrorScheduled', 'mirrorSnapshot'],
+ [() => current, new Set(['s']), 's', view, isHistoryViewUnavailable, reconcile, undefined, undefined, vi.fn(), false, vi.fn()]);
+ await Promise.resolve();
expect(reconcile).toHaveBeenCalledTimes(active && current ? 1 : 0);
if (active && current) expect(reconcile).toHaveBeenCalledWith('s', { force: true });
}
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index ceda31a878..abb97646ed 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -11878,9 +11878,6 @@ function createRemoteHistoryView(sessionId: string) {
new Set(state.messages.filter((row) => !row.isPendingPersist).map((row) => row.clientId)));
return messages === state.messages ? state : { ...state, messages };
});
- if (view.isActive()) {
- void reconcileRemoteMessages(sessionId, { force: true }).catch(() => undefined);
- }
return;
}
if (!snapshot.ready) return;
@@ -11912,9 +11909,14 @@ function createRemoteHistoryView(sessionId: string) {
if (persistTimer) clearTimeout(persistTimer);
if (!isCurrent() || !sessions.has(sessionId)) return;
const snapshot = view.getSnapshot();
- const isLoadingMore = view.isLoadingOlder();
- setState(sessionId, (state) => state.isLoadingMore === isLoadingMore
- ? state : { ...state, isLoadingMore });
+ if (!snapshot.ready && view.isActive() && isHistoryViewUnavailable(snapshot.error)) {
+ void reconcileRemoteMessages(sessionId, { force: true }).catch(() => undefined);
+ }
+ if (snapshot.ready) {
+ const isLoadingMore = view.isLoadingOlder();
+ setState(sessionId, (state) => state.isLoadingMore === isLoadingMore
+ ? state : { ...state, isLoadingMore });
+ }
if (isHistoryViewUnavailable(snapshot.error)) writeCache = undefined;
else if (snapshot.ready && !snapshot.loading && !snapshot.error && writeCache) {
const writer = writeCache;