Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(contacts): dedupe orders only real date text, so a numeric last_* field never merges away a distinct value (#8109)

garrytan4bd7d74e847d
diff --git a/src/core/contact-rows.ts b/src/core/contact-rows.ts
index 227d4d4fe8..064a8670f8 100644
--- a/src/core/contact-rows.ts
+++ b/src/core/contact-rows.ts
@@ -26,8 +26,9 @@ const keyOf = (row: unknown): string | null => {
const type = row.type.trim().toLowerCase(), value = String(row.value).trim();
return type && value ? JSON.stringify([type, value]) : null;
};
+const DATE_TEXT = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2}))?$/;
const instant = (value: unknown): number => {
- const text = value instanceof Date ? value.toISOString() : typeof value === 'string' ? value : null;
+ const text = value instanceof Date ? value.toISOString() : typeof value === 'string' && DATE_TEXT.test(value) ? value : null;
return text === null ? NaN : Date.parse(text);
};
diff --git a/test/contact-rows.test.ts b/test/contact-rows.test.ts
index 5de1556bfb..7736facaae 100644
--- a/test/contact-rows.test.ts
+++ b/test/contact-rows.test.ts
@@ -33,6 +33,8 @@ describe('#8109 dedupeContactRows', () => {
expect(dedupeContactRows(list)).toEqual({ rows: list.slice(0, 2), removed: 1, kept_conflicting: 1 });
// An activity date that is not a date cannot be ordered: the rows are kept apart, exact copies still go.
expect(dedupeContactRows([phone('+15550100', 'yesterday'), phone('+15550100', '2026-10-01'), phone('+15550100', 'yesterday')])!.rows).toHaveLength(2);
+ // A last_* field holding a number is not a date, even though Date.parse reads '0100' and '2' as years.
+ expect(dedupeContactRows([phone('+15550100', '2026-10-01', { last_digits: '0100' }), phone('+15550100', '2026-10-01', { last_digits: '2' })])).toBeNull();
});
test('non-row entries, rows without a type or value, and lists with nothing to merge are left alone', () => {