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(device-link): 终态补丁清除待发旧活动

Dash14a2bc72984f
diff --git a/apps/desktop/src/main/device-link/__tests__/dispatchMakerEventBatch.test.ts b/apps/desktop/src/main/device-link/__tests__/dispatchMakerEventBatch.test.ts
index 88b747e377..9888fa0a47 100644
--- a/apps/desktop/src/main/device-link/__tests__/dispatchMakerEventBatch.test.ts
+++ b/apps/desktop/src/main/device-link/__tests__/dispatchMakerEventBatch.test.ts
@@ -243,6 +243,35 @@ it.each([SESSION_ACTIVITY_CHANNEL, 'local-db:sessions:patched'])('rechecks %s ca
expect(h.sent.map(push => push.payload)).toEqual([payload('completed')]);
});
+// Review regression (unit): a lifecycle patch can overtake activity still in the
+// stage, including the item awaiting authorization. Existing ordering tests only
+// covered maker-event batches. Observe outgoing pushes through real dispatch.
+it.each(['deleted', 'archived'] as const)('drops older activity before a %s patch across staging boundaries', async (status) => {
+ for (const boundary of ['authorizing', 'queued', 'backpressure'] as const) {
+ const h = mkClient();
+ __testing.setActiveClient(h.client as never);
+ subscriptions.subscribe('phone', ['sessions']);
+ let release!: () => void;
+ const pending = new Promise<void>(resolve => { release = resolve; });
+ setRemoteBotSessionLookup(async () => { await pending; return 'visible'; });
+ if (boundary === 'backpressure') h.client.getReliableSendQueueDepth.mockReturnValue(8);
+ if (boundary === 'queued') __testing.forwardPush(SESSION_ACTIVITY_CHANNEL, { sessionId: 's0', phase: 'working' });
+ __testing.forwardPush(SESSION_ACTIVITY_CHANNEL, { sessionId: 's1', phase: 'working' });
+ __testing.forwardPush('local-db:sessions:patched', { sessionId: 's1', patch: { status } });
+ __testing.forwardPush(SESSION_ACTIVITY_CHANNEL, { sessionId: 's2', phase: 'completed' });
+ h.client.getReliableSendQueueDepth.mockReturnValue(0);
+ release();
+ await vi.advanceTimersByTimeAsync(500);
+ expect(h.sent.filter(push => push.channel === SESSION_ACTIVITY_CHANNEL).map(push => push.payload))
+ .toEqual(boundary === 'queued'
+ ? [{ sessionId: 's0', phase: 'working' }, { sessionId: 's2', phase: 'completed' }]
+ : [{ sessionId: 's2', phase: 'completed' }]);
+ expect(h.sent.filter(push => push.channel === 'local-db:sessions:patched').map(push => push.payload))
+ .toEqual([{ sessionId: 's1', patch: { status } }]);
+ handleControllerOffline('phone');
+ }
+});
+
it.each(['superseded', 'offline', 'hidden'] as const)('discards %s activity while authorization is pending', async (outcome) => {
const h = mkClient();
__testing.setActiveClient(h.client as never);
diff --git a/apps/desktop/src/main/device-link/dispatch.ts b/apps/desktop/src/main/device-link/dispatch.ts
index e5ab6f73e0..7d6477ed41 100644
--- a/apps/desktop/src/main/device-link/dispatch.ts
+++ b/apps/desktop/src/main/device-link/dispatch.ts
@@ -2216,6 +2216,11 @@ function forwardPush(channel: string, payload: unknown, ownerStamp?: PushOwnerSt
}
if (channel === 'local-db:sessions:patched') {
const item = targetPayload as SessionPatch;
+ // A terminal patch supersedes older activity still staged or awaiting
+ // authorization. The drain's identity check also cancels its in-flight item.
+ if (item?.patch?.status === 'deleted' || item?.patch?.status === 'archived') {
+ sessionActivityStages.get(dst)?.queue.delete(item.sessionId);
+ }
// Engine/lifecycle fields are barriers for following maker events. Only
// independent list metadata may wait; fold older metadata into a barrier.
if (item?.patch && Object.keys(item.patch).every((key) => key === 'title' || key === 'extraDirs')) {