Repository navigation
feat(pipeline): share insights and dedupe reports across mailboxes - #11
Merged
Merged
Conversation
When the same email reaches several mailboxes, each copy was analyzed on its own (two AI calls, possibly different summaries and to-dos), pushed to the same channel twice, and listed twice in daily and weekly reports. A copy is the same email when Message-ID, sender (case-insensitive) and subject all match, so a forged Message-ID can't pick up another email's insight. - Reuse an existing insight and its AI labels from another copy instead of calling the AI; copies are processed one at a time per Message-ID so simultaneous arrivals still call the AI once - Reanalysis updates every copy that already has an insight - Push each email to a channel once; per-mailbox rule actions (mark read, star, move) still run on every copy - Reports count an email once in totals, categories, important, needs reply and bills; per-account counts stay per mailbox, and a reply from any copy clears needs reply - Add a partial index on messages.message_id for cross-account lookup Closes #9 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In the all-mailboxes list, a thread whose latest email also appears in another mailbox's thread is folded into that thread, so the same conversation shows once with every mailbox it is in. When both latest emails are the same, the thread with more matching messages is kept. Per-mailbox and per-folder views are unchanged. The merged row and the reading pane carry copyThreadIds; read, star, archive, trash, delete and label actions apply to every copy. The containment query uses LEFT JOIN / GROUP BY instead of correlated NOT EXISTS so the planner estimate stays low and JIT is not triggered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In the all-mailboxes reader, the star button only looked at the open thread, so it showed unstarred while the merged list row showed a star when only another mailbox's copy was starred. Clicking it did nothing, because the open thread had no starred message to clear. getThread now returns copiesFlagged, scoped to visible mailboxes, and the reader counts it. When the open thread has nothing to change, the action still applies to the copy threads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #9
Why
When the same email reaches several of your mailboxes, each copy was analyzed separately (two AI calls, possibly different summaries and to-dos), pushed to the same channel twice, and listed twice in daily and weekly reports.
What changed
A copy counts as the same email when Message-ID, sender (case-insensitive) and subject all match, so a forged Message-ID can't pick up another email's insight or hide another email in reports.
AI analysis (
server/src/services/pipeline.ts)copiedFrom.reanalyze) updates every other copy that already has an insight (syncedCopiesin the job result).Notifications: the issue left this open. I went with push once per email.
notifyactions and event subscriptions alike.process_messagejobs, plus a 60-second in-memory record covering the gap before a job's result is written.Reports (
server/src/services/reports.ts)receivedCtetakes a newacrossAccountsoption. Reports use it for totals, previous-period count, categories, daily series, top senders, important, needs reply and bills.answeredis true when any copy was replied to, so a reply sent from another mailbox clears "needs reply".All-mailboxes view (
server/src/services/mail.ts,web/)copyThreadIds. Read, unread, star, unstar, archive, trash, delete and labels apply to every copy. Opening a merged thread marks every copy read.copiesFlagged), so it matches the list row, and unstar clears a star held only by a copy.Schema: migration
0025_message_id_globaladds a partial index onmessages.message_id(where not null) for the cross-account lookup.Reviewer notes
analytics.ts) also usesreceivedCtein per-account mode. Two things change there:answeredis true if any folder copy was replied to.jobstable, which is kept forKEEP_DAYS.LEFT JOIN/GROUP BYrather than correlatedNOT EXISTS. The correlated version made Postgres overestimate the cost and spend ~360ms in JIT compilation; now the all-mailboxes list takes about as long as a single inbox.Tests
server/test/cross-mailbox.test.tscovers:pnpm testinserver/: 177/177 pass.tsc --noEmitis clean.web/type-checks and builds.🤖 Generated with Claude Code