Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 按主机历史顺序判断缓存窗口交接
Dash5412958aca32
diff --git a/apps/mobile/src/__tests__/outboxHistoryCache.test.ts b/apps/mobile/src/__tests__/outboxHistoryCache.test.tsindex 153697803b..e5dc7bc8ab 100644--- a/apps/mobile/src/__tests__/outboxHistoryCache.test.ts+++ b/apps/mobile/src/__tests__/outboxHistoryCache.test.ts@@ -87,11 +87,45 @@ describe('outbox to offline history handoff', () => {await opened([row('newer', 3)]);expect(await save()).toBe(true);});- it.each([2, undefined])('does not infer handoff from skewed timestamps (rowid=%s)', async (rowid) => {- state.rows = [{ ...row('sent', 0), rowid }];+ it('keeps a new send when older history was imported with larger rowids', async () => {+ await opened([{ ...row('imported', 1), rowid: 100 }]);+ expect(await save()).toBe(false);+ });+ it('uses persisted host chronology even when insertion order differs', async () => {+ state.rows = [{ ...row('sent', 0), rowid: 100 }];+ await opened([row('newer', 1)]);+ expect(await save()).toBe(true);+ });+ it.each([1, 2, 3])('uses rowid only to break equal host timestamps (rowid=%s)', async (rowid) => {+ await opened([{ ...row('boundary', 2), rowid }]);+ expect(await save()).toBe(rowid > 2);+ });+ it.each(['sent', 'boundary'])('retains ownership when %s lacks a persisted rowid', async (missing) => {+ state.rows = [{ ...row('sent', 0), rowid: missing === 'sent' ? undefined : 2 }];+ await opened([{ ...row('previous', 1), rowid: missing === 'boundary' ? undefined : 1 }]);+ expect(await save()).toBe(false);+ });+ it('does not infer handoff from invalid host timestamps', async () => {+ state.rows = [{ ...row('sent', 0), createdAt: 'invalid' }];await opened([row('previous', 1)]);expect(await save()).toBe(false);});+ it('finds the message boundary after leading folded work and restores that window offline', async () => {+ const { entry } = await opened([+ { ...row('work', 3), role: 'thinking', content: 'working' },+ { ...row('answer', 4), role: 'assistant', agentMeta: { turnCompleted: true } },+ ]);+ expect(entry.view.getSnapshot().items[0].type).toBe('work');+ expect(await save()).toBe(true);+ const cached = await readHistoryDisk(historyDiskAuthority('d', 's'));+ expect(cached?.items[0].type).toBe('work');+ const network = vi.fn(async () => { throw new Error('offline'); });+ const cold = new HistoryViewController<RemoteMessage>({ page: network, details: network, expanded: async () => {} });+ cold.setNetworkAvailable(false);+ await cold.restoreCachedView(async () => cached);+ expect(cold.getSnapshot().items).toEqual(cached?.items);+ expect(network).not.toHaveBeenCalled();+ });it.each(['UNSUPPORTED_CAPABILITY', 'CHANNEL_NOT_ALLOWED'])('persists the raw fallback for %s hosts', async (error) => {await opened([], error);state.fail = true;diff --git a/apps/mobile/src/session/outboxHistoryCache.ts b/apps/mobile/src/session/outboxHistoryCache.tsindex 86232622fc..58b523cec6 100644--- a/apps/mobile/src/session/outboxHistoryCache.ts+++ b/apps/mobile/src/session/outboxHistoryCache.ts@@ -11,11 +11,14 @@ function coversMessage(snapshot: HistoryViewSnapshot<RemoteMessage>, message: Reconst leaves = historyViewLeaves(snapshot.items);if (leaves.some(item => item.type === 'messages'&& item.messages.some(row => row.role === 'user' && row.clientId === message.clientId))) return true;- // Only host insertion order can prove the row aged out; timestamps may skew.- const first = leaves[0];- const oldest = first?.type === 'messages' ? first.messages[0]?.rowid : undefined;- return typeof message.rowid === 'number' && typeof oldest === 'number'- && Number.isFinite(message.rowid) && Number.isFinite(oldest) && message.rowid < oldest;+ // User rows never fold into work. Skip leading work to find a stored boundary,+ // and use the host's (createdAt, rowid) order, not import/insertion order alone.+ const first = leaves.find(item => item.type === 'messages' && item.messages.length > 0);+ const oldest = first?.type === 'messages' ? first.messages[0] : undefined;+ if (!oldest || !Number.isFinite(message.rowid) || !Number.isFinite(oldest.rowid)) return false;+ const sentAt = Date.parse(message.createdAt), oldestAt = Date.parse(oldest.createdAt);+ return Number.isFinite(sentAt) && Number.isFinite(oldestAt)+ && (sentAt < oldestAt || (sentAt === oldestAt && message.rowid! < oldest.rowid!));}/** Keep the existing durable outbox until the representation used on reentry is on disk. */