Stop merging unrelated emails into a customer's other open ticket

Inbound email with no In-Reply-To/References match against a tracked
message now always opens a new ticket, instead of falling back to the
customer's most recent open ticket. That fallback made sense for
Telegram/website chat (no subject, single running stream) but was
wrong for email, where an unrelated new request from a repeat
customer got silently appended to whatever ticket happened to still
be open.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gh2UXUQUVBWroWEnn1FLFG
This commit is contained in:
ogrechkoandClaude Sonnet 5 committed 2026-09-07 05:22:29 +00:00
1 parent d96e354e63
commit 99927aea0b
1 file changed
+7 -5
+7 -5
View File
@@ -310,10 +310,12 @@ export async function recordChatInboundMessage(params: {
} }
/** /**
* Records an inbound email. Prefers exact thread matching via * Records an inbound email. Threads it onto an existing ticket only via
* In-Reply-To/References (so a reply to a specific closed ticket lands on * exact In-Reply-To/References matching. Unlike Telegram/the website widget
* that ticket, not a random other open one); falls back to the same * (a continuous chat stream with no subject), email always carries a
* find-or-create-open-ticket heuristic used for Telegram. * distinct subject per conversation — so a message with no header match is
* always a new, unrelated request and must become its own ticket, even if
* the customer already has another ticket open.
*/ */
export async function recordEmailInboundMessage(params: { export async function recordEmailInboundMessage(params: {
fromEmail: string; fromEmail: string;
@@ -330,7 +332,7 @@ export async function recordEmailInboundMessage(params: {
const matchedTicketId = await findTicketIdByEmailReferences(params.referencedMessageIds); const matchedTicketId = await findTicketIdByEmailReferences(params.referencedMessageIds);
let ticket = matchedTicketId let ticket = matchedTicketId
? await db.query.tickets.findFirst({ where: eq(tickets.id, matchedTicketId) }) ? await db.query.tickets.findFirst({ where: eq(tickets.id, matchedTicketId) })
: await findOpenTicketForCustomer(customer.id); : null;
let ticketIsNew = false; let ticketIsNew = false;
if (!ticket) { if (!ticket) {