Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(remote): 统一空历史交接清理并补齐滚动测试环境
Dasha1b4a73a5191
diff --git a/apps/desktop/src/renderer/__tests__/remoteHistoryHandoff.test.ts b/apps/desktop/src/renderer/__tests__/remoteHistoryHandoff.test.tsindex 5e30490375..b25f98d91b 100644--- a/apps/desktop/src/renderer/__tests__/remoteHistoryHandoff.test.ts+++ b/apps/desktop/src/renderer/__tests__/remoteHistoryHandoff.test.ts@@ -53,13 +53,14 @@ function fixture() {}describe('desktop remote history uses the shared live-to-history handoff', () => {- it('lets a newer empty page retire a list receipt before the raw deletion push arrives', async () => {+ it.each([false, true])('lets a newer empty page retire a receipt before the raw deletion push arrives (streamed=%s)', async (streamed) => {const { view, render, setSource } = fixture();const readReceipt = nextHistoryCacheReceipt();- const received = { ...row('reply'), cacheReceipt: nextHistoryCacheReceipt() };+ let received = { ...row('reply', streamed), cacheReceipt: nextHistoryCacheReceipt() };view.setActive(false);await view.restoreCachedView(async () => ({ ...view.getSnapshot(), ready: true, readReceipt }));expect(render([received]).text).toContain('visible answer');+ received = { ...received, isStreaming: false };setSource([]);view.setActive(true);await view.refresh();@@ -67,6 +68,7 @@ describe('desktop remote history uses the shared live-to-history handoff', () =>view.setActive(false);expect(render([received]).items).toEqual([]);expect(render([received]).state.tail.size).toBe(0);+ expect(render([received]).state.pending.size).toBe(0);});// Unit: reproduce the list-receipt/history timestamp disagreement through thediff --git a/apps/mobile/src/__tests__/messageFollowGesture.test.ts b/apps/mobile/src/__tests__/messageFollowGesture.test.tsindex e7f3a75288..c42c096e94 100644--- a/apps/mobile/src/__tests__/messageFollowGesture.test.ts+++ b/apps/mobile/src/__tests__/messageFollowGesture.test.ts@@ -71,6 +71,7 @@ function harness(richContent: RichContentRuntime | null = new RichContentRuntime// Companion receipt behavior is covered by the mounted MessageRenderer tests.acknowledgeCompanionReadRef: ref(vi.fn()),shareSelectionActiveRef: ref(false),+ itemsForStructureRef: ref([]),scrollMetricsRef: ref({ contentHeight: 2000, offsetY: 1200, viewportHeight: 800 }),};const tailScroll = vi.fn((_options: { animated: boolean }) => {@@ -79,6 +80,7 @@ function harness(richContent: RichContentRuntime | null = new RichContentRuntime});const environment = {richContent,+ remoteDeviceId: 'remote-device', scrollResetKey: 'session',readingPosition: { write: vi.fn() }, reopeningPosition: undefined,captureCurrentHistoryAnchor: vi.fn((): { key: string; viewportOffset: number } | null => null),getCurrentHistoryTopOffsetAdjustment: vi.fn(() => 0),diff --git a/apps/mobile/src/__tests__/mobileHistoryHandoff.test.ts b/apps/mobile/src/__tests__/mobileHistoryHandoff.test.tsindex a29da2bef6..4d0e6d102d 100644--- a/apps/mobile/src/__tests__/mobileHistoryHandoff.test.ts+++ b/apps/mobile/src/__tests__/mobileHistoryHandoff.test.ts@@ -15,9 +15,9 @@ const createHandoff = () => new HistoryViewHandoff<RemoteMessage>((row) => row.adescribe('mobile history handoff', () => {// A later authoritative read can omit a removed row entirely. Its list receipt// must retire even if a separate raw-store deletion push has not arrived yet.- it('retires a received body after a newer empty page, including reentry', async () => {+ it.each([false, true])('retires a received body after a newer empty page, including reentry (streamed=%s)', async (streamed) => {const readReceipt = nextHistoryCacheReceipt();- const received = { ...row('answer'), cacheReceipt: nextHistoryCacheReceipt() };+ let received = { ...row('answer', streamed), cacheReceipt: nextHistoryCacheReceipt() };let hasMore = true;const view = new HistoryViewController<RemoteMessage>({refreshOnResume: false,@@ -36,21 +36,56 @@ describe('mobile history handoff', () => {staleTail: state.tail, pendingHandoff: state.pending, streaming: true, sessionId: 's' }) };};expect(render().state.tail.has('answer')).toBe(true);+ // The raw store finalizes before the authoritative empty read, while its+ // deletion push lags. Both pending and tail must yield to that read.+ received = { ...received, agentMeta: null };view.setActive(true);await view.refresh();// A latest-page window cannot prove an absent older row was deleted.- expect(render().state.tail.has('answer')).toBe(true);+ expect(render().items.filter(item => item.type === 'message')+ .some(item => item.message.body === 'visible answer')).toBe(true);hasMore = false;await view.refresh();for (const active of [true, false, true]) {view.setActive(active);const result = render();expect(result.state.tail.size).toBe(0);+ expect(result.state.pending.size).toBe(0);expect(result.items.filter(item => item.type === 'message')).toEqual([]);}view.setActive(false);});+ // Unit, review #6401: empty reads cannot retire a finalized streaming body+ // received after the read began, or one without comparable receipt evidence.+ // Existing empty-page coverage only exercised a receipt older than the read.+ it.each(['newer', 'unmarked'] as const)('preserves pending content without superseding receipt evidence (%s)', async (receipt) => {+ const view = new HistoryViewController<RemoteMessage>({+ refreshOnResume: false,+ page: async () => ({ version: 1, items: [], hasMore: false, nextCursor: null }),+ details: async () => ({ version: 1, messages: [], hasMore: false, nextCursor: null }), expanded: async () => undefined,+ });+ view.setActive(false);+ await view.restoreCachedView(async () => ({ ...view.getSnapshot(), ready: true, readReceipt: nextHistoryCacheReceipt() }));+ const handoff = createHandoff();+ let received: RemoteMessage = { ...row('answer', true), cacheReceipt: nextHistoryCacheReceipt() };+ const render = () => {+ const snapshot = view.getSnapshot();+ const state = handoff.reconcile(snapshot, [received]);+ return buildMobileHistoryRenderItems({ view, snapshot, messages: state.messages,+ pendingHandoff: state.pending, staleTail: state.tail, streaming: false, sessionId: 's' })+ .filter(item => item.type === 'message').map(item => item.message.body);+ };+ expect(render()).toEqual(['visible answer']);+ view.setActive(true);+ const reading = view.refresh();+ received = { ...row('answer'), cacheReceipt: receipt === 'newer' ? nextHistoryCacheReceipt() : undefined };+ await reading;+ expect(render()).toEqual(['visible answer']);+ view.setActive(false);+ expect(render()).toEqual(['visible answer']);+ });+// #6293 orders received bodies by local receipt, not Host timestamps. The// renderer must honor that decision too when a late row predates the page tail.it.each([true, false])('keeps a received earlier-timestamp answer through cached/fresh history (stale=%s)', async (stale) => {diff --git a/packages/maker-shared/src/historyViewHandoff.ts b/packages/maker-shared/src/historyViewHandoff.tsindex 46d72b5ab5..f26b3e9672 100644--- a/packages/maker-shared/src/historyViewHandoff.ts+++ b/packages/maker-shared/src/historyViewHandoff.ts@@ -49,11 +49,18 @@ export class HistoryViewHandoff<T extends HistoryMessageSource> {// received after this page's read began must remain visible even if that// older page arrives later. Fresh reads also retire receipts from an earlier run.const receivedAfterRead = (row: T) => historyCacheReceiptFollows(row.cacheReceipt, snapshot.readReceipt, snapshot.stale);+ // Only a complete, authoritative empty read can prove an absent body was+ // removed. Apply the same receipt evidence before either handoff is merged.+ const cleared = snapshot.ready && !snapshot.stale && !snapshot.hasMore && snapshot.items.length === 0;+ const supersededByEmptyRead = (row: T) => cleared+ && isHistoryCacheReceipt(row.cacheReceipt) && isHistoryCacheReceipt(snapshot.readReceipt)+ && !receivedAfterRead(row);const current = new Set(raw.map(row => row.clientId));for (const id of this.pending) if (!current.has(id)) this.pending.delete(id);for (const row of raw) {if (row.role !== 'assistant') continue;- if (this.streaming(row)) this.pending.add(row.clientId);+ if (supersededByEmptyRead(row)) this.pending.delete(row.clientId);+ else if (this.streaming(row)) this.pending.add(row.clientId);else if (history.has(row.clientId) && !this.streaming(history.get(row.clientId)!)) this.pending.delete(row.clientId);}const pending = new Set(this.pending);@@ -62,15 +69,10 @@ export class HistoryViewHandoff<T extends HistoryMessageSource> {const known = history.get(row.clientId);history.set(row.clientId, known ? liveContentWithHistoryOrder(row, known) : row);}- // An authoritative empty history retires older receipts even if the raw- // deletion push lags behind it. A nonempty paged window cannot prove an- // absent older row was deleted; keep the existing coverage/removal rule.- const cleared = !snapshot.stale && !snapshot.hasMore && snapshot.items.length === 0;const rawById = new Map(raw.map(row => [row.clientId, row]));for (const id of this.tail) {const row = rawById.get(id);- if (!row || (!receivedAfterRead(row) && (history.has(id)- || (cleared && isHistoryCacheReceipt(row.cacheReceipt) && isHistoryCacheReceipt(snapshot.readReceipt))))) {+ if (!row || supersededByEmptyRead(row) || (history.has(id) && !receivedAfterRead(row))) {this.tail.delete(id);}}