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(bot-autonomy): 远程轮询兼容旧版被控端返回的活动数组,未知格式按读取失败处理

Chris9e37c2bab618
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 2651de18ea..ee87888067 100644
--- a/apps/desktop/src/main/bot-autonomy/__tests__/taskWatch.test.ts
+++ b/apps/desktop/src/main/bot-autonomy/__tests__/taskWatch.test.ts
@@ -246,6 +246,31 @@ describe('TaskWatch ownership and startup retries', () => {
});
describe('TaskWatch remote polling', () => {
+ // 依据:协议兼容(docs/dev-rules/protocol-compatibility.md)——旧版被控端不认 snapshotVersion,仍回数组。
+ // 缺口:数组被当成「没有任务」,那台电脑的行被全部清掉还显示在线。最小失败输入:list-active 回数组。tier:unit。
+ it('reads the legacy array an older computer returns, and treats an unknown shape as a failed read', async () => {
+ let shape: 'array' | 'garbage' = 'array';
+ const h = harness({
+ devices: [{ deviceId: 'dev-1', name: 'Studio', online: true, eligible: true }],
+ invokeRemote: async (_deviceId, channel) => {
+ if (channel === 'maker:list-active') {
+ return shape === 'array' ? [{ sessionId: 'r1', isTurnRunning: true, activityPhase: 'running' }] : { format: 'unknown' };
+ }
+ if (channel === 'local-db:sessions:get-many') return [{ id: 'r1', title: 'Old host build', source: 'desktop', status: 'active', hiddenAt: null }];
+ return [];
+ },
+ });
+ await h.watch.start();
+ await h.watch.sweep();
+ expect(h.watch.get('dev-1::r1')).toMatchObject({ phase: 'running', title: 'Old host build', online: true });
+
+ shape = 'garbage';
+ h.advance(AUTONOMY_THRESHOLDS.remotePollMs);
+ await h.watch.sweep();
+ expect(h.watch.get('dev-1::r1')).toMatchObject({ online: false });
+ expect(h.watch.offlineDevices()).toEqual(['Studio']);
+ });
+
it('reads eligible online computers, then backs off and marks rows offline when polling fails', async () => {
let fail = false;
const h = harness({
diff --git a/apps/desktop/src/main/bot-autonomy/taskWatch.ts b/apps/desktop/src/main/bot-autonomy/taskWatch.ts
index 705e2fa8ef..6a1c9ea258 100644
--- a/apps/desktop/src/main/bot-autonomy/taskWatch.ts
+++ b/apps/desktop/src/main/bot-autonomy/taskWatch.ts
@@ -687,10 +687,14 @@ export class TaskWatch {
}
private async pollDevice(deviceId: string, state: RemoteDeviceState, now: number): Promise<void> {
- const result = record(await this.deps.invokeRemote(deviceId, 'maker:list-active', [
+ const response = await this.deps.invokeRemote(deviceId, 'maker:list-active', [
{ summary: true, snapshotVersion: 2 },
- ]));
- const sessions = Array.isArray(result?.sessions) ? result.sessions : [];
+ ]);
+ // 新版被控端返回 active-sessions-v2 包装;不认识 snapshotVersion 的旧版仍返回原来的数组,两种都收。
+ // 都不是就按读取失败处理(退避、标离线),不能当成「没有任务」把那台电脑的行全清掉。
+ const result = record(response);
+ const sessions = Array.isArray(response) ? response : Array.isArray(result?.sessions) ? result.sessions : null;
+ if (!sessions) throw Object.assign(new Error('Unexpected active session list'), { code: 'REMOTE_SHAPE' });
const active = new Map<string, { isTurnRunning?: unknown; activityPhase?: unknown }>();
for (const raw of sessions) {
const row = record(raw);