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): 卡顿诊断字段不被日志脱敏抹掉

Dash8d704e1fa2a5
diff --git a/apps/mobile/src/__tests__/remoteSessionStore.test.ts b/apps/mobile/src/__tests__/remoteSessionStore.test.ts
index bbc9849f6f..0e1b2051d7 100644
--- a/apps/mobile/src/__tests__/remoteSessionStore.test.ts
+++ b/apps/mobile/src/__tests__/remoteSessionStore.test.ts
@@ -5744,6 +5744,25 @@ describe('任务消息内存治理', () => {
expect(rows.at(-1)?.id).toBe('s1-m-299');
});
+ it('后台单窗上限只裁可重取的行,保留本地系统卡', () => {
+ remoteSessionStore.setDeviceSessions('dev-1', 'Mac', [session('s1')]);
+ remoteSessionStore.setSessionRunning('s1', true);
+ const localCard = {
+ ...messageAt('mobile-system-local-only', 's1', '2025-12-31T23:59:59.000Z'),
+ role: 'system' as const,
+ };
+ remoteSessionStore.setMessages('s1', [localCard]);
+ for (const row of manyMessages('s1', 200)) {
+ remoteSessionStore.applyRemotePush('dev-1', 'local-db:messages:created', {
+ sessionId: 's1', listMessage: true, message: row,
+ });
+ }
+ const rows = remoteSessionStore.getMessages('s1');
+ expect(rows).toHaveLength(80);
+ expect(rows.some((row) => row.id === localCard.id)).toBe(true);
+ expect(rows.at(-1)?.id).toBe('s1-m-199');
+ });
+
it('正在看的 regular 任务不受后台单窗上限影响', () => {
remoteSessionStore.setDeviceSessions('dev-1', 'Mac', [session('s1')]);
remoteSessionStore.setSessionRunning('s1', true);
diff --git a/apps/mobile/src/debug/jankMetrics.test.ts b/apps/mobile/src/debug/jankMetrics.test.ts
index 8e208627e6..4716404d8a 100644
--- a/apps/mobile/src/debug/jankMetrics.test.ts
+++ b/apps/mobile/src/debug/jankMetrics.test.ts
@@ -6,6 +6,14 @@ import {
setRemoteSessionStoreSizeSource,
takeJankMetrics,
} from "./jankMetrics";
+import { serializeMobileDebugRecord } from "./mobileDebugRecord";
+
+const store = {
+ sessionCount: 2,
+ messageCount: 120,
+ maxSessionMessageCount: 80,
+ subscriberCount: 40,
+};
describe("jank metrics", () => {
afterEach(() => setJankMetricsEnabled(false));
@@ -16,41 +24,55 @@ describe("jank metrics", () => {
expect(takeJankMetrics()).toMatchObject({
pushCount: 0,
invokeCount: 0,
- pushes: {},
- invokes: {},
+ pushes: [],
+ invokes: [],
});
});
it("reports per-channel push time and request counts for one interval, then resets", () => {
setJankMetricsEnabled(true);
- setRemoteSessionStoreSizeSource(() => ({
- sessions: 2,
- messages: 120,
- maxSessionMessages: 80,
- storeSubscribers: 40,
- }));
+ setRemoteSessionStoreSizeSource(() => store);
+ recordPushHandled("maker:event", 1);
recordPushHandled("local-db:messages:created", 4);
recordPushHandled("local-db:messages:created", 10);
- recordPushHandled("maker:event", 1);
recordInvokeSent("git-context:pr-status");
recordInvokeSent("git-context:pr-status");
expect(takeJankMetrics()).toEqual({
- store: {
- sessions: 2,
- messages: 120,
- maxSessionMessages: 80,
- storeSubscribers: 40,
- },
+ store,
pushCount: 3,
pushMs: 15,
- pushes: {
- "local-db:messages:created": { count: 2, totalMs: 14, maxMs: 10 },
- "maker:event": { count: 1, totalMs: 1, maxMs: 1 },
- },
+ pushes: [
+ {
+ channel: "local-db:messages:created",
+ count: 2,
+ totalMs: 14,
+ maxMs: 10,
+ },
+ { channel: "maker:event", count: 1, totalMs: 1, maxMs: 1 },
+ ],
invokeCount: 2,
- invokes: { "git-context:pr-status": 2 },
+ invokes: [{ channel: "git-context:pr-status", count: 2 }],
});
expect(takeJankMetrics()).toMatchObject({ pushCount: 0, invokeCount: 0 });
});
+
+ it("keeps every number through the debug log redaction", () => {
+ setJankMetricsEnabled(true);
+ setRemoteSessionStoreSizeSource(() => store);
+ // Channel names that look sensitive must not take their counts with them.
+ recordPushHandled("auth:token-refreshed", 3);
+ recordInvokeSent("local-db:messages:view");
+ const line = serializeMobileDebugRecord("debug", "performance", [
+ "jank metrics",
+ takeJankMetrics(),
+ ]);
+
+ expect(line).not.toContain("[redacted]");
+ expect(JSON.parse(line).args[1]).toMatchObject({
+ store,
+ pushes: [{ count: 1, totalMs: 3 }],
+ invokes: [{ channel: "local-db:messages:view", count: 1 }],
+ });
+ });
});
diff --git a/apps/mobile/src/debug/jankMetrics.ts b/apps/mobile/src/debug/jankMetrics.ts
index 4330cee6cd..55f7c1ebf7 100644
--- a/apps/mobile/src/debug/jankMetrics.ts
+++ b/apps/mobile/src/debug/jankMetrics.ts
@@ -6,16 +6,19 @@
* retained size, and the diagnostic tick logs and resets them. Only fixed channel names and numbers
* are kept: no payloads, arguments, device ids or session ids.
*
+ * Field names must survive `serializeMobileDebugRecord`, which redacts keys such as `messages` and
+ * anything containing `token`; channel names are therefore values, never object keys.
+ *
* Disabled (the default) every record call is a single boolean check.
*/
export interface RemoteSessionStoreSizeMetrics {
/** Sessions holding an in-memory message window. */
- sessions: number;
- messages: number;
+ sessionCount: number;
+ messageCount: number;
/** Largest single in-memory window, the one every push to that task re-sorts. */
- maxSessionMessages: number;
- storeSubscribers: number;
+ maxSessionMessageCount: number;
+ subscriberCount: number;
}
interface ChannelTiming {
@@ -24,6 +27,9 @@ interface ChannelTiming {
maxMs: number;
}
+type ChannelTimingRow = { channel: string } & ChannelTiming;
+type ChannelCountRow = { channel: string; count: number };
+
const TOP_CHANNELS = 6;
let enabled = false;
@@ -63,15 +69,13 @@ export function setRemoteSessionStoreSizeSource(
storeSizeSource = source;
}
-function topChannels<T>(
- map: Map<string, T>,
- weight: (value: T) => number,
-): Record<string, T> {
- return Object.fromEntries(
- [...map]
- .sort((left, right) => weight(right[1]) - weight(left[1]))
- .slice(0, TOP_CHANNELS),
- );
+function topChannels<T extends { channel: string }>(
+ rows: T[],
+ weight: (row: T) => number,
+): T[] {
+ return rows
+ .sort((left, right) => weight(right) - weight(left))
+ .slice(0, TOP_CHANNELS);
}
/** Read and reset the interval counters. */
@@ -79,27 +83,36 @@ export function takeJankMetrics(): {
store: RemoteSessionStoreSizeMetrics | null;
pushCount: number;
pushMs: number;
- pushes: Record<string, ChannelTiming>;
+ pushes: ChannelTimingRow[];
invokeCount: number;
- invokes: Record<string, number>;
+ invokes: ChannelCountRow[];
} {
let pushCount = 0;
let pushMs = 0;
- for (const entry of pushes.values()) {
+ const pushRows: ChannelTimingRow[] = [];
+ for (const [channel, entry] of pushes) {
pushCount += entry.count;
pushMs += entry.totalMs;
- entry.totalMs = Math.round(entry.totalMs);
- entry.maxMs = Math.round(entry.maxMs);
+ pushRows.push({
+ channel,
+ count: entry.count,
+ totalMs: Math.round(entry.totalMs),
+ maxMs: Math.round(entry.maxMs),
+ });
}
let invokeCount = 0;
- for (const count of invokes.values()) invokeCount += count;
+ const invokeRows: ChannelCountRow[] = [];
+ for (const [channel, count] of invokes) {
+ invokeCount += count;
+ invokeRows.push({ channel, count });
+ }
const snapshot = {
store: storeSizeSource?.() ?? null,
pushCount,
pushMs: Math.round(pushMs),
- pushes: topChannels(pushes, (entry) => entry.totalMs),
+ pushes: topChannels(pushRows, (row) => row.totalMs),
invokeCount,
- invokes: topChannels(invokes, (count) => count),
+ invokes: topChannels(invokeRows, (row) => row.count),
};
pushes = new Map();
invokes = new Map();
diff --git a/apps/mobile/src/session/remoteSessionStore.ts b/apps/mobile/src/session/remoteSessionStore.ts
index 37f8f05ca5..e0b77f2a21 100644
--- a/apps/mobile/src/session/remoteSessionStore.ts
+++ b/apps/mobile/src/session/remoteSessionStore.ts
@@ -721,7 +721,7 @@ setRemoteSessionStoreSizeSource(() => {
total += list.length;
max = Math.max(max, list.length);
}
- return { sessions: messages.size, messages: total, maxSessionMessages: max, storeSubscribers: subs.size };
+ return { sessionCount: messages.size, messageCount: total, maxSessionMessageCount: max, subscriberCount: subs.size };
});
const homeStatusSubs = new Set<() => void>();
const sessionMessagePreviewSubs = new Map<string, Set<() => void>>();