Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 卡顿诊断分别记录首页状态与消息预览订阅数
Dashae8e311cb1cc
diff --git a/apps/mobile/src/__tests__/remoteSessionStore.test.ts b/apps/mobile/src/__tests__/remoteSessionStore.test.tsindex 0e1b2051d7..7af8f876ad 100644--- a/apps/mobile/src/__tests__/remoteSessionStore.test.ts+++ b/apps/mobile/src/__tests__/remoteSessionStore.test.ts@@ -4,6 +4,7 @@ import { clampLiveRowCreatedAt } from '@/session/messagePaging';import { MOBILE_TOOL_INPUT_PROJECTION_THRESHOLD_BYTES } from '@/session/messageToolPayloadProjection';import { remoteSessionStore, resolveSessionWriteDevices, sessionPendingWrites } from '@/session/remoteSessionStore';import type { InputProjection, PendingInteraction, RemoteMessage, RemoteSession } from '@/session/types';+import { setJankMetricsEnabled, takeJankMetrics } from '@/debug/jankMetrics';function session(id: string, patch: Partial<RemoteSession> = {}): RemoteSession {return {@@ -6952,3 +6953,32 @@ describe('list message reuse', () => {expect(remoteSessionStore.getMessages('s1')).toEqual([]);});});++describe('jank metrics store size', () => {+ beforeEach(() => remoteSessionStore.clear());++ it('counts full-store, home status and per-task preview subscribers separately', () => {+ remoteSessionStore.setDeviceSessions('dev-1', 'Host', [session('s1'), session('s2')]);+ remoteSessionStore.setMessages('s1', [message('m1', 's1'), message('m2', 's1')]);+ const before = takeJankMetrics().store!;+ const unsubscribe = [+ remoteSessionStore.subscribe(() => undefined),+ remoteSessionStore.subscribeHomeStatus(() => undefined),+ remoteSessionStore.subscribeHomeStatus(() => undefined),+ remoteSessionStore.subscribeSessionMessagePreview('s1', () => undefined),+ remoteSessionStore.subscribeSessionMessagePreview('s2', () => undefined),+ remoteSessionStore.subscribeSessionMessagePreview('s2', () => undefined),+ ];+ setJankMetricsEnabled(true);+ try {+ const store = takeJankMetrics().store!;+ expect(store).toMatchObject({ sessionCount: 1, messageCount: 2, maxSessionMessageCount: 2 });+ expect(store.subscriberCount - before.subscriberCount).toBe(1);+ expect(store.homeStatusSubscriberCount - before.homeStatusSubscriberCount).toBe(2);+ expect(store.previewSubscriberCount - before.previewSubscriberCount).toBe(3);+ } finally {+ setJankMetricsEnabled(false);+ for (const off of unsubscribe) off();+ }+ });+});diff --git a/apps/mobile/src/debug/jankMetrics.test.ts b/apps/mobile/src/debug/jankMetrics.test.tsindex 4716404d8a..0357c33af9 100644--- a/apps/mobile/src/debug/jankMetrics.test.ts+++ b/apps/mobile/src/debug/jankMetrics.test.ts@@ -13,6 +13,8 @@ const store = {messageCount: 120,maxSessionMessageCount: 80,subscriberCount: 40,+ homeStatusSubscriberCount: 12,+ previewSubscriberCount: 30,};describe("jank metrics", () => {diff --git a/apps/mobile/src/debug/jankMetrics.ts b/apps/mobile/src/debug/jankMetrics.tsindex 55f7c1ebf7..df4c70e298 100644--- a/apps/mobile/src/debug/jankMetrics.ts+++ b/apps/mobile/src/debug/jankMetrics.ts@@ -18,7 +18,12 @@ export interface RemoteSessionStoreSizeMetrics {messageCount: number;/** Largest single in-memory window, the one every push to that task re-sorts. */maxSessionMessageCount: number;+ /** Full-store subscribers: every store change notifies each of them. */subscriberCount: number;+ /** Home rows' status channel, separate from the full store. */+ homeStatusSubscriberCount: number;+ /** Per-task message preview listeners, summed across tasks. */+ previewSubscriberCount: number;}interface ChannelTiming {diff --git a/apps/mobile/src/session/remoteSessionStore.ts b/apps/mobile/src/session/remoteSessionStore.tsindex e0b77f2a21..09ce049489 100644--- a/apps/mobile/src/session/remoteSessionStore.ts+++ b/apps/mobile/src/session/remoteSessionStore.ts@@ -714,6 +714,8 @@ const sessionListRefreshListeners = new Set<(deviceId: string) => void>();const sessionListRefreshArmed = new Set<string>();const sessionListRefreshSeen = new Set<string>();const subs = new Set<() => void>();+const homeStatusSubs = new Set<() => void>();+const sessionMessagePreviewSubs = new Map<string, Set<() => void>>();setRemoteSessionStoreSizeSource(() => {let total = 0;let max = 0;@@ -721,10 +723,17 @@ setRemoteSessionStoreSizeSource(() => {total += list.length;max = Math.max(max, list.length);}- return { sessionCount: messages.size, messageCount: total, maxSessionMessageCount: max, subscriberCount: subs.size };+ let previewSubscribers = 0;+ for (const listeners of sessionMessagePreviewSubs.values()) previewSubscribers += listeners.size;+ return {+ sessionCount: messages.size,+ messageCount: total,+ maxSessionMessageCount: max,+ subscriberCount: subs.size,+ homeStatusSubscriberCount: homeStatusSubs.size,+ previewSubscriberCount: previewSubscribers,+ };});-const homeStatusSubs = new Set<() => void>();-const sessionMessagePreviewSubs = new Map<string, Set<() => void>>();const pendingMessagePreviewSessionIds = new Set<string>();let homeStatusNotifyPending = false;let notifyAllMessagePreviewsPending = false;