Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(contacts): preserve large sync snapshot differences
Chris0b9c253312fc
diff --git a/packages/maker-core/src/contacts/__tests__/contactsSync.test.ts b/packages/maker-core/src/contacts/__tests__/contactsSync.test.tsindex 95f8de7798..d7cda684a6 100644--- a/packages/maker-core/src/contacts/__tests__/contactsSync.test.ts+++ b/packages/maker-core/src/contacts/__tests__/contactsSync.test.ts@@ -199,6 +199,18 @@ describe("contacts device sync", () => {expect(() => stableContactsSyncJson(contactRecord.status)).not.toThrow();});+ it("规范化不会把旧预算之后的合法快照差异折叠成相等", () => {+ const baseline = {+ rows: Array.from({ length: 100_001 }, (_, index) => index),+ };+ const changed = structuredClone(baseline);+ changed.rows[100_000] = -1;++ expect(stableContactsSyncJson(baseline)).not.toBe(+ stableContactsSyncJson(changed),+ );+ });+it("确认成员元数据使用同步层上限,不收紧多设备合并后的合法身份数", () => {const store = createStore();store.activateDeviceSync();diff --git a/packages/maker-core/src/contacts/sync/merge.ts b/packages/maker-core/src/contacts/sync/merge.tsindex 17b7a801ae..ae132dce23 100644--- a/packages/maker-core/src/contacts/sync/merge.ts+++ b/packages/maker-core/src/contacts/sync/merge.ts@@ -21,16 +21,14 @@ export function compareContactsSyncText(a: string, b: string): number {return a < b ? -1 : a > b ? 1 : 0;}-const MAX_STABLE_JSON_NODES = 100_000;-/*** JSON-compatible serialization with sorted object keys.** This is deliberately iterative: stamped values may carry unknown extension* fields from a newer client, and a deeply nested extension must not overflow- * the codec worker's call stack. The node budget keeps malformed cyclic or- * unexpectedly broad values bounded while preserving deterministic ordering for- * normal JSON-shaped sync data.+ * the codec worker's call stack. Valid sync rows are already bounded by the+ * state validator; cyclic references are handled explicitly so malformed+ * in-memory values cannot loop forever.*/export function stableContactsSyncJson(value: unknown): string {type Frame =@@ -40,7 +38,6 @@ export function stableContactsSyncJson(value: unknown): string {const output: string[] = [];const stack: Frame[] = [{ kind: "value", value }];const seen = new WeakSet<object>();- let nodes = 0;while (stack.length > 0) {const frame = stack.pop()!;@@ -49,12 +46,6 @@ export function stableContactsSyncJson(value: unknown): string {continue;}- nodes += 1;- if (nodes > MAX_STABLE_JSON_NODES) {- output.push('"[truncated]"');- continue;- }-const current = frame.value;if (current === null || typeof current !== "object") {output.push(JSON.stringify(current) ?? "null");@@ -76,14 +67,15 @@ export function stableContactsSyncJson(value: unknown): string {continue;}- const keys = Object.keys(current)- .filter((key) => current[key] !== undefined)+ const record = current as Record<string, unknown>;+ const keys = Object.keys(record)+ .filter((key) => record[key] !== undefined).sort(compareContactsSyncText);output.push("{");stack.push({ kind: "text", text: "}" });for (let index = keys.length - 1; index >= 0; index -= 1) {const key = keys[index]!;- stack.push({ kind: "value", value: current[key] });+ stack.push({ kind: "value", value: record[key] });stack.push({ kind: "text", text: `:${JSON.stringify(key)}` });if (index > 0) stack.push({ kind: "text", text: "," });}