Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 发送已读前保留后来出现的任务提醒
Dash2024994206b4
diff --git a/apps/mobile/src/__tests__/useSessionListActions.test.tsx b/apps/mobile/src/__tests__/useSessionListActions.test.tsxindex 552e17c75f..c327830e98 100644--- a/apps/mobile/src/__tests__/useSessionListActions.test.tsx+++ b/apps/mobile/src/__tests__/useSessionListActions.test.tsx@@ -7,6 +7,7 @@ import { useSessionListActions } from '@/session/useSessionListActions';import { loadSharedSessionScheduleIndex, resetScheduleIndexThrottleForTesting } from '@/session/scheduleIndex';import { createMobileMakerTransport, type RemoteInvoke } from '@/device-link/mobileMakerTransport';import type { RemoteSession } from '@/session/types';+import { remoteSessionStore } from '@/session/remoteSessionStore';const mocks = vi.hoisted(() => ({ invoke: vi.fn() }));vi.mock('react-native', () => ({ Alert: { alert: vi.fn() } }));@@ -39,6 +40,7 @@ async function markRead(session = task) {beforeEach(() => {vi.clearAllMocks();resetScheduleIndexThrottleForTesting();+ remoteSessionStore.clear();mocks.invoke.mockImplementation(async (_device: string, channel: string) => {if (channel === 'maker:schedule:list') return [];if (channel === 'maker:schedule:list-sidebar-index-runs') return { runs: [] };@@ -49,13 +51,43 @@ beforeEach(() => {afterEach(() => act(() => root.unmount()));describe('task list mark-read', () => {+ it.each(['unchanged', 'error', 'completed', 'restart-and-complete'])('checks queued attention against the swipe snapshot (%s)', async (change) => {+ remoteSessionStore.applySessionActivity('host', { sessionId: 'task', phase: 'completed', attention: true, compactDetail: 'original' });+ const send = vi.fn();+ let flush!: () => void;+ mocks.invoke.mockImplementation((_device: string, channel: string, _args: unknown[], options?: { preSend?: () => void }) => {+ if (channel !== 'notification:clear-session-attention') {+ return Promise.resolve(channel === 'maker:schedule:list-sidebar-index-runs' ? { runs: [] } : []);+ }+ return new Promise<void>((resolve, reject) => {+ flush = () => {+ try { options?.preSend?.(); send(); resolve(); } catch (error) { reject(error); }+ };+ });+ });+ mount();+ act(() => actions.sessionSwipeControls.onMarkRead(task));+ 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.+ remoteSessionStore.applySessionActivity('host', { sessionId: 'task', phase: 'completed', attention: true, compactDetail: 'original' });+ } else if (change !== 'unchanged') {+ remoteSessionStore.applySessionActivity('host', { sessionId: 'task', phase: change, attention: true, compactDetail: 'new' });+ }+ const latest = remoteSessionStore.getSessionLiveActivity('task');+ await act(async () => flush());+ expect(send).toHaveBeenCalledTimes(change === 'unchanged' ? 1 : 0);+ expect(remoteSessionStore.getSessionLiveActivity('task')).toBe(latest);+ 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 }));mocks.invoke.mockClear();mount(preferred);await markRead();- expect(mocks.invoke.mock.calls).toEqual([[host, 'notification:clear-session-attention', ['task', 'explicit']]]);+ expect(mocks.invoke.mock.calls).toEqual([[host, 'notification:clear-session-attention', ['task', 'explicit'], { preSend: expect.any(Function) }]]);expect(Alert.alert).not.toHaveBeenCalled();});@@ -73,7 +105,7 @@ describe('task list mark-read', () => {});mount();await markRead({ ...task, source: 'scheduler' });- expect(mocks.invoke).toHaveBeenCalledWith('host', 'notification:clear-session-attention', ['task', 'explicit']);+ 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']]]);expect(Alert.alert).not.toHaveBeenCalled();diff --git a/apps/mobile/src/session/useSessionListActions.ts b/apps/mobile/src/session/useSessionListActions.tsindex 23ee2c56e9..9efbfcbf88 100644--- a/apps/mobile/src/session/useSessionListActions.ts+++ b/apps/mobile/src/session/useSessionListActions.ts@@ -264,10 +264,22 @@ export function useSessionListActions(options?: {Alert.alert(t('devices.list.alert.actionFailed'), t('devices.list.error.sessionDeviceNotFound'));return;}- const maker = createMobileMakerTransport({ deviceId: devices.rpcDeviceId, invoke });+ const activityAtSwipe = remoteSessionStore.getSessionLiveActivity(session.id);+ const runAtSwipe = remoteSessionStore.getSessionRunStatus(session.id);+ const superseded = new Error('RECEIPT_SUPERSEDED');+ const maker = createMobileMakerTransport({+ deviceId: devices.rpcDeviceId,+ invoke: (deviceId, channel, args) => channel !== 'notification:clear-session-attention'+ ? 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;+ } }),+ });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 (!isWorktreeChannelNotAllowedError(err)) throw err;+ if (err !== superseded && !isWorktreeChannelNotAllowedError(err)) throw err;})];if (sessionMayHaveScheduleRuns(devices.rpcDeviceId, session.id, session.source)) {writes.push(markSessionScheduleRunsRead(maker, session.id, devices.rpcDeviceId));