fix: derive captain reopen cohort from handled conversations

This commit is contained in:
Shivam Mishra
2026-07-01 12:16:37 +05:30
parent 76dc037c1a
commit b9e7030908
@@ -181,12 +181,13 @@ class Captain::AssistantStatsBuilder
values.map { |value| quote(value) }.join(', ')
end
# Of the conversations Captain auto-resolved (inbox-based), the share reopened afterwards.
# Covers both the evaluated (inference) and time-based (bot) resolve paths so the
# denominator matches auto_resolution_rate.
# Of the conversations Captain auto-resolved, the share reopened afterwards. The cohort is
# derived from the assistant's handled conversations (not current inbox membership) so a later
# inbox reassignment doesn't drop historical resolves, and covers both the evaluated (inference)
# and time-based (bot) resolve paths so the denominator matches auto_resolution_rate.
def reopen_rate(range)
resolved_scope = account.reporting_events.where(name: RESOLVED_EVENT_NAMES,
inbox_id: assistant_inbox_ids, created_at: range)
resolved_scope = account.reporting_events.where(name: RESOLVED_EVENT_NAMES, created_at: range,
conversation_id: handled_scope(range).select(:conversation_id))
# event_start_time on a reopen is the preceding resolve's timestamp, so requiring it
# within the window keeps only reopens that followed the in-window resolve, not an
# earlier resolve/reopen cycle on the same conversation.
@@ -198,10 +199,6 @@ class Captain::AssistantStatsBuilder
rate(reopened, resolved_scope.distinct.count(:conversation_id))
end
def assistant_inbox_ids
@assistant_inbox_ids ||= assistant.inboxes.ids
end
# Approved/pending FAQ counts and the document total in a single round trip.
def knowledge
approved, pending, documents = Captain::AssistantResponse.by_assistant(assistant.id).reorder(nil).pick(