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 (codex): exclude iMessage reactions; distinguish STALE_INBOUND from ALREADY_REPLIED

[._.]/ Adam Eivy51e726887cfd
diff --git a/client/src/pages/Tribe.jsx b/client/src/pages/Tribe.jsx
index a4537b9409..57256bd3c5 100644
--- a/client/src/pages/Tribe.jsx
+++ b/client/src/pages/Tribe.jsx
@@ -628,11 +628,18 @@ function OutreachQueue() {
lastInboundAt: thread.lastInboundAt,
};
const result = await api.generateTribeOutreachDraft(seed, { silent: true }).catch((err) => {
- // The thread may have been answered since the list loaded (409) — drop it
- // rather than leave a stale nudge the user can re-click.
- if (err?.status === 409 || err?.code === 'ALREADY_REPLIED') {
+ // The Care Queue loaded once, so the thread may have moved on (409):
+ // - ALREADY_REPLIED: you answered it → drop the now-resolved nudge.
+ // - STALE_INBOUND: they sent a newer message → it's STILL unanswered, so
+ // refetch to pick up the latest turn rather than falsely dropping it.
+ if (err?.code === 'ALREADY_REPLIED') {
setThreads((prev) => (prev || []).filter((t) => t.conversationKey !== key));
toast.success(`Looks like you already replied to ${thread.personName}`);
+ } else if (err?.code === 'STALE_INBOUND') {
+ api.getTribeOutreach({ silent: true })
+ .then((r) => setThreads(r?.threads || []))
+ .catch(() => {});
+ toast(`${thread.personName} sent a newer message — refreshed`);
} else {
toast.error(err.message || 'Could not generate a draft');
}
diff --git a/server/services/imessageSync.js b/server/services/imessageSync.js
index 997ea17863..254afc4835 100644
--- a/server/services/imessageSync.js
+++ b/server/services/imessageSync.js
@@ -162,6 +162,10 @@ export function imessageActivityCandidate(msg) {
service: msg.service || null,
handle: counterpart || null,
rowid: msg.rowid ?? null,
+ // Tag Tapbacks/reactions so downstream consumers (Tribe outreach #2158) can
+ // exclude them — a reaction is not a message awaiting a reply. Only set when
+ // true to keep ordinary-message metadata unchanged.
+ ...(Number(msg.associatedType) ? { isReaction: true } : {}),
},
};
}
@@ -333,7 +337,7 @@ function readMessages(db, cursorRowid, limit) {
// string; appleDateToDate parses it (second-scale precision is all we need).
const rows = db.prepare(
`SELECT m.ROWID AS rowid, m.guid, CAST(m.date AS TEXT) AS date, m.text, m.attributedBody,
- m.is_from_me AS is_from_me, m.service,
+ m.is_from_me AS is_from_me, m.service, m.associated_message_type AS assoc_type,
h.id AS handle,
c.guid AS chat_guid, c.display_name AS chat_name, c.chat_identifier
FROM message m
@@ -369,6 +373,9 @@ function readMessages(db, cursorRowid, limit) {
chatGuid,
chatName: row.chat_name || row.chat_identifier || '',
service: row.service || null,
+ // Non-zero `associated_message_type` = a Tapback/reaction/edit attached to
+ // another message, not a standalone message (2000-3005 reactions, etc.).
+ associatedType: Number(row.assoc_type) || 0,
participants,
});
}
diff --git a/server/services/imessageSync.runSync.test.js b/server/services/imessageSync.runSync.test.js
index f1d6fedd15..35db1bed55 100644
--- a/server/services/imessageSync.runSync.test.js
+++ b/server/services/imessageSync.runSync.test.js
@@ -65,7 +65,7 @@ beforeAll(() => {
CREATE TABLE handle (ROWID INTEGER PRIMARY KEY, id TEXT);
CREATE TABLE chat (ROWID INTEGER PRIMARY KEY, guid TEXT, chat_identifier TEXT, display_name TEXT);
CREATE TABLE chat_handle_join (chat_id INTEGER, handle_id INTEGER);
- CREATE TABLE message (ROWID INTEGER PRIMARY KEY, guid TEXT, date INTEGER, text TEXT, attributedBody BLOB, is_from_me INTEGER, service TEXT, handle_id INTEGER);
+ CREATE TABLE message (ROWID INTEGER PRIMARY KEY, guid TEXT, date INTEGER, text TEXT, attributedBody BLOB, is_from_me INTEGER, service TEXT, handle_id INTEGER, associated_message_type INTEGER DEFAULT 0);
CREATE TABLE chat_message_join (chat_id INTEGER, message_id INTEGER);
`);
db.exec(`INSERT INTO handle VALUES (1,'+15551234567')`);
diff --git a/server/services/tribeOutreach.js b/server/services/tribeOutreach.js
index 1018a927cc..8a8cec61b7 100644
--- a/server/services/tribeOutreach.js
+++ b/server/services/tribeOutreach.js
@@ -120,6 +120,8 @@ export function groupUnansweredThreads(events, { now = Date.now(), staleAfterMs
const groups = new Map();
for (const ev of events || []) {
if (!ev || !MESSAGE_KINDS.has(ev.kind)) continue;
+ // A Tapback/reaction is not a message awaiting (or constituting) a reply.
+ if (ev.metadata?.isReaction) continue;
const key = conversationKey(ev);
if (!key) continue;
if (!groups.has(key)) groups.set(key, []);
@@ -208,10 +210,12 @@ export async function findUnansweredTribeThreads({
}).catch(() => { /* partial read → drop this source to avoid false nudges */ })
));
- // Every outbound turn just needs to cancel the unanswered flag for its
- // conversation (grouped by chatGuid/conversationId).
- const tagged = [...sent];
+ // Drop Tapbacks/reactions from both directions — a reaction is not a message
+ // awaiting a reply (it must not anchor an "unanswered" thread), and a sent
+ // reaction is not a real reply (it must not mark a thread answered).
+ const tagged = sent.filter((ev) => !ev.metadata?.isReaction);
for (const ev of received) {
+ if (ev.metadata?.isReaction) continue;
// Scope to 1:1 conversations — a chat with more than one counterpart is a
// group, where "you never replied" rarely means a personal obligation and
// multi-sender turns can't be cleanly attributed or anchored. A 1:1 chat's
@@ -319,7 +323,9 @@ async function generateOutreachDraftImpl({
}).catch(() => []);
const sorted = (convoEvents || [])
- .filter((ev) => MESSAGE_KINDS.has(ev.kind))
+ // Exclude reactions here too — they must neither anchor the reply nor pad the
+ // grounding context as spurious '[non-text message]' turns.
+ .filter((ev) => MESSAGE_KINDS.has(ev.kind) && !ev.metadata?.isReaction)
.sort((a, b) => Date.parse(a.happenedAt) - Date.parse(b.happenedAt));
// Anchor to the EXACT detected inbound (by timestamp) in the FULL list, BEFORE
// any grounding-window truncation — otherwise a long tail of later turns could
diff --git a/server/services/tribeOutreach.test.js b/server/services/tribeOutreach.test.js
index 1b7905bb35..a2ee244b65 100644
--- a/server/services/tribeOutreach.test.js
+++ b/server/services/tribeOutreach.test.js
@@ -145,6 +145,16 @@ describe('groupUnansweredThreads', () => {
expect(out).toHaveLength(0); // replied within the same email thread
});
+ it('ignores Tapback/reaction turns — a reaction neither anchors nor answers', () => {
+ // A reaction as the last inbound must NOT create an unanswered nudge.
+ const out = groupUnansweredThreads([
+ inbound({ happenedAt: daysAgo(5), summary: 'dinner Friday?' }),
+ { kind: 'message.sent', source: 'imessage', happenedAt: daysAgo(4), metadata: { chatGuid: 'chat-1' } },
+ inbound({ happenedAt: daysAgo(2), summary: 'liked "sounds good"', metadata: { chatGuid: 'chat-1', handle: '+15550001', isReaction: true } }),
+ ], WINDOW);
+ expect(out).toHaveLength(0); // the real inbound was answered; the reaction is ignored
+ });
+
it('drops events with unparseable timestamps without throwing', () => {
const out = groupUnansweredThreads([inbound({ happenedAt: 'not-a-date' })], WINDOW);
expect(out).toHaveLength(0);