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.

feat(conversations): show snooze and unsnooze in ticket activity history (#66637)

Abigailae9eb0326d01
diff --git a/products/conversations/backend/api/tests/test_snooze.py b/products/conversations/backend/api/tests/test_snooze.py
index d7a5e7fbbaa3..79f398fd2ad2 100644
--- a/products/conversations/backend/api/tests/test_snooze.py
+++ b/products/conversations/backend/api/tests/test_snooze.py
@@ -288,10 +288,11 @@ class TestWakeSnoozedTickets(BaseTest):
defaults.update(kwargs)
return Ticket.objects.create_with_number(**defaults)
+ @parameterized.expand([(Status.ON_HOLD,), (Status.PENDING,), (Status.RESOLVED,)])
@patch("products.conversations.backend.tasks.capture_ticket_status_changed")
- def test_wakes_expired_on_hold_ticket(self, mock_capture):
+ def test_expired_snooze_reopens_inactive_ticket(self, start_status, mock_capture):
ticket = self._make_ticket(
- status=Status.ON_HOLD,
+ status=start_status,
snoozed_until=timezone.now() - timedelta(minutes=5),
)
@@ -300,21 +301,7 @@ class TestWakeSnoozedTickets(BaseTest):
ticket.refresh_from_db()
self.assertEqual(ticket.status, Status.OPEN)
self.assertIsNone(ticket.snoozed_until)
- mock_capture.assert_called_once_with(ticket, Status.ON_HOLD, Status.OPEN, actor_type="system")
-
- @patch("products.conversations.backend.tasks.capture_ticket_status_changed")
- def test_clears_snooze_but_preserves_resolved_status(self, mock_capture):
- ticket = self._make_ticket(
- status=Status.RESOLVED,
- snoozed_until=timezone.now() - timedelta(minutes=5),
- )
-
- wake_snoozed_tickets()
-
- ticket.refresh_from_db()
- self.assertEqual(ticket.status, Status.RESOLVED)
- self.assertIsNone(ticket.snoozed_until)
- mock_capture.assert_not_called()
+ mock_capture.assert_called_once_with(ticket, start_status, Status.OPEN, actor_type="system")
@patch("products.conversations.backend.tasks.capture_ticket_status_changed")
def test_ignores_future_snoozed_tickets(self, mock_capture):
@@ -362,3 +349,55 @@ class TestWakeSnoozedTickets(BaseTest):
def test_noop_when_no_expired_tickets(self, mock_capture):
wake_snoozed_tickets()
mock_capture.assert_not_called()
+
+ @patch("products.conversations.backend.tasks.capture_ticket_status_changed")
+ def test_wake_logs_system_activity_for_reopen(self, _):
+ ticket = self._make_ticket(
+ status=Status.ON_HOLD,
+ snoozed_until=timezone.now() - timedelta(minutes=5),
+ )
+
+ wake_snoozed_tickets()
+
+ activity = ActivityLog.objects.filter(
+ team_id=self.team.id, scope="Ticket", item_id=str(ticket.id), activity="updated"
+ ).first()
+ assert activity is not None
+ assert activity.detail is not None
+ self.assertTrue(activity.is_system)
+ self.assertIsNone(activity.user_id)
+ changes = activity.detail.get("changes", [])
+
+ snooze_change = next((c for c in changes if c["field"] == "snoozed_until"), None)
+ assert snooze_change is not None
+ self.assertIsNotNone(snooze_change["before"])
+ self.assertIsNone(snooze_change["after"])
+
+ status_change = next((c for c in changes if c["field"] == "status"), None)
+ assert status_change is not None
+ self.assertEqual(status_change["before"], Status.ON_HOLD)
+ self.assertEqual(status_change["after"], Status.OPEN)
+
+ @parameterized.expand([(Status.OPEN,), (Status.NEW,)])
+ @patch("products.conversations.backend.tasks.capture_ticket_status_changed")
+ def test_wake_clears_snooze_on_active_ticket_without_status_change(self, start_status, mock_capture):
+ ticket = self._make_ticket(
+ status=start_status,
+ snoozed_until=timezone.now() - timedelta(minutes=5),
+ )
+
+ wake_snoozed_tickets()
+
+ ticket.refresh_from_db()
+ self.assertEqual(ticket.status, start_status)
+ self.assertIsNone(ticket.snoozed_until)
+ mock_capture.assert_not_called()
+
+ activity = ActivityLog.objects.filter(
+ team_id=self.team.id, scope="Ticket", item_id=str(ticket.id), activity="updated"
+ ).first()
+ assert activity is not None
+ assert activity.detail is not None
+ changes = activity.detail.get("changes", [])
+ self.assertEqual([c["field"] for c in changes], ["snoozed_until"])
+ self.assertIsNone(changes[0]["after"])
diff --git a/products/conversations/backend/tasks.py b/products/conversations/backend/tasks.py
index d84a93f863bf..5cae5d9393eb 100644
--- a/products/conversations/backend/tasks.py
+++ b/products/conversations/backend/tasks.py
@@ -19,6 +19,7 @@ import requests
import structlog
from celery import shared_task
+from posthog.models.activity_logging.activity_log import Change, Detail, log_activity
from posthog.models.comment import Comment as CommentModel
from posthog.models.team import Team
from posthog.models.uploaded_media import UploadedMedia
@@ -1417,6 +1418,36 @@ def poll_teams_shared_channels() -> None:
WAKE_SNOOZE_BATCH_SIZE = 100
+def _log_snooze_expired(ticket: Ticket, old_status: str, old_snoozed_until: datetime | None) -> None:
+ """Record the system snooze-expiry (and reopen, unless already open) in the activity log."""
+
+ changes = [
+ Change(
+ type="Ticket",
+ field="snoozed_until",
+ before=old_snoozed_until.isoformat() if old_snoozed_until else None,
+ after=None,
+ action="changed",
+ )
+ ]
+ if old_status not in (Status.OPEN, Status.NEW):
+ changes.append(Change(type="Ticket", field="status", before=old_status, after=Status.OPEN, action="changed"))
+
+ try:
+ log_activity(
+ organization_id=ticket.team.organization_id,
+ team_id=ticket.team_id,
+ user=None, # system actor — distinguishes auto-expiry from a manual unsnooze
+ was_impersonated=False,
+ item_id=str(ticket.id),
+ scope="Ticket",
+ activity="updated",
+ detail=Detail(name=f"Ticket #{ticket.ticket_number}", changes=changes),
+ )
+ except Exception:
+ logger.exception("wake_snoozed_ticket_activity_log_failed", ticket_id=str(ticket.id))
+
+
@shared_task(ignore_result=True)
def wake_snoozed_tickets() -> None:
"""Reopen tickets whose snooze period has expired, in batches."""
@@ -1427,7 +1458,8 @@ def wake_snoozed_tickets() -> None:
while True:
with transaction.atomic():
batch = list(
- Ticket.objects.select_for_update(skip_locked=True)
+ Ticket.objects.select_for_update(skip_locked=True, of=("self",))
+ .select_related("team")
.filter(snoozed_until__isnull=False, snoozed_until__lte=now)
.order_by("snoozed_until")[:WAKE_SNOOZE_BATCH_SIZE]
)
@@ -1436,9 +1468,12 @@ def wake_snoozed_tickets() -> None:
for ticket in batch:
old_status = ticket.status
+ old_snoozed_until = ticket.snoozed_until
ticket.snoozed_until = None
- if old_status == Status.ON_HOLD:
+ # An expiring snooze reopens the ticket, unless it's already active (open or
+ # new) — then there's just the snooze to clear, no status change.
+ if old_status not in (Status.OPEN, Status.NEW):
ticket.status = Status.OPEN
ticket.save(update_fields=["status", "snoozed_until", "updated_at"])
try:
@@ -1448,6 +1483,8 @@ def wake_snoozed_tickets() -> None:
else:
ticket.save(update_fields=["snoozed_until", "updated_at"])
+ _log_snooze_expired(ticket, old_status, old_snoozed_until)
+
total += len(batch)
if len(batch) < WAKE_SNOOZE_BATCH_SIZE:
break
diff --git a/products/conversations/frontend/activityDescriber.test.tsx b/products/conversations/frontend/activityDescriber.test.tsx
new file mode 100644
index 000000000000..d0390788c75d
--- /dev/null
+++ b/products/conversations/frontend/activityDescriber.test.tsx
@@ -0,0 +1,75 @@
+import { render } from '@testing-library/react'
+
+import { ActivityChange, ActivityLogItem } from 'lib/components/ActivityLog/humanizeActivity'
+
+import { ActivityScope } from '~/types'
+
+import { ticketActivityDescriber } from './activityDescriber'
+
+const getTextContent = (describer: { description: JSX.Element | string | null }): string => {
+ if (!describer.description || typeof describer.description === 'string') {
+ return (describer.description as string) || ''
+ }
+ const { container } = render(describer.description)
+ return container.textContent || ''
+}
+
+const ticketLogItem = (overrides: Partial<ActivityLogItem>): ActivityLogItem => ({
+ activity: 'updated',
+ created_at: '2026-06-25T10:00:00Z',
+ scope: 'Ticket',
+ item_id: 'ticket-uuid',
+ detail: { merge: null, trigger: null, changes: null, name: 'Ticket #2043' },
+ ...overrides,
+})
+
+describe('ticketActivityDescriber', () => {
+ const snoozeCleared: ActivityChange = {
+ type: ActivityScope.TICKET,
+ action: 'changed',
+ field: 'snoozed_until',
+ before: '2026-06-25T10:00:00Z',
+ after: null,
+ }
+ const reopened: ActivityChange = {
+ type: ActivityScope.TICKET,
+ action: 'changed',
+ field: 'status',
+ before: 'on_hold',
+ after: 'open',
+ }
+
+ it('describes a manual unsnooze (user present) as "removed snooze"', () => {
+ const result = ticketActivityDescriber(
+ ticketLogItem({
+ user: { email: '[email protected]', first_name: 'Max', last_name: 'AI' },
+ detail: { merge: null, trigger: null, name: 'Ticket #2043', changes: [snoozeCleared] },
+ })
+ )
+ const text = getTextContent(result)
+ expect(text).toContain('removed snooze')
+ expect(text).not.toContain('snooze expired')
+ })
+
+ it('describes a system snooze-expiry (no user) as "snooze expired – reopened"', () => {
+ const result = ticketActivityDescriber(
+ ticketLogItem({
+ detail: { merge: null, trigger: null, name: 'Ticket #2043', changes: [snoozeCleared, reopened] },
+ })
+ )
+ const text = getTextContent(result)
+ expect(text).toContain('snooze expired')
+ expect(text).toContain('reopened')
+ })
+
+ it('describes a system snooze-expiry with no status change as "snooze expired" (not reopened)', () => {
+ const result = ticketActivityDescriber(
+ ticketLogItem({
+ detail: { merge: null, trigger: null, name: 'Ticket #3', changes: [snoozeCleared] },
+ })
+ )
+ const text = getTextContent(result)
+ expect(text).toContain('snooze expired')
+ expect(text).not.toContain('reopened')
+ })
+})
diff --git a/products/conversations/frontend/activityDescriber.tsx b/products/conversations/frontend/activityDescriber.tsx
index a9f503a418d1..2a2fdfb07bb0 100644
--- a/products/conversations/frontend/activityDescriber.tsx
+++ b/products/conversations/frontend/activityDescriber.tsx
@@ -88,6 +88,42 @@ const ticketActionsMapping: Record<
],
}
},
+ snoozed_until: function onSnoozedUntil(change, logItem) {
+ const before = change?.before as string | null
+ const after = change?.after as string | null
+
+ if (!before && after) {
+ return {
+ description: [
+ <>
+ snoozed until{' '}
+ <strong>
+ <TZLabel time={after} />
+ </strong>
+ </>,
+ ],
+ }
+ }
+ if (before && !after) {
+ // The same set→null change happens for a manual unsnooze and the system
+ // wake task auto-expiring the snooze — tell them apart by actor. Only claim
+ // "reopened" when the expiry actually flipped the ticket back to open; a
+ // snooze on an already-resolved ticket clears without reopening it.
+ if (logItem?.user) {
+ return { description: [<>removed snooze</>] }
+ }
+ const reopened = (logItem?.detail?.changes ?? []).some((c) => c.field === 'status' && c.after === 'open')
+ return { description: [reopened ? <>snooze expired – reopened</> : <>snooze expired</>] }
+ }
+ return {
+ description: [
+ <>
+ changed snooze from <strong>{before ? <TZLabel time={before} /> : 'none'}</strong> to{' '}
+ <strong>{after ? <TZLabel time={after} /> : 'none'}</strong>
+ </>,
+ ],
+ }
+ },
tag: function onTag(change) {
const tagName = (change?.after || change?.before) as string
if (change?.action === 'created') {