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

fix: retain browser identity across legacy timestamp and sync formats (#8784)

[._.]/ Adam Eivy289118bcdc51
diff --git a/server/lib/messageBrowserIdentity.js b/server/lib/messageBrowserIdentity.js
index 73b2a2d284..69a98cc3a4 100644
--- a/server/lib/messageBrowserIdentity.js
+++ b/server/lib/messageBrowserIdentity.js
@@ -83,13 +83,23 @@ async function actOnMessageRow(provider, identity, action, readOutlookRow) {
date: dated?.getAttribute('title') || ''
};
}
+ function sameTimestamp(actual, expected) {
+ if (actual === expected) return true;
+ // Normalize only complete, timezone-qualified timestamps. Relative dates,
+ // date-only labels and timezone-less wall clocks are not exact identities.
+ const complete = value => typeof value === 'string' && /\d{4}/.test(value)
+ && /\d{1,2}:\d{2}/.test(value) && /(?:Z|[+-]\d{2}:?\d{2}|GMT|UTC)(?:\s|$)/i.test(value);
+ if (!complete(actual) || !complete(expected)) return false;
+ const actualTime = Date.parse(actual);
+ return Number.isFinite(actualTime) && actualTime === Date.parse(expected);
+ }
function matches(row) {
const actual = read(row);
if (identity.providerRowId) return actual.providerRowId === identity.providerRowId;
// Legacy records must supply every identity dimension. Do not normalize
// case, truncate subjects, or guess missing dates/senders.
if (!identity.subject?.trim() || !identity.date || !(identity.from?.email || identity.from?.name)) return false;
- return actual.subject === identity.subject && actual.date === identity.date
+ return actual.subject === identity.subject && sameTimestamp(actual.date, identity.date)
&& (!identity.from.email || actual.fromEmail === identity.from.email)
&& (!identity.from.name || actual.from === identity.from.name);
}
diff --git a/server/services/messageActions.test.js b/server/services/messageActions.test.js
index 5d2f458b75..9edbe49e2f 100644
--- a/server/services/messageActions.test.js
+++ b/server/services/messageActions.test.js
@@ -59,6 +59,12 @@ for (const provider of ['gmail', 'outlook']) describe(`${provider} browser ident
await executeAction(accountId, message.id, 'archive');
expect(clicked).toEqual([{ index: 2, label: 'Archive' }]);
});
+ it('matches a cached ISO timestamp to an equivalent complete provider timestamp', async () => {
+ mocks.message.mockResolvedValue({ ...message, date: '2026-09-26T10:30:00.000Z' });
+ const clicked = mailbox([{ ...message, date: 'Sat, 26 Sep 2026 10:30:00 GMT' }]);
+ await executeAction(accountId, message.id, 'archive');
+ expect(clicked).toEqual([{ index: 0, label: 'Archive' }]);
+ });
it.each(['duplicate', 'blank', 'missing-date', 'missing-sender', 'missing-id', 'virtualized'])('rejects %s identity without action or cache writes', async scenario => {
const target = { ...message };
if (scenario === 'blank') target.subject = '';
diff --git a/server/services/messageSync.js b/server/services/messageSync.js
index 3115d78fdf..aebb32ac10 100644
--- a/server/services/messageSync.js
+++ b/server/services/messageSync.js
@@ -222,15 +222,23 @@ export async function syncAccount(accountId, io, options = {}) {
// Deduplicate by externalId; update flags and body on existing messages
const existingMap = new Map(cache.messages.filter(m => m.externalId).map(m => [m.providerRowId ? `${m.externalId}|${m.providerRowId}` : m.externalId, m]));
+ const uniqueByExternalId = new Map();
+ for (const message of cache.messages) {
+ uniqueByExternalId.set(message.externalId, uniqueByExternalId.has(message.externalId) ? null : message);
+ }
+ const incomingCounts = new Map();
+ for (const message of newMessages) {
+ incomingCounts.set(message.externalId, (incomingCounts.get(message.externalId) || 0) + 1);
+ }
const uniqueNew = [];
for (const msg of newMessages) {
const identityKey = msg.providerRowId ? `${msg.externalId}|${msg.providerRowId}` : msg.externalId;
- // Upgrade a legacy identity only when both sides are unique. Duplicate
- // summaries must never move an existing local ID to a different row.
- const legacy = msg.providerRowId && existingMap.get(msg.externalId);
- const canUpgrade = legacy && cache.messages.filter(m => m.externalId === msg.externalId).length === 1
- && newMessages.filter(m => m.externalId === msg.externalId).length === 1;
- const existing = existingMap.get(identityKey) || (canUpgrade ? legacy : null);
+ // A missing row ID on either side permits a summary fallback only
+ // when both sides are unique; never overwrite a different known row ID.
+ const fallback = uniqueByExternalId.get(msg.externalId);
+ const canMatchSummary = fallback && incomingCounts.get(msg.externalId) === 1
+ && (!msg.providerRowId || !fallback.providerRowId);
+ const existing = existingMap.get(identityKey) || (canMatchSummary ? fallback : null);
if (!msg.externalId || !existing) {
uniqueNew.push(msg);
} else {
diff --git a/server/services/messageSync.test.js b/server/services/messageSync.test.js
index fecce30245..e23b023ec0 100644
--- a/server/services/messageSync.test.js
+++ b/server/services/messageSync.test.js
@@ -574,6 +574,14 @@ describe('syncAccount', () => {
]);
});
+ it('retains a known row ID when a later unambiguous extraction omits it', async () => {
+ getAccount.mockResolvedValue({ id: VALID_UUID, type: 'outlook', enabled: true });
+ readFile.mockResolvedValue(JSON.stringify({ messages: [{ id: 'local', externalId: 'summary', providerRowId: 'stable-row' }] }));
+ syncPlaywright.mockResolvedValue({ status: 'success', messages: [{ id: 'new-local', externalId: 'summary', providerRowId: null, isRead: true }] });
+ await syncAccount(VALID_UUID, mockIo);
+ expect(atomicWrite.mock.calls[0][1].messages).toEqual([expect.objectContaining({ id: 'local', providerRowId: 'stable-row', isRead: true })]);
+ });
+
it('upgrades a unique legacy cache entry with its ingested provider row ID', async () => {
getAccount.mockResolvedValue({ id: VALID_UUID, type: 'outlook', enabled: true });
readFile.mockResolvedValue(JSON.stringify({ messages: [{ id: 'legacy-local', externalId: 'summary' }] }));