Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(history): 修复手机打开长 Codex 任务时历史退回逐条加载、每页过少 (#5434)
Dashf7a739e5ab17
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/historyViewOutline.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/historyViewOutline.test.tsindex 94fecb15d1..3e052426e4 100644--- a/apps/desktop/src/main/localDb/ipc/__tests__/historyViewOutline.test.ts+++ b/apps/desktop/src/main/localDb/ipc/__tests__/historyViewOutline.test.ts@@ -25,6 +25,16 @@ describe('SQLite history outline', () => {const result = withHistoryArtifacts({ id: '1', clientId: '1', role: 'tool_use', content, createdAt: '2026-09-25T00:00:00Z' });expect(result.historyArtifacts).toMatchObject([{ path: '/work/report.md', source: 'tool' }]);});+ it('folds plain-text tool output while keeping artifact candidates and failures', () => {+ const body = 'Checking original UI image catalogs: 55\n'.repeat(50000);+ expect(outline('tool_result', body, null, true)).toBe('');+ expect(outline('tool_result', `<tool_use_error>${body}`, null, true)).toBe('<tool_use_error>');+ expect(outline('tool_result', 'saved cindy-media://blobs/a.png', null, true)).toBe('saved cindy-media://blobs/a.png');+ expect(outline('tool_result', 'xdt-file:///work/report.pdf', null, true)).toBe('xdt-file:///work/report.pdf');+ // Incidental mentions in long output must not keep the whole body.+ expect(outline('tool_result', `const xdt_helper = 1;\n${body}`, null, true)).toBe('');+ expect(outline('tool_result', `${body}see xdt-file:///work/report.pdf`, null, true)).toBe('');+ });it('keeps visible prose, artifacts and malformed legacy bodies intact', () => {expect(outline('assistant', 'Final answer')).toBe('Final answer');expect(outline('assistant', 'Internal prose', { parentUuid: 'agent' })).toBe('');diff --git a/apps/desktop/src/main/localDb/ipc/historyViewOutline.ts b/apps/desktop/src/main/localDb/ipc/historyViewOutline.tsindex 02793f7cc3..77721bde39 100644--- a/apps/desktop/src/main/localDb/ipc/historyViewOutline.ts+++ b/apps/desktop/src/main/localDb/ipc/historyViewOutline.ts@@ -8,10 +8,19 @@ import { messages } from '../schema';/** Read-model headers only. Full content is read by ID after visible items are selected.* Candidate artifact results are conservative: the shared parser remains authoritative.* Invalid legacy JSON stays intact instead of disappearing from the history.+ * Plain-text tool output (Codex stores most results this way) is folded like a+ * JSON result; otherwise one long turn exhausts the scan budget on outlines alone.+ * Media and card payloads require JSON, so plain text can only carry `xdt-file://`+ * links or a bare `cindy-media://` URL. Real deliveries are short; long logs that+ * merely mention those schemes are folded too.*/export function historyOutlineContent(): SQL<string> {const body = messages.content;return sql<string>`CASE+ WHEN ${messages.role} = 'tool_result' AND NOT json_valid(${body})+ AND NOT (length(${body}) <= 16384+ AND (instr(${body}, 'xdt-file://') > 0 OR instr(${body}, 'cindy-media://') > 0))+ THEN json_quote(CASE WHEN instr(${body}, '<tool_use_error>') > 0 THEN '<tool_use_error>' ELSE '' END)WHEN NOT json_valid(${body}) THEN ${body}WHEN ${messages.role} = 'thinking' THEN json_object('isRedacted', json(CASEWHEN (json_type(${body}, '$') = 'text' AND length(json_extract(${body}, '$')) > 0)diff --git a/apps/mobile/src/__tests__/remoteHistoryReentry.test.ts b/apps/mobile/src/__tests__/remoteHistoryReentry.test.tsindex ff4f681134..5ccd90561c 100644--- a/apps/mobile/src/__tests__/remoteHistoryReentry.test.ts+++ b/apps/mobile/src/__tests__/remoteHistoryReentry.test.ts@@ -51,6 +51,23 @@ describe('history reentry', () => {expect(entry.view.getSnapshot()).toMatchObject({ ready: true, items: [] });});+ it('retries the projection when a downgraded task is entered again', async () => {+ const source = reader();+ source.readHistoryView.mockRejectedValueOnce(new Error('[UNSUPPORTED_CAPABILITY] History view scan budget exceeded'));+ const entry = getRemoteHistoryView('d', 'downgraded', source);+ const release = mount(entry, source);+ await entry.view.refresh();+ expect(String(entry.view.getSnapshot().error)).toContain('UNSUPPORTED_CAPABILITY');+ // Within one entry the raw fallback stays put.+ await entry.view.refresh();+ expect(source.readHistoryView).toHaveBeenCalledTimes(1);+ release();+ mount(entry, source);+ await entry.view.refresh();+ expect(entry.view.getSnapshot()).toMatchObject({ ready: true, error: null });+ expect(JSON.stringify(entry.view.getSnapshot().items)).toContain('unchanged answer');+ });+it('does not register abandoned renders', () => {getRemoteHistoryView('d', 's', reader());expect(findRemoteHistoryView('d', 's')).toBeUndefined();diff --git a/apps/mobile/src/session/remoteHistoryViews.ts b/apps/mobile/src/session/remoteHistoryViews.tsindex 5fe05de86f..4bf378eb79 100644--- a/apps/mobile/src/session/remoteHistoryViews.ts+++ b/apps/mobile/src/session/remoteHistoryViews.ts@@ -72,8 +72,11 @@ export function mountRemoteHistoryView(entry: Entry, reader: Reader, active: bootimer = setTimeout(persist, 1200);};const unsubscribe = entry.view.subscribe(onSnapshot);- // Retire an existing downgrade before activation can clear its error for a retry.+ // Retire an existing downgrade (clearing its disk projection), then retry the+ // projection once per entry: a refresh never leaves raw fallback on its own,+ // and the Host may since have become able to serve this history.onSnapshot();+ if (isHistoryViewUnavailable(entry.view.getSnapshot().error)) entry.view.reset();entry.view.setActive(active);void entry.view.restoreCachedView(() => readHistoryDisk(authority));return () => {diff --git a/packages/maker-shared/src/__tests__/historyView.test.ts b/packages/maker-shared/src/__tests__/historyView.test.tsindex a0a439dadf..4b874abd55 100644--- a/packages/maker-shared/src/__tests__/historyView.test.ts+++ b/packages/maker-shared/src/__tests__/historyView.test.ts@@ -1,6 +1,6 @@import { describe, expect, it, vi } from 'vitest';import { projectHistoryView } from '../historyViewProjection.js';-import { isHistoryViewUnavailable, readHistoryWorkDetails, type HistoryMessageSource } from '../historyView.js';+import { historyWorkSummaries, isHistoryViewUnavailable, readHistoryWorkDetails, type HistoryMessageSource } from '../historyView.js';function row(id: number, role: string, content: unknown): HistoryMessageSource {return { id: String(id), clientId: `c${id}`, role, content,@@ -41,6 +41,22 @@ describe('history reading projection', () => {expect(visible.map((item) => item.id)).toEqual(['0', '2', '3', '4', '5', '6']);});+ it('keeps file artifacts on leaf summaries only, once per nesting level', () => {+ const tool = (id: number, toolUseId: string, path: string): HistoryMessageSource[] => [+ { ...row(id, 'tool_use', { toolName: 'Bash', toolUseId, input: { command: `echo > ${path}` } }), toolUseId,+ historyArtifacts: [{ path, source: 'command', createdAt: row(id, '', '').createdAt, toolUseId }] },+ { ...row(id + 1, 'tool_result', ''), toolUseId }];+ const rows = [row(0, 'user', 'Work'), row(1, 'thinking', 'plan'), ...tool(2, 'a', '/work/a.txt'),+ row(4, 'assistant', 'Halfway there'), row(5, 'thinking', 'more'), ...tool(6, 'b', '/work/b.txt'),+ { ...row(8, 'assistant', 'Done'), agentMeta: { turnCompleted: true } }];+ const projected = projectHistoryView(rows, false, true);+ const outer = projected.find((item) => item.type === 'work' && item.children);+ expect(outer?.type).toBe('work');+ expect(outer?.type === 'work' && 'artifacts' in outer.summary).toBe(false);+ expect(historyWorkSummaries(projected).flatMap((summary) => summary.artifacts ?? []).map((file) => file.path))+ .toEqual(['/work/a.txt', '/work/b.txt']);+ });+it('keeps sealed history completed when a new active tail arrives before its user row', () => {const rows = [row(0, 'thinking', 'old'),{ ...row(1, 'assistant', 'Done'), agentMeta: { turnCompleted: true } },diff --git a/packages/maker-shared/src/historyView.ts b/packages/maker-shared/src/historyView.tsindex d122b78eec..8ee34a21ea 100644--- a/packages/maker-shared/src/historyView.ts+++ b/packages/maker-shared/src/historyView.ts@@ -1,7 +1,7 @@/** Reading projections never replace persisted messages or the agent transcript. */export const HISTORY_VIEW_VERSION = 1 as const;export const HISTORY_VIEW_PAGE_ITEMS = 20;-export const HISTORY_VIEW_PAGE_BYTES = 256 * 1024;+export const HISTORY_VIEW_PAGE_BYTES = 1024 * 1024;export const HISTORY_DETAIL_PAGE_BYTES = 256 * 1024;export function isHistoryViewUnavailable(error: unknown): boolean {diff --git a/packages/maker-shared/src/historyViewProjection.ts b/packages/maker-shared/src/historyViewProjection.tsindex 29a35fcbec..adf2af1d3e 100644--- a/packages/maker-shared/src/historyViewProjection.ts+++ b/packages/maker-shared/src/historyViewProjection.ts@@ -194,6 +194,12 @@ function projectHistorySourceView<T extends HistoryMessageSource>(revision: `${last.id}:${run.length}:${hash >>> 0}`,} };};+ // Consumers read artifacts from leaf summaries only (historyWorkSummaries), so+ // an outer copy would repeat every child's list once per nesting level.+ const nest = (result: GroupItem<T>, children: HistoryViewItem<T>[]): GroupItem<T> => {+ const { artifacts: _leafOnly, ...summary } = result.summary;+ return { ...result, summary, children };+ };const toViewItem = (item: Item): HistoryViewItem<T> => item.type === 'group'? { type: 'work', key: item.summary.key, summary: item.summary, ...(item.children ? { children: item.children } : {}) }: { type: 'messages', key: item.row.clientId || item.row.id, messages: [item.row] };@@ -213,8 +219,7 @@ function projectHistorySourceView<T extends HistoryMessageSource>(else segment.push(item);}flush();- result.children = children;- return result;+ return nest(result, children);}if (active) {const indexes = run.flatMap((item, index) => item.row.role === 'thinking' || item.row.role === 'tool_use' ? [index] : []);@@ -253,8 +258,7 @@ function projectHistorySourceView<T extends HistoryMessageSource>(else { flush(); children.push(toViewItem(item)); previous = timestamp(item); }}flush();- result.children = children;- return result;+ return nest(result, children);},});return grouped.map(toViewItem);