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: address review — preserve curated channel, keep name-only msg identities, full-cache scan (#2033)

Adam Eivyc09aa0187ac9
diff --git a/server/services/messageSync.js b/server/services/messageSync.js
index 2833788f64..4c09e87e94 100644
--- a/server/services/messageSync.js
+++ b/server/services/messageSync.js
@@ -185,9 +185,13 @@ export async function syncAccount(accountId, io, options = {}) {
await saveCache(accountId, cache);
await updateSyncStatus(accountId, providerStatus === 'success' ? 'success' : providerStatus);
- // Auto-log Tribe touchpoints from newly synced messages (#2033) — secondary
- // effect, must not fail the sync; deduped per thread + day so re-syncs are safe.
- await logMessageTouchpoints(account, uniqueNew).catch((err) =>
+ // Auto-log Tribe touchpoints from the cached messages (#2033) — secondary
+ // effect, must not fail the sync. Scans the full (maxMessages-capped) cache
+ // rather than only the newly-added batch, mirroring the calendar path: so
+ // adding a person's email AFTER their messages synced still backfills, and a
+ // prior auto-log failure self-heals on the next sync. Deduped per thread+day
+ // (partial unique index), so re-scanning already-logged messages is a no-op.
+ await logMessageTouchpoints(account, cache.messages).catch((err) =>
console.error(`🤝 Tribe auto-log failed for account ${accountId}: ${err.message}`));
io?.emit('messages:sync:completed', { accountId, newMessages: uniqueNew.length, pruned, status: providerStatus });
@@ -349,8 +353,14 @@ export async function logMessageTouchpoints(account, messages = []) {
const participants = [message.from, ...(message.to || []), ...(message.cc || [])];
const identities = participants
.map(toIdentity)
- .filter((identity) => identity && identity.email
- && identity.email.trim().toLowerCase() !== selfEmail);
+ .filter((identity) => {
+ if (!identity) return false;
+ const email = (identity.email || '').trim().toLowerCase();
+ if (email && email === selfEmail) return false; // exclude the account owner
+ // Keep name-only participants too so the matcher's unique-name fallback
+ // still applies (mirrors the calendar path, which passes every identity).
+ return Boolean(email || identity.name);
+ });
if (identities.length === 0) continue;
const when = message.date || new Date().toISOString();
const day = new Date(safeDate(when)).toISOString().slice(0, 10);
diff --git a/server/services/messageSync.test.js b/server/services/messageSync.test.js
index 8e18e0b8f8..27b8a6cbcb 100644
--- a/server/services/messageSync.test.js
+++ b/server/services/messageSync.test.js
@@ -615,6 +615,15 @@ describe('logMessageTouchpoints — candidate building (#2033)', () => {
expect(candidates[0].dedupeKey).toBe(`msg:${VALID_UUID}:m2:2026-06-02`);
});
+ it('keeps a name-only participant so the matcher unique-name fallback applies', async () => {
+ await logMessageTouchpoints(account, [{
+ id: 'm4', subject: 'Hi', date: '2026-06-01T00:00:00Z',
+ from: { name: 'Ada Lovelace', email: '' }, to: [], cc: [],
+ }]);
+ const [candidates] = autoLogTouchpoints.mock.calls[0];
+ expect(candidates[0].identities).toEqual([{ email: '', name: 'Ada Lovelace' }]);
+ });
+
it('skips a message with no counterpart beyond the account owner', async () => {
await logMessageTouchpoints(account, [{
id: 'm3', date: '2026-06-01T00:00:00Z',
diff --git a/server/services/tribe.js b/server/services/tribe.js
index 73f2c51bac..b19859edb3 100644
--- a/server/services/tribe.js
+++ b/server/services/tribe.js
@@ -404,13 +404,17 @@ async function autoCreateTouchpoint(personId, data) {
);
if (!result.rows[0]) return null; // duplicate — already logged for this key
+ // Advance last_contact_on only. Unlike a manual touchpoint, an auto-log must
+ // NOT overwrite the person's curated `channel` (their preferred way to
+ // connect): it fires silently on every sync and would otherwise churn the
+ // preference to the last meeting location / account type. The synced
+ // channel is still preserved on the touchpoint row itself.
await client.query(
`UPDATE tribe_people
SET last_contact_on = GREATEST(COALESCE(last_contact_on, DATE '1900-01-01'), $2::date),
- channel = CASE WHEN $3::text = '' THEN channel ELSE $3::text END,
updated_at = NOW()
WHERE id = $1`,
- [personId, happenedAt, data.channel || ''],
+ [personId, happenedAt],
);
return rowToTouchpoint(result.rows[0]);
});