Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 用同一滑动快照约束自动任务已读
Dash7c5c7d946c0d
diff --git a/apps/mobile/src/__tests__/useSessionListActions.test.tsx b/apps/mobile/src/__tests__/useSessionListActions.test.tsxindex c327830e98..cc296a4574 100644--- a/apps/mobile/src/__tests__/useSessionListActions.test.tsx+++ b/apps/mobile/src/__tests__/useSessionListActions.test.tsx@@ -66,7 +66,7 @@ describe('task list mark-read', () => {});});mount();- act(() => actions.sessionSwipeControls.onMarkRead(task));+ await markRead();if (change === 'restart-and-complete') {remoteSessionStore.applySessionActivity('host', { sessionId: 'task', phase: 'running' });// Same final label and phase: the newer run must still invalidate the old receipt.@@ -81,6 +81,41 @@ describe('task list mark-read', () => {expect(Alert.alert).not.toHaveBeenCalled();});+ // Same receipt invariant across both writes: late index data and queued run+ // writes cannot consume a completion produced after the gesture. A normal+ // attention-clear broadcast must not prevent reading the original run.+ it.each(['index', 'run-write', 'unchanged'])('fences automation reads across %s settling', async (stage) => {+ remoteSessionStore.applySessionActivity('host', { sessionId: 'task', phase: 'completed', attention: true, compactDetail: 'old' });+ const sentRunIds: string[] = [];+ let settle!: () => void;+ mocks.invoke.mockImplementation(async (_device: string, channel: string, args: unknown[], options?: { preSend?: () => void }) => {+ if (channel === 'notification:clear-session-attention') {+ options?.preSend?.();+ remoteSessionStore.applySessionActivity('host', { sessionId: 'task', phase: 'completed', attention: false });+ }+ if (channel === 'maker:schedule:list') return [{ id: 'schedule', name: 'Daily', status: 'active' }];+ if (channel === 'maker:schedule:list-sidebar-index-runs') throw new Error('[CHANNEL_NOT_ALLOWED] legacy index');+ if (channel === 'maker:schedule:list-runs') {+ if (stage === 'index') await new Promise<void>((resolve) => { settle = resolve; });+ return [{ id: 'run', scheduleId: 'schedule', sessionId: 'task', status: 'success', firedAt: 1 }];+ }+ if (channel === 'maker:schedule:mark-run-read') {+ if (stage === 'run-write') await new Promise<void>((resolve) => { settle = resolve; });+ options?.preSend?.();+ sentRunIds.push(args[0] as string);+ }+ });+ mount();+ await markRead({ ...task, source: 'scheduler' });+ if (stage !== 'unchanged') {+ remoteSessionStore.applySessionActivity('host', { sessionId: 'task', phase: 'error', attention: true, compactDetail: 'new' });+ await act(async () => settle());+ expect(remoteSessionStore.getSessionLiveActivity('task')).toMatchObject({ phase: 'error', attention: true });+ }+ expect(sentRunIds).toEqual(stage === 'unchanged' ? ['run'] : []);+ expect(Alert.alert).not.toHaveBeenCalled();+ });+it.each([undefined, 'route-host'])('writes ordinary task attention to the resolved Host (%s)', async (preferred) => {const host = preferred ?? 'host';await loadSharedSessionScheduleIndex(host, createMobileMakerTransport({ deviceId: host, invoke: mocks.invoke as RemoteInvoke }));@@ -107,7 +142,7 @@ describe('task list mark-read', () => {await markRead({ ...task, source: 'scheduler' });expect(mocks.invoke).toHaveBeenCalledWith('host', 'notification:clear-session-attention', ['task', 'explicit'], { preSend: expect.any(Function) });expect(mocks.invoke.mock.calls.filter((call) => call[1] === 'maker:schedule:mark-run-read'))- .toEqual([['host', 'maker:schedule:mark-run-read', ['unread']]]);+ .toEqual([['host', 'maker:schedule:mark-run-read', ['unread'], { preSend: expect.any(Function) }]]);expect(Alert.alert).not.toHaveBeenCalled();});@@ -143,4 +178,14 @@ describe('task list mark-read', () => {await markRead();expect(Alert.alert).toHaveBeenCalledWith('devices.list.alert.actionFailed', 'permission denied');});++ it('reports schedule lookup failure while still clearing the unchanged attention', async () => {+ mocks.invoke.mockImplementation(async (_device: string, channel: string) => {+ if (channel === 'maker:schedule:list') throw new Error('schedule unavailable');+ });+ mount();+ await markRead({ ...task, source: 'scheduler' });+ expect(mocks.invoke).toHaveBeenCalledWith('host', 'notification:clear-session-attention', ['task', 'explicit'], { preSend: expect.any(Function) });+ expect(Alert.alert).toHaveBeenCalledExactlyOnceWith('devices.list.alert.actionFailed', 'schedule unavailable');+ });});diff --git a/apps/mobile/src/session/useSessionListActions.ts b/apps/mobile/src/session/useSessionListActions.tsindex 9efbfcbf88..a388e0e22e 100644--- a/apps/mobile/src/session/useSessionListActions.ts+++ b/apps/mobile/src/session/useSessionListActions.ts@@ -267,24 +267,32 @@ export function useSessionListActions(options?: {const activityAtSwipe = remoteSessionStore.getSessionLiveActivity(session.id);const runAtSwipe = remoteSessionStore.getSessionRunStatus(session.id);const superseded = new Error('RECEIPT_SUPERSEDED');+ const isCurrent = () => remoteSessionStore.getSessionLiveActivity(session.id) === activityAtSwipe+ && remoteSessionStore.getSessionRunStatus(session.id) === runAtSwipe;const maker = createMobileMakerTransport({deviceId: devices.rpcDeviceId,invoke: (deviceId, channel, args) => channel !== 'notification:clear-session-attention'+ && channel !== 'maker:schedule:mark-run-read'? invoke(deviceId, channel, args): invoke(deviceId, channel, args, { preSend: () => {// Recheck after reconnect/backpressure. A new run invalidates even an identical completion label.- if (remoteSessionStore.getSessionLiveActivity(session.id) !== activityAtSwipe- || remoteSessionStore.getSessionRunStatus(session.id) !== runAtSwipe) throw superseded;+ if (!isCurrent()) throw superseded;} }),});- const writes: Promise<unknown>[] = [maker.clearSessionAttention(session.id, 'explicit').catch((err: unknown) => {- // Older Hosts lack this channel. Preserve schedule-read below and surface real failures.- if (err !== superseded && !isWorktreeChannelNotAllowedError(err)) throw err;- })];- if (sessionMayHaveScheduleRuns(devices.rpcDeviceId, session.id, session.source)) {- writes.push(markSessionScheduleRunsRead(maker, session.id, devices.rpcDeviceId));- }- void Promise.all(writes).catch((err: unknown) => {+ const scheduleRead = sessionMayHaveScheduleRuns(devices.rpcDeviceId, session.id, session.source)+ ? markSessionScheduleRunsRead(maker, session.id, devices.rpcDeviceId, isCurrent).catch((err: unknown) => {+ if (!isCurrent()) throw superseded;+ throw err;+ }) : Promise.resolve();+ // Clear attention last: its normal relay echo must not invalidate this gesture's schedule reads.+ // A schedule lookup failure still permits the independent attention write, and remains reportable.+ const attentionRead = scheduleRead.catch(() => undefined)+ .then(() => maker.clearSessionAttention(session.id, 'explicit')).catch((err: unknown) => {+ // Older Hosts lack this channel; schedule-read has already been attempted.+ if (err !== superseded && !isWorktreeChannelNotAllowedError(err)) throw err;+ });+ void Promise.all([scheduleRead, attentionRead]).catch((err: unknown) => {+ if (err === superseded) return;Alert.alert(t('devices.list.alert.actionFailed'), humanizeRemoteError(err));});}, [invoke, preferredRpcDeviceId, t]);