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): preserve synchronous cached glance consumers

zqchris9984b8b91531
diff --git a/apps/desktop/src/main/bot-autonomy/__tests__/hub.test.ts b/apps/desktop/src/main/bot-autonomy/__tests__/hub.test.ts
index 271b29a1a1..81402eb394 100644
--- a/apps/desktop/src/main/bot-autonomy/__tests__/hub.test.ts
+++ b/apps/desktop/src/main/bot-autonomy/__tests__/hub.test.ts
@@ -76,7 +76,7 @@ it('only refreshes remote state for an explicit scheduler workbench read and dis
expect(await getBotAutonomyGlance('sched')).toBe(projection);
expect(remote).toHaveBeenCalledOnce();
remote.mockImplementationOnce(async () => { h.scope = 'b'; });
- await expect(getBotAutonomyGlance('sched')).rejects.toThrow('PRECONDITION_FAILED');
+ expect(() => getBotAutonomyGlance('sched')).toThrow('PRECONDITION_FAILED');
});
// Unit regression for #6675: a nonresponding peer must not block the first cached
@@ -89,15 +89,12 @@ it('returns the cached glance while a remote peer is still pending or fails', as
watch: { getSchedulerBotId: () => 'sched', refreshRemote: () => pending },
glance: () => projection,
} as unknown as BotAutonomyRuntime });
- let received: unknown;
- const read = getBotAutonomyGlance('sched').then(value => { received = value; });
try {
- await Promise.resolve();
- await Promise.resolve();
- expect(received).toBe(projection);
+ // The detached permission handler also consumes this synchronous projection.
+ expect(getBotAutonomyGlance('sched')).toBe(projection);
} finally {
rejectRemote(new Error('remote unavailable'));
- await read.catch(() => {});
+ await Promise.resolve();
}
expect(await getBotAutonomyGlance('sched', undefined, false)).toBe(projection);
});
diff --git a/apps/desktop/src/main/bot-autonomy/hub.ts b/apps/desktop/src/main/bot-autonomy/hub.ts
index 6b1d2defa3..824c1a74db 100644
--- a/apps/desktop/src/main/bot-autonomy/hub.ts
+++ b/apps/desktop/src/main/bot-autonomy/hub.ts
@@ -67,9 +67,9 @@ function emptyGlance(botId: string): BotGlance {
return { botId, scope: 'own', waiting: [], working: [], lastSweepAt: 0, doneToday: 0, offlineDevices: [] };
}
-export async function getBotAutonomyGlance(
+export function getBotAutonomyGlance(
botId: string, options?: GlanceOptions, refreshRemote = true,
-): Promise<BotGlance> {
+): BotGlance {
if (isAppSessionBoundaryPending()) throwIpcError('PRECONDITION_FAILED', 'App session is switching; retry later.');
const active = current && scopeIsCurrent(current.scope) ? current.runtime : null;
if (!active) return emptyGlance(botId);
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index f18ba83698..cb5797ac60 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -3541,7 +3541,7 @@ function cancelPendingInteraction(requestId: string, decision: InteractionDecisi
/** Narrow detached-workbench action: the Bot's live glance must still own this exact local permission. */
export function allowBotWorkbenchPendingPermission(botId: string, sessionId: string, requestId: string): { accepted: boolean } {
- const row = getBotAutonomyGlance(botId).waiting.find((item) =>
+ const row = getBotAutonomyGlance(botId, undefined, false).waiting.find((item) =>
item.deviceId === null && item.sessionId === sessionId &&
item.requestId === requestId && item.waitingFor === 'permission');
const pending = pendingInteractionResolvers.get(requestId);