Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (copilot): equalListByKeys non-array branch uses true reference identity

Adam Eivy2fad7bd9949e
diff --git a/client/src/lib/compareHelpers.js b/client/src/lib/compareHelpers.js
index 232995212d..329409504f 100644
--- a/client/src/lib/compareHelpers.js
+++ b/client/src/lib/compareHelpers.js
@@ -23,12 +23,12 @@ export const equalByKeys = (a, b, keys) =>
keys.every((key) => valueAt(a, key) === valueAt(b, key));
// True when `a` and `b` are arrays of equal length whose items are pairwise
-// equal on every key. Non-arrays fall back to identity (`a === b`), matching
-// the `Array.isArray(x) ? x : null` guard the inline callers used.
+// equal on every key. When either input is not an array, falls back to
+// reference identity (`a === b`) — so two distinct non-array values (e.g.
+// `{}` vs `{}`) read as changed and are never silently deduped; only `null`
+// vs `null` / the same reference vs itself read as equal.
export const equalListByKeys = (a, b, keys) => {
- const aArr = Array.isArray(a) ? a : null;
- const bArr = Array.isArray(b) ? b : null;
- if (aArr === null || bArr === null) return aArr === bArr;
- if (aArr.length !== bArr.length) return false;
- return aArr.every((item, i) => equalByKeys(item, bArr[i], keys));
+ if (!Array.isArray(a) || !Array.isArray(b)) return a === b;
+ if (a.length !== b.length) return false;
+ return a.every((item, i) => equalByKeys(item, b[i], keys));
};
diff --git a/client/src/lib/compareHelpers.test.js b/client/src/lib/compareHelpers.test.js
index 40f68203c7..0838dce50a 100644
--- a/client/src/lib/compareHelpers.test.js
+++ b/client/src/lib/compareHelpers.test.js
@@ -90,11 +90,18 @@ describe('equalListByKeys', () => {
)).toBe(false);
});
- it('falls back to identity for non-arrays', () => {
+ it('falls back to reference identity for non-arrays', () => {
expect(equalListByKeys(null, null, ['id'])).toBe(true);
expect(equalListByKeys(undefined, undefined, ['id'])).toBe(true);
expect(equalListByKeys(null, [{ id: 'a' }], ['id'])).toBe(false);
expect(equalListByKeys([{ id: 'a' }], null, ['id'])).toBe(false);
+ // distinct non-array objects are NOT structurally equal — identity only,
+ // so a real change can't be silently deduped away
+ expect(equalListByKeys({}, {}, ['id'])).toBe(false);
+ expect(equalListByKeys({ id: 'a' }, { id: 'a' }, ['id'])).toBe(false);
+ // the same reference compares equal
+ const shared = { id: 'a' };
+ expect(equalListByKeys(shared, shared, ['id'])).toBe(true);
});
it('treats two empty arrays as equal', () => {