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): return cached workbench before remote refresh

zqchris9481f1c47f31
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 98f5fb6cd9..271b29a1a1 100644
--- a/apps/desktop/src/main/bot-autonomy/__tests__/hub.test.ts
+++ b/apps/desktop/src/main/bot-autonomy/__tests__/hub.test.ts
@@ -78,3 +78,26 @@ it('only refreshes remote state for an explicit scheduler workbench read and dis
remote.mockImplementationOnce(async () => { h.scope = 'b'; });
await expect(getBotAutonomyGlance('sched')).rejects.toThrow('PRECONDITION_FAILED');
});
+
+// Unit regression for #6675: a nonresponding peer must not block the first cached
+// glance. Existing immediate remote mocks cannot expose the unresolved IPC.
+it('returns the cached glance while a remote peer is still pending or fails', async () => {
+ let rejectRemote!: (error: Error) => void;
+ const pending = new Promise<void>((_resolve, reject) => { rejectRemote = reject; });
+ const projection = { botId: 'sched', working: [{ sessionId: 'local' }] };
+ setActiveBotAutonomy({ scope: 'a', engine: {} as RoutineEngine, runtime: {
+ 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);
+ } finally {
+ rejectRemote(new Error('remote unavailable'));
+ await read.catch(() => {});
+ }
+ expect(await getBotAutonomyGlance('sched', undefined, false)).toBe(projection);
+});
diff --git a/apps/desktop/src/main/bot-autonomy/__tests__/taskWatch.test.ts b/apps/desktop/src/main/bot-autonomy/__tests__/taskWatch.test.ts
index ac9ef86c3c..00102663e4 100644
--- a/apps/desktop/src/main/bot-autonomy/__tests__/taskWatch.test.ts
+++ b/apps/desktop/src/main/bot-autonomy/__tests__/taskWatch.test.ts
@@ -457,15 +457,26 @@ it('stops global observation on opt-out and rehydrates current activity on opt-i
expect(h.listRemoteDevices).not.toHaveBeenCalled();
});
-it('keeps remote IO out of scheduled sweeps and coalesces explicit view reads', async () => {
+// Unit #6675: after returning cached glance, the visible view needs a change signal
+// carrying updated rows. Previously only the awaited read saw the remote result.
+it('keeps remote IO out of scheduled sweeps and notifies coalesced view reads of new rows', async () => {
const h = harness({ devices: [{ deviceId: 'dev-1', name: 'Studio', online: true, eligible: true }],
- invokeRemote: async () => [] });
+ invokeRemote: async (_device, channel) => channel === 'maker:list-active'
+ ? [{ sessionId: 'r1', isTurnRunning: true, activityPhase: 'running' }]
+ : [{ id: 'r1', title: 'Remote task', source: 'desktop', status: 'active' }] });
await h.watch.start();
await h.watch.sweep();
expect(h.listRemoteDevices).not.toHaveBeenCalled();
+ h.onChange.mockClear();
+ const displayed: string[][] = [];
+ h.onChange.mockImplementation(() => { displayed.push(h.watch.list().map(row => row.title)); });
await Promise.all([h.watch.refreshRemote(), h.watch.refreshRemote()]);
- expect(h.invokeRemote).toHaveBeenCalledTimes(1);
+ expect(h.invokeRemote).toHaveBeenCalledTimes(2);
+ expect(displayed).toEqual([['Remote task']]);
+ // The notification's reread stays inside the existing remote throttle.
+ await h.watch.refreshRemote();
+ expect(h.invokeRemote).toHaveBeenCalledTimes(2);
h.advance(120_000);
await h.watch.sweep();
- expect(h.invokeRemote).toHaveBeenCalledTimes(1);
+ expect(h.invokeRemote).toHaveBeenCalledTimes(2);
});
diff --git a/apps/desktop/src/main/bot-autonomy/hub.ts b/apps/desktop/src/main/bot-autonomy/hub.ts
index 8c2230b91f..6b1d2defa3 100644
--- a/apps/desktop/src/main/bot-autonomy/hub.ts
+++ b/apps/desktop/src/main/bot-autonomy/hub.ts
@@ -75,7 +75,10 @@ export async function getBotAutonomyGlance(
if (!active) return emptyGlance(botId);
const scope = activeOwnerScopeKey();
// The hidden auto-open probe and Agent reads use cached projections only.
- if (refreshRemote && active.watch.getSchedulerBotId() === botId) await active.watch.refreshRemote();
+ // Return cached/local rows immediately; the watch pushes changes when remote IO settles.
+ if (refreshRemote && active.watch.getSchedulerBotId() === botId) {
+ void active.watch.refreshRemote().catch((error) => log.warn('autonomy remote refresh failed', { error: errorCode(error) }));
+ }
assertOwner(scope);
if (current?.runtime !== active) throwIpcError('PRECONDITION_FAILED', 'Task observation changed; retry later.');
return active.glance(botId, options);
diff --git a/apps/desktop/src/main/bot-autonomy/taskWatch.ts b/apps/desktop/src/main/bot-autonomy/taskWatch.ts
index f980ca44d2..0c9a04709b 100644
--- a/apps/desktop/src/main/bot-autonomy/taskWatch.ts
+++ b/apps/desktop/src/main/bot-autonomy/taskWatch.ts
@@ -335,7 +335,11 @@ export class TaskWatch {
refreshRemote(): Promise<void> {
if (this.stopped) return Promise.resolve();
if (!this.remoteRefresh) {
- this.remoteRefresh = this.pollRemote(this.deps.now()).finally(() => { this.remoteRefresh = null; });
+ this.remoteRefresh = this.pollRemote(this.deps.now()).finally(() => {
+ this.remoteRefresh = null;
+ // View reads already returned cached rows. Runtime deduplicates unchanged projections.
+ if (!this.stopped) this.deps.onChange();
+ });
}
return this.remoteRefresh;
}