Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(conversations): exclude tags from compose dedupe identity (#103860)

Abigail1f2ffeae02d8
diff --git a/products/conversations/backend/api/tests/test_tickets.py b/products/conversations/backend/api/tests/test_tickets.py
index a274012de872..ecf6ee8a04ef 100644
--- a/products/conversations/backend/api/tests/test_tickets.py
+++ b/products/conversations/backend/api/tests/test_tickets.py
@@ -2349,8 +2349,9 @@ class TestComposeTicketAPI(APIBaseTest):
assert first.json()["id"] != second.json()["id"]
assert Ticket.objects.filter(team=self.team).count() == 2
- def test_compose_same_content_with_different_tags_is_not_deduplicated(self, mock_on_commit):
- # A different tag set must open its own ticket, not silently drop the tags of a replay.
+ def test_compose_same_content_with_different_tags_is_deduplicated(self, mock_on_commit):
+ # Tags are not part of the dedupe identity, so the same content to the same recipient
+ # replays the first ticket. A replay does not re-tag, so the first ticket's tags stand.
base = {
"recipient_email": "[email protected]",
"email_config_id": str(self.email_config.id),
@@ -2361,14 +2362,35 @@ class TestComposeTicketAPI(APIBaseTest):
second = self._compose({**base, "tags": ["bug_report"]})
assert first.status_code == status.HTTP_201_CREATED
- assert second.status_code == status.HTTP_201_CREATED
- assert first.json()["id"] != second.json()["id"]
- assert Ticket.objects.filter(team=self.team).count() == 2
+ assert second.status_code == status.HTTP_200_OK
+ assert first.json()["id"] == second.json()["id"]
+ assert Ticket.objects.filter(team=self.team).count() == 1
- first_detail = self.client.get(f"/api/projects/{self.team.id}/conversations/tickets/{first.json()['id']}/")
- second_detail = self.client.get(f"/api/projects/{self.team.id}/conversations/tickets/{second.json()['id']}/")
- assert first_detail.json()["tags"] == ["roadmap_pitch"]
- assert second_detail.json()["tags"] == ["bug_report"]
+ detail = self.client.get(f"/api/projects/{self.team.id}/conversations/tickets/{first.json()['id']}/")
+ assert detail.json()["tags"] == ["roadmap_pitch"]
+
+ def test_compose_replays_after_the_ticket_gains_a_system_tag(self, mock_on_commit):
+ # The system tags a composed ticket after it is created (plan tier at creation, then
+ # triage). A retry must still replay the original ticket, not open a duplicate.
+ payload = {
+ "recipient_email": "[email protected]",
+ "email_config_id": str(self.email_config.id),
+ "message": "Great idea, we logged it.",
+ "tags": ["roadmap_pitch"],
+ }
+
+ first = self._compose(payload)
+ assert first.status_code == status.HTTP_201_CREATED
+
+ ticket = Ticket.objects.get(pk=first.json()["id"])
+ plan_tag, _ = Tag.objects.get_or_create(name="plan_free", team_id=self.team.id)
+ ticket.tagged_items.create(tag=plan_tag)
+
+ second = self._compose(payload)
+
+ assert second.status_code == status.HTTP_200_OK
+ assert second.json()["id"] == first.json()["id"]
+ assert Ticket.objects.filter(team=self.team).count() == 1
def test_compose_recovers_the_existing_ticket_past_newer_unrelated_tickets(self, mock_on_commit):
# A burst of newer, unrelated tickets to the same channel must not crowd out the real match.
diff --git a/products/conversations/backend/api/tickets.py b/products/conversations/backend/api/tickets.py
index 12a591273c80..73214c62208a 100644
--- a/products/conversations/backend/api/tickets.py
+++ b/products/conversations/backend/api/tickets.py
@@ -41,7 +41,6 @@ from posthog.api.tagged_item import (
BulkUpdateTagsUUIDResponseSerializer,
TaggedItemSerializerMixin,
TaggedItemViewSetMixin,
- normalize_tag_names,
set_tags_on_object,
)
from posthog.dataclasses import frozen
@@ -1907,7 +1906,6 @@ class TicketViewSet(TaggedItemViewSetMixin, TeamAndOrgViewSetMixin, AccessContro
rich_content=data.get("rich_content"),
distinct_id=distinct_id,
creator_id=request.user.id if request.user and request.user.is_authenticated else None,
- tags=normalize_tag_names(data.get("tags") or []),
)
assert fingerprint is not None
guarded = reply_dedupe.create_ticket_deduplicated(fingerprint, create_ticket)
diff --git a/products/conversations/backend/reply_dedupe.py b/products/conversations/backend/reply_dedupe.py
index 1d479f0e6079..66bb4793a1f9 100644
--- a/products/conversations/backend/reply_dedupe.py
+++ b/products/conversations/backend/reply_dedupe.py
@@ -19,7 +19,7 @@ replica and report a conflict for a reservation that already resolved. This clie
import json
import uuid
import hashlib
-from collections.abc import Callable, Iterable
+from collections.abc import Callable
from dataclasses import dataclass
from datetime import datetime, timedelta
from enum import Enum
@@ -30,7 +30,6 @@ from django.utils import timezone
import structlog
-from posthog.api.tagged_item import current_tag_names
from posthog.models.comment import Comment
from posthog.redis import get_client
@@ -381,7 +380,7 @@ def _classify_held_value(key: str, held: Any, token: str) -> Reservation:
# Compose opens a brand-new outbound ticket, so it hashes into its own keyspace — a compose retry
# must never collapse onto a reply, or vice versa. Bump the version when the contents below change.
-_COMPOSE_KEY_PREFIX = "conversations:compose_dedupe:v4:"
+_COMPOSE_KEY_PREFIX = "conversations:compose_dedupe:v5:"
@dataclass(frozen=True, kw_only=True)
@@ -391,6 +390,9 @@ class ComposeFingerprint:
Two requests with the same fingerprint open the same outbound ticket: same team, sending
channel, recipient, subject, first message, and resolved person link. ``build`` returns None
for anything this guard must not collapse.
+
+ Tags are not part of the identity. The system tags a ticket after it is created (plan tier at
+ creation, then triage), so the ticket's live tags outgrow the request's and cannot identify it.
"""
team_id: int
@@ -406,8 +408,6 @@ class ComposeFingerprint:
# send identical content to the same recipient are two distinct tickets, so they must not
# collapse — only a genuine retry from the same author does.
creator_id: int | None
- # Two composes that differ only by tags are distinct requests, not a replay of one another.
- tags: frozenset[str]
@classmethod
def build(
@@ -421,7 +421,6 @@ class ComposeFingerprint:
rich_content: Any,
distinct_id: Any,
creator_id: int | None,
- tags: Iterable[str] = (),
) -> "ComposeFingerprint | None":
if not email_config_id or not recipient_email or not isinstance(message, str) or not message:
return None
@@ -434,7 +433,6 @@ class ComposeFingerprint:
rich_content=rich_content,
distinct_id=str(distinct_id or ""),
creator_id=creator_id,
- tags=frozenset(tags),
)
@property
@@ -449,7 +447,6 @@ class ComposeFingerprint:
"rich_content": self.rich_content,
"distinct_id": self.distinct_id,
"creator_id": self.creator_id,
- "tags": sorted(self.tags),
},
sort_keys=True,
separators=(",", ":"),
@@ -482,9 +479,6 @@ class ComposeFingerprint:
# a distinct ticket even when everything else matches.
if first.created_by_id != self.creator_id:
return False
- # A retry that adds or drops a tag must not replay a differently-tagged ticket.
- if current_tag_names(ticket) != self.tags:
- return False
return True
def find_persisted_match(self, *, created_after: datetime) -> Ticket | None: