Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(device-link): reset history views on destructive pushes
Dash081408958b49
diff --git a/apps/desktop/src/renderer/__tests__/deviceLinkControllerScenarios.test.ts b/apps/desktop/src/renderer/__tests__/deviceLinkControllerScenarios.test.tsindex 2de91ff594..aade8d9695 100644--- a/apps/desktop/src/renderer/__tests__/deviceLinkControllerScenarios.test.ts+++ b/apps/desktop/src/renderer/__tests__/deviceLinkControllerScenarios.test.ts@@ -161,6 +161,10 @@ function makeFakeHost(deviceId: string, deviceName: string) {messages.set(sid, arr);if (!opts?.lossy) pushCb?.({ deviceId, channel: 'local-db:messages:created', payload: { sessionId: sid, message: msg } });},+ hostDelete(sid: string, clientIds: string[]): void {+ messages.set(sid, (messages.get(sid) ?? []).filter((row) => !clientIds.includes(row.clientId)));+ pushCb?.({ deviceId, channel: 'local-db:messages:deleted', payload: { sessionId: sid, clientIds } });+ },/** 被控端改某会话设置 → 广播 sessions:patched(控制端镜像收敛)。 */hostPatch(sid: string, patch: Record<string, unknown>): void {sessionsMeta.set(sid, { ...(sessionsMeta.get(sid) ?? {}), ...patch });@@ -586,6 +590,33 @@ describe('device-link controller mirror — end-to-end scenarios', () => {}});+ it.each(['delete', 'clear'])('retires loaded older projection pages after a remote %s', async (operation) => {+ const s = sid();+ host.enableHistoryView();+ const rows = Array.from({ length: 30 }, (_, index) => dbMessage(s, String(index), 'visible',+ new Date(1_750_000_000_000 + index * 1000).toISOString(), 'user'));+ host.seedSession(s, { clearedAt: null }, rows);+ remoteProjectsStore.setDeviceSessions(DEVICE_ID, 'Mac A', [{ id: s } as Session]);+ makerChatStore.ensureInitialMessages(s);+ await flush(); await flush();+ const view = getRemoteHistoryView(s)!;+ await view.refresh(true);+ expect(view.getSnapshot().items).toHaveLength(30);+ host.hostPatch(s, { title: 'ordinary metadata' });+ expect(view.getSnapshot().items).toHaveLength(30);+ if (operation === 'delete') host.hostDelete(s, [rows[0].clientId]);+ else {+ host.seedSession(s, {}, []);+ host.hostPatch(s, { clearedAt: '2026-09-08T10:00:00Z' });+ }+ expect(view.getSnapshot().items).toEqual([]);+ expect(makerChatStore.getSnapshot(s).messages.some((row) => row.clientId === rows[0].clientId)).toBe(false);+ await flush(); await flush();+ expect(view.getSnapshot().ready).toBe(true);+ expect(view.getSnapshot().items).toHaveLength(operation === 'delete' ? 20 : 0);+ view.setActive(false);+ });+it('returns to raw history when a previously capable Host is downgraded', async () => {const s = sid();host.enableHistoryView();diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.tsindex 1375a0f7cb..67da8b3fea 100644--- a/apps/desktop/src/renderer/lib/makerChatStore.ts+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts@@ -8532,6 +8532,9 @@ function initGlobalListeners(options: GlobalListenerOptions = {}): void {const ownsSession = getStickySessionDeviceId(p.sessionId) === push.deviceId;if (Object.prototype.hasOwnProperty.call(p.patch, 'clearedAt')) {observeRemoteInputClearBoundary(p.sessionId, p.patch.clearedAt);+ if (!terminal && ownsSession && typeof p.patch.clearedAt === 'string' && getRemoteHistoryView(p.sessionId)) {+ reloadMessages(p.sessionId);+ }}remoteProjectsStore.applyPatch(push.deviceId, p.sessionId, p.patch);if (terminal && ownsSession) {diff --git a/apps/mobile/src/__tests__/sessionSyncProductionCallbacks.test.ts b/apps/mobile/src/__tests__/sessionSyncProductionCallbacks.test.tsindex a7589deb16..bc30bc5814 100644--- a/apps/mobile/src/__tests__/sessionSyncProductionCallbacks.test.ts+++ b/apps/mobile/src/__tests__/sessionSyncProductionCallbacks.test.ts@@ -306,3 +306,44 @@ describe('production session recovery callbacks', () => {expect(f.store.mergeEarlierMessages).toHaveBeenCalledTimes(1);});});++// Run the production push routing tail with real projection generations.+describe('destructive remote history pushes', () => {+ it.each(['delete', 'clear', 'archive', 'initial-delete'])('retires old pages on %s without an unrelated activity event', async (operation) => {+ const context = readFileSync(resolve(process.cwd(), 'src/device-link/DeviceLinkContext.tsx'), 'utf8');+ const body = context.slice(context.indexOf(' const historySessionId ='), context.indexOf('/** provider revision')).trim().slice(0, -1);+ const stale = { id: 'old', clientId: 'old', role: 'user', content: 'old', createdAt: '2026-09-08T00:00:00Z' };+ const oldPage = { version: 1 as const, items: projectHistoryView([stale], false), hasMore: false, nextCursor: null };+ const delayed = deferred<typeof oldPage>();+ let reads = 0;+ const view = new HistoryViewController({+ page: async () => ++reads === 1 ? (operation === 'initial-delete' ? delayed.promise : oldPage)+ : { ...oldPage, items: [] },+ details: async () => ({ version: 1, messages: [], hasMore: false, nextCursor: null }),+ expanded: async () => undefined,+ });+ const first = view.refresh();+ if (operation !== 'initial-delete') await first;+ let raw = [stale];+ const store = {+ applyRemotePush: vi.fn(() => { if (operation !== 'clear') raw = []; }),+ invalidateSessionMessageWindow: vi.fn(() => { raw = []; }),+ };+ const push = operation === 'clear' || operation === 'archive'+ ? { channel: 'local-db:sessions:patched', payload: { sessionId: 's', patch: operation === 'clear'+ ? { clearedAt: '2026-09-08T01:00:00Z' } : { status: 'archived' } } }+ : { channel: 'local-db:messages:deleted', payload: { sessionId: 's', clientIds: ['old'] } };+ const compiled = ts.transpileModule(body, { compilerOptions: { target: ts.ScriptTarget.ES2022 } }).outputText;+ const route = new Function('push', 'env', 'findRemoteHistoryView', 'remoteSessionStore', compiled);+ route(push, { src: 'device-a' }, (device: string, session: string) => device === 'device-a' && session === 's' ? view : undefined, store);+ expect(raw).toEqual([]);+ expect(view.getSnapshot().items).toEqual([]);+ expect(view.getSnapshot().details.size).toBe(0);+ if (operation === 'initial-delete') delayed.resolve(oldPage);+ await first; await tick();+ expect(view.getSnapshot().items).toEqual([]);+ expect(view.isActive()).toBe(operation !== 'archive');+ if (operation === 'clear') expect(store.invalidateSessionMessageWindow).toHaveBeenCalledWith('s', 'device-a');+ view.setActive(false);+ });+});diff --git a/apps/mobile/src/device-link/DeviceLinkContext.tsx b/apps/mobile/src/device-link/DeviceLinkContext.tsxindex dbd28721ac..01fe4c8bc0 100644--- a/apps/mobile/src/device-link/DeviceLinkContext.tsx+++ b/apps/mobile/src/device-link/DeviceLinkContext.tsx@@ -1392,7 +1392,19 @@ export function routeFrame(env: Envelope, handlers: {return;}remoteSessionStore.applyRemotePush(env.src, push.channel, push.payload);- if (historyView?.getSnapshot().ready && (push.channel === 'local-db:messages:created' || push.channel === 'maker:status-changed')) historyView.invalidate();+ const patch = (push.payload as { patch?: { clearedAt?: unknown; status?: unknown } } | null)?.patch;+ if (historyView && push.channel === 'local-db:sessions:patched'+ && (patch?.status === 'deleted' || patch?.status === 'archived')) {+ historyView.setActive(false);+ historyView.reset();+ } else if (historyView && push.channel === 'local-db:sessions:patched' && typeof patch?.clearedAt === 'string') {+ // reset switches the screen back to its raw mirror until the fresh view arrives.+ // Retire that mirror too so a failed refresh cannot reveal pre-clear messages.+ remoteSessionStore.invalidateSessionMessageWindow(historySessionId as string, env.src);+ historyView.reset();+ } else if (historyView && push.channel === 'local-db:messages:deleted') {+ historyView.reset();+ } else if (historyView?.getSnapshot().ready && (push.channel === 'local-db:messages:created' || push.channel === 'maker:status-changed')) historyView.invalidate();}/** provider revision 后并行重拉所有 agent 的能力;旧代或异常结果都不触碰当前页面。 */diff --git a/packages/maker-shared/src/__tests__/historyView.test.ts b/packages/maker-shared/src/__tests__/historyView.test.tsindex e79e59cc36..0aafc20e07 100644--- a/packages/maker-shared/src/__tests__/historyView.test.ts+++ b/packages/maker-shared/src/__tests__/historyView.test.ts@@ -241,6 +241,28 @@ describe('shared history view lifecycle', () => {expect(intents.at(-1)).toEqual([]);});+ it.each([false, true])('releases old detail interest when reset before a replacement page is ready (inactive=%s)', async (inactive) => {+ const items = projectHistoryView([row(1, 'thinking', 'body')], true);+ let first = true;+ const expanded = vi.fn(async () => undefined);+ const view = new HistoryViewController<HistoryMessageSource>({+ page: () => first ? (first = false, Promise.resolve({ version: 1, items, hasMore: false, nextCursor: null }))+ : new Promise(() => undefined),+ details: async () => ({ version: 1, messages: [], hasMore: false, nextCursor: null }),+ expanded,+ });+ await view.refresh();+ view.setExpanded(items[0].key, true);+ await new Promise((done) => setTimeout(done, 0));+ expect(expanded).toHaveBeenLastCalledWith([items[0].type === 'work' ? items[0].summary : undefined]);+ if (inactive) view.setActive(false);+ view.reset();+ await new Promise((done) => setTimeout(done, 0));+ expect(view.getSnapshot().ready).toBe(false);+ expect(expanded).toHaveBeenLastCalledWith([]);+ view.setActive(false);+ });+it('does not revive durable messages removed by rewind through the live overlay', async () => {const view = new HistoryViewController<HistoryMessageSource>({page: async () => ({ version: 1, items: projectHistoryView([row(1, 'user', 'kept')], false), hasMore: false, nextCursor: null }),diff --git a/packages/maker-shared/src/historyViewController.ts b/packages/maker-shared/src/historyViewController.tsindex b89c650b4a..d032fa6799 100644--- a/packages/maker-shared/src/historyViewController.ts+++ b/packages/maker-shared/src/historyViewController.ts@@ -152,7 +152,7 @@ export class HistoryViewController<T extends HistoryMessageSource> {const generation = this.generation;this.intentQueue.tail = this.intentQueue.tail.catch(() => undefined).then(async () => {if (generation !== this.generation) return;- if (!this.state.ready) return;+ // Empty replacement intents must release old interest even before a reset view is ready.const summaries = this.active ? historyWorkSummaries(this.state.items).filter((item) => this.state.expanded.has(item.key)) : [];await this.transport.expanded(summaries);}).catch(() => {