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(mobile): 调度 runtime-state 诊断事件不再触发手机全量刷新 (#5259)

Chris Zhang6b10ba07c2c6
diff --git a/apps/mobile/src/__tests__/remoteScheduleEvents.test.ts b/apps/mobile/src/__tests__/remoteScheduleEvents.test.ts
index 6bd7b7bfad..c8ee80bb08 100644
--- a/apps/mobile/src/__tests__/remoteScheduleEvents.test.ts
+++ b/apps/mobile/src/__tests__/remoteScheduleEvents.test.ts
@@ -178,6 +178,33 @@ describe('remote schedule event store', () => {
expect(remoteScheduleEventStore.getSnapshot('dev-1').lastProjection?.refresh.runRefresh).toEqual({ mode: 'all' });
});
+ it('ignores runtime-state diagnostics without invalidating, notifying, or replacing the last projection', () => {
+ remoteScheduleEventStore.apply('dev-1', {
+ type: 'completed', scheduleId: 'sched-1', runId: 'run-1', sessionId: 'chat-1',
+ });
+ const before = remoteScheduleEventStore.getSnapshot('dev-1');
+ const invalidationVersion = getScheduleIndexInvalidationVersion('dev-1');
+ const sub = vi.fn();
+ const off = remoteScheduleEventStore.subscribe(sub);
+ try {
+ remoteScheduleEventStore.apply('dev-1', { type: 'runtime-state', snapshot: { inFlight: 0 } });
+ expect(sub).not.toHaveBeenCalled();
+ expect(remoteScheduleEventStore.getSnapshot('dev-1')).toBe(before);
+ expect(getScheduleIndexInvalidationVersion('dev-1')).toBe(invalidationVersion);
+
+ // 未知的新类型仍走保守的全量刷新。
+ remoteScheduleEventStore.apply('dev-1', { type: 'future-event' });
+ expect(sub).toHaveBeenCalledTimes(1);
+ expect(getScheduleIndexInvalidationVersion('dev-1')).toBe(invalidationVersion + 1);
+ expect(remoteScheduleEventStore.getSnapshot('dev-1')).toMatchObject({
+ runsVersion: before.runsVersion + 1,
+ scheduleListVersion: before.scheduleListVersion + 1,
+ sessionIndexVersion: before.sessionIndexVersion + 1,
+ unreadVersion: before.unreadVersion + 1,
+ });
+ } finally { off(); }
+ });
+
it('unreadClearVersion 只随未读清除类事件(read / all-read)递增', () => {
// fired / completed 属非清除类(none / may-increase),不 bump。
remoteScheduleEventStore.apply('dev-1', { type: 'fired', scheduleId: 'sched-1', runId: 'run-1' });
diff --git a/apps/mobile/src/scheduler/remoteScheduleEvents.ts b/apps/mobile/src/scheduler/remoteScheduleEvents.ts
index 4746cd292f..8c81a3dc92 100644
--- a/apps/mobile/src/scheduler/remoteScheduleEvents.ts
+++ b/apps/mobile/src/scheduler/remoteScheduleEvents.ts
@@ -49,9 +49,19 @@ export const remoteScheduleEventStore = {
apply(deviceId: string, payload?: unknown): void {
if (!deviceId) return;
const projection = projectScheduleEvent(payload);
- const prev = snapshots.get(deviceId) ?? emptySnapshot;
const clearsUnread = projection.unreadImpact === 'may-clear-schedule'
|| projection.unreadImpact === 'clear-all';
+ // 不要求任何刷新、也不带 run 状态的事件(runtime-state 高频诊断)不换快照:否则挂载屏
+ // 每次都重渲染,且会覆盖上一个可操作事件(如 completed)的 lastProjection。
+ if (
+ projection.refresh.runRefresh.mode === 'none'
+ && !projection.refresh.scheduleList
+ && !projection.refresh.sessionIndex
+ && !projection.refresh.unreadSummary
+ && projection.unreadImpact === 'none'
+ && projection.runPatch.status === 'unknown'
+ ) return;
+ const prev = snapshots.get(deviceId) ?? emptySnapshot;
// Invalidate once before notifying all screens. Consumer-local force loads
// otherwise launch competing scans for the same authoritative event.
if (projection.refresh.sessionIndex || projection.refresh.scheduleList || clearsUnread) {
diff --git a/packages/maker-shared/src/__tests__/scheduleEvents.test.ts b/packages/maker-shared/src/__tests__/scheduleEvents.test.ts
index 25ef37db1f..7222ed5b9b 100644
--- a/packages/maker-shared/src/__tests__/scheduleEvents.test.ts
+++ b/packages/maker-shared/src/__tests__/scheduleEvents.test.ts
@@ -168,6 +168,34 @@ describe('shared scheduler event projection', () => {
});
});
+ it('treats desktop runtime-state diagnostics as a no-refresh event instead of unknown', () => {
+ const payload = {
+ type: 'runtime-state',
+ snapshot: {
+ schedulerInstanceId: 'sched-instance',
+ inFlight: 1,
+ slotsInUse: 1,
+ maxConcurrentRuns: 8,
+ inFlightRuns: [],
+ waitingSchedules: [],
+ },
+ };
+ expect(normalizeSchedulerEvent(payload)).toEqual({ type: 'runtime-state' });
+ // snapshot 形状不参与投影:缺失或畸形都不能退回 unknown 的全量刷新。
+ expect(normalizeSchedulerEvent({ type: 'runtime-state' })).toEqual({ type: 'runtime-state' });
+ expect(projectScheduleEvent(payload)).toEqual({
+ event: { type: 'runtime-state' },
+ refresh: {
+ runRefresh: { mode: 'none' },
+ scheduleList: false,
+ sessionIndex: false,
+ unreadSummary: false,
+ },
+ runPatch: { scheduleId: null, runId: null, sessionId: null, status: 'unknown' },
+ unreadImpact: 'none',
+ });
+ });
+
it('decides whether a selected schedule should refresh its run list', () => {
expect(shouldRefreshRunsForSchedule({ mode: 'none' }, 'sched-1')).toBe(false);
expect(shouldRefreshRunsForSchedule({ mode: 'all' }, 'sched-1')).toBe(true);
diff --git a/packages/maker-shared/src/scheduleEvents.ts b/packages/maker-shared/src/scheduleEvents.ts
index 52b1fe3194..e75d8ed428 100644
--- a/packages/maker-shared/src/scheduleEvents.ts
+++ b/packages/maker-shared/src/scheduleEvents.ts
@@ -9,7 +9,12 @@ export type SchedulerEvent =
| { type: 'changed'; scheduleId: string }
| { type: 'read'; scheduleId: string }
| { type: 'all-read' }
- | { type: 'ready' };
+ | { type: 'ready' }
+ /**
+ * In-flight 数量或并发闸门等待队列变化的运行诊断(desktop engine 高频广播)。与 desktop
+ * renderer 一致,不驱动任何列表 / run / 未读刷新;投影不需要 snapshot,因此不校验也不保留。
+ */
+ | { type: 'runtime-state' };
export type SchedulerEventType = SchedulerEvent['type'];
export type NormalizedSchedulerEvent = SchedulerEvent | { type: 'unknown'; rawType: string | null };
@@ -82,6 +87,7 @@ export function normalizeSchedulerEvent(value: unknown): NormalizedSchedulerEven
}
case 'all-read':
case 'ready':
+ case 'runtime-state':
return { type };
default:
return unknownEvent(type);
@@ -166,6 +172,15 @@ export function projectNormalizedScheduleEvent(event: NormalizedSchedulerEvent):
sessionIndex: true,
unreadSummary: true,
}, 'clear-all', runPatch(null, null, null, 'read'));
+ case 'runtime-state':
+ // 纯运行诊断:不能落进 unknown 的全量刷新,否则每次 in-flight 变化都让消费方重拉
+ // schedule index / 列表 / runs。
+ return projection(event, {
+ runRefresh: { mode: 'none' },
+ scheduleList: false,
+ sessionIndex: false,
+ unreadSummary: false,
+ }, 'none', runPatch(null, null, null, 'unknown'));
case 'unknown':
return projection(event, {
runRefresh: { mode: 'all' },