Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): 修复长列表缓存与滑动操作回归

DavidShenb123cea1d23c
diff --git a/apps/mobile/src/__tests__/messagePaging.test.ts b/apps/mobile/src/__tests__/messagePaging.test.ts
index e8fc4b3653..18c3ed581f 100644
--- a/apps/mobile/src/__tests__/messagePaging.test.ts
+++ b/apps/mobile/src/__tests__/messagePaging.test.ts
@@ -172,6 +172,18 @@ describe('messagePaging', () => {
const rows = [compact('only', '2026-01-01T00:00:01.000Z')];
expect(projectLoadedMessageWindow(rows)).toBe(rows);
});
+
+ it('collapses an adjacent Compact-only wall when no host cursor is loaded', () => {
+ const rows = [
+ compact('first', '2026-01-01T00:00:01.000Z'),
+ compact('second', '2026-01-01T00:00:02.000Z'),
+ compact('latest', '2026-01-01T00:00:03.000Z'),
+ ];
+
+ expect(projectLoadedMessageWindow(rows).map((row) => row.id)).toEqual([
+ 'mobile-system-compact:latest',
+ ]);
+ });
});
it('keeps the load-earlier affordance only when the remote page is full', () => {
diff --git a/apps/mobile/src/__tests__/messagePerformance.test.ts b/apps/mobile/src/__tests__/messagePerformance.test.ts
index a223659efc..92b69f2fe9 100644
--- a/apps/mobile/src/__tests__/messagePerformance.test.ts
+++ b/apps/mobile/src/__tests__/messagePerformance.test.ts
@@ -205,6 +205,110 @@ describe('message render performance', () => {
expect(next.items.slice(0, first.prefix!.items.length)).toEqual(first.prefix!.items);
});
+ it('invalidates a historical prefix only when one of its task updates changes', () => {
+ const prefixTask = message({
+ id: 'historical-prefix-task',
+ role: 'tool_use',
+ toolUseId: 'historical-prefix-task',
+ content: {
+ toolUseId: 'historical-prefix-task',
+ toolName: 'collab:spawn',
+ input: { task: 'Review the historical prefix' },
+ },
+ createdAt: timestamp(1),
+ });
+ const stableAssistant = message({
+ id: 'historical-prefix-assistant',
+ role: 'assistant',
+ content: 'The review has started.',
+ createdAt: timestamp(2),
+ });
+ const activeUser = message({
+ id: 'historical-prefix-active-user',
+ role: 'user',
+ content: 'Continue',
+ createdAt: timestamp(3),
+ });
+ const activeAssistant = message({
+ id: 'historical-prefix-active-assistant',
+ role: 'assistant',
+ content: 'Partial',
+ agentMeta: { isStreaming: true },
+ createdAt: timestamp(4),
+ });
+ const prefixUpdate: AgentTaskUpdate = {
+ provider: 'codex',
+ taskId: 'historical-prefix-task',
+ status: 'running',
+ };
+ const prefixCache: {
+ current: ReturnType<typeof buildMobileStreamingRenderWindow>['prefix'];
+ } = { current: null };
+ const options = {
+ isSessionStreaming: true,
+ renderOrphanTaskUpdates: true,
+ sessionId: 's1',
+ } as const;
+ const messages = [prefixTask, stableAssistant, activeUser, activeAssistant];
+ const firstUpdates = new Map<string, AgentTaskUpdate>([
+ ['historical-prefix-task', prefixUpdate],
+ ]);
+ const first = buildMobileStreamingRenderWindow({
+ cacheKey: 'en',
+ messages,
+ options,
+ prefixCache,
+ taskUpdates: firstUpdates,
+ });
+
+ expect(first.prefix?.mode).toBe('history');
+ expect(first.items.filter((item) => item.type === 'agent_task')).toMatchObject([
+ { key: 'task-historical-prefix-task', update: prefixUpdate },
+ ]);
+
+ const unrelatedUpdate: AgentTaskUpdate = {
+ provider: 'codex',
+ taskId: 'active-orphan-task',
+ status: 'running',
+ };
+ const unrelatedUpdates = new Map<string, AgentTaskUpdate>([
+ ['historical-prefix-task', prefixUpdate],
+ ['active-orphan-task', unrelatedUpdate],
+ ]);
+ const unrelated = buildMobileStreamingRenderWindow({
+ cacheKey: 'en',
+ messages,
+ options,
+ prefixCache,
+ taskUpdates: unrelatedUpdates,
+ });
+
+ expect(unrelated.prefix).toBe(first.prefix);
+ expect(unrelated.items.filter((item) => item.type === 'agent_task')).toMatchObject([
+ { key: 'task-historical-prefix-task', update: prefixUpdate },
+ { key: 'task-update-active-orphan-task', update: unrelatedUpdate },
+ ]);
+
+ const changedPrefixUpdate = { ...prefixUpdate, title: 'Updated historical task' };
+ const changedUpdates = new Map<string, AgentTaskUpdate>([
+ ['historical-prefix-task', changedPrefixUpdate],
+ ['active-orphan-task', unrelatedUpdate],
+ ]);
+ const changed = buildMobileStreamingRenderWindow({
+ cacheKey: 'en',
+ messages,
+ options,
+ prefixCache,
+ taskUpdates: changedUpdates,
+ });
+
+ expect(changed.prefix).not.toBe(first.prefix);
+ expect(changed.items.filter((item) => item.type === 'agent_task')).toMatchObject([
+ { key: 'task-historical-prefix-task', update: changedPrefixUpdate },
+ { key: 'task-update-active-orphan-task', update: unrelatedUpdate },
+ ]);
+ });
+
it('publishes a reusable prefix before a streaming render commits', () => {
const history = createLargeDesktopMessageFixture(20);
const activeUser = message({
diff --git a/apps/mobile/src/__tests__/swipeableSessionRowLifecycle.test.ts b/apps/mobile/src/__tests__/swipeableSessionRowLifecycle.test.ts
index 6a5fe6db24..b77ded1528 100644
--- a/apps/mobile/src/__tests__/swipeableSessionRowLifecycle.test.ts
+++ b/apps/mobile/src/__tests__/swipeableSessionRowLifecycle.test.ts
@@ -31,4 +31,9 @@ describe('SwipeableSessionRow native animation lifecycle', () => {
expect(source).toContain('<View style={styles.pinShell}>');
expect(source).toContain('<View style={styles.rightShell}>');
});
+
+ it('keeps the two right-side action buttons evenly spaced', () => {
+ expect(source).toMatch(/optionsButton:\s*\{[\s\S]*?right: BUTTON_GAP \* 2 \+ BUTTON_SIZE,/);
+ expect(source).toMatch(/archiveButton:\s*\{[\s\S]*?right: BUTTON_GAP,/);
+ });
});
diff --git a/apps/mobile/src/session/SwipeableSessionRow.tsx b/apps/mobile/src/session/SwipeableSessionRow.tsx
index 7fcf80dd7d..a4bed0f19e 100644
--- a/apps/mobile/src/session/SwipeableSessionRow.tsx
+++ b/apps/mobile/src/session/SwipeableSessionRow.tsx
@@ -541,6 +541,7 @@ const makeStyles = (colors: ThemeColors) => StyleSheet.create({
marginTop: -BUTTON_SIZE / 2,
overflow: 'hidden',
position: 'absolute',
+ right: BUTTON_GAP * 2 + BUTTON_SIZE,
top: '50%',
width: BUTTON_SIZE,
},
diff --git a/apps/mobile/src/session/messagePaging.ts b/apps/mobile/src/session/messagePaging.ts
index 2bf4c254a7..868febc146 100644
--- a/apps/mobile/src/session/messagePaging.ts
+++ b/apps/mobile/src/session/messagePaging.ts
@@ -46,7 +46,20 @@ export function projectLoadedMessageWindow(
if (firstHostIndex < 0) firstHostIndex = index;
lastHostIndex = index;
}
- if (firstHostIndex < 0) return messages;
+ if (firstHostIndex < 0) {
+ let changed = false;
+ const projected: RemoteMessage[] = [];
+ for (const message of messages) {
+ const previous = projected.at(-1);
+ if (isLocalCompactCard(message) && previous && isLocalCompactCard(previous)) {
+ projected[projected.length - 1] = message;
+ changed = true;
+ continue;
+ }
+ projected.push(message);
+ }
+ return changed ? projected : messages;
+ }
let latestDetachedTailCompactIndex = -1;
for (let index = lastHostIndex + 1; index < messages.length; index += 1) {
diff --git a/apps/mobile/src/session/messageRenderStreamingCache.ts b/apps/mobile/src/session/messageRenderStreamingCache.ts
index 655e3f0a87..0d1fda786f 100644
--- a/apps/mobile/src/session/messageRenderStreamingCache.ts
+++ b/apps/mobile/src/session/messageRenderStreamingCache.ts
@@ -124,10 +124,14 @@ export function buildMobileStreamingRenderWindow(
const canReusePrefix = previousPrefix?.mode === 'history'
&& previousPrefix.sessionId === sessionId
&& previousPrefix.cacheKey === cacheKey
+ && sameTaskUpdateDependencies(previousPrefix.taskUpdateDependencies, taskUpdates)
&& sameMessagePrefixReferences(previousPrefix.messages, messages, activeTurnStart);
const prefixMessages = canReusePrefix
? previousPrefix.messages
: messages.slice(0, activeTurnStart);
+ const prefixTaskUpdateDependencies = canReusePrefix
+ ? previousPrefix.taskUpdateDependencies ?? []
+ : collectTaskUpdateDependencies(prefixMessages, taskUpdates);
const prefixItems = canReusePrefix
? previousPrefix.items
: buildMobileMessageRenderItems(prefixMessages, {
@@ -135,14 +139,21 @@ export function buildMobileStreamingRenderWindow(
autoResumePending: null,
isSessionStreaming: false,
renderOrphanTaskUpdates: false,
- });
+ }, taskUpdates);
const prefix = canReusePrefix
? previousPrefix
- : { cacheKey, items: prefixItems, messages: prefixMessages, mode: 'history' as const, sessionId };
+ : {
+ cacheKey,
+ items: prefixItems,
+ messages: prefixMessages,
+ mode: 'history' as const,
+ sessionId,
+ taskUpdateDependencies: prefixTaskUpdateDependencies,
+ };
const activeItems = buildMobileMessageRenderItems(
messages.slice(activeTurnStart),
options,
- taskUpdates,
+ omitTaskUpdatesConsumedByPrefix(taskUpdates, prefixTaskUpdateDependencies),
);
const result = {
items: [...prefixItems, ...activeItems],
@@ -312,6 +323,22 @@ function sameTaskUpdateDependencySnapshots(
});
}
+function omitTaskUpdatesConsumedByPrefix(
+ taskUpdates: ReadonlyMap<string, AgentTaskUpdate> | undefined,
+ dependencies: readonly MobileStreamingTaskUpdateDependency[],
+): ReadonlyMap<string, AgentTaskUpdate> | undefined {
+ if (!taskUpdates || taskUpdates.size === 0) return taskUpdates;
+ const consumedUpdates = new Set(
+ dependencies
+ .map((dependency) => dependency.update)
+ .filter((update): update is AgentTaskUpdate => update !== undefined),
+ );
+ if (consumedUpdates.size === 0) return taskUpdates;
+ return new Map(
+ [...taskUpdates].filter(([, update]) => !consumedUpdates.has(update)),
+ );
+}
+
function findLastStableAssistantBoundaryIndex(messages: readonly RemoteMessage[]): number {
for (let index = messages.length - 2; index > 0; index -= 1) {
const message = messages[index];