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(posthog-ai): tolerate trailing punctuation in ticket topic parsing (#71327)

Steven Shultse8858fdabe15
diff --git a/frontend/src/scenes/max/ticketUtils.test.ts b/frontend/src/scenes/max/ticketUtils.test.ts
index 13c54ebb2240..661ad0d64bc2 100644
--- a/frontend/src/scenes/max/ticketUtils.test.ts
+++ b/frontend/src/scenes/max/ticketUtils.test.ts
@@ -54,7 +54,19 @@ describe('ticketUtils', () => {
['bold topic line with valid area', 'Issue: foo\n\n**Topic:** data_warehouse', 'data_warehouse'],
['plain topic line with valid area', 'Issue: foo\n\nTopic: session_replay', 'session_replay'],
['case and whitespace variations', 'Issue: foo\n\ntopic: Data_Warehouse ', 'data_warehouse'],
+ ['trailing period is stripped', 'Issue: foo\n\nTopic: session_replay.', 'session_replay'],
+ [
+ 'trailing parenthetical is ignored',
+ 'Issue: foo\n\n**Topic:** data_warehouse (Stripe integration)',
+ 'data_warehouse',
+ ],
+ [
+ 'trailing comma and prose are ignored',
+ 'Issue: foo\n\nTopic: feature_flags, most likely',
+ 'feature_flags',
+ ],
['unknown area is rejected', 'Issue: foo\n\nTopic: quantum_computing', null],
+ ['unknown area with trailing prose is rejected', 'Issue: foo\n\nTopic: quantum_computing (maybe)', null],
['no topic line', 'Issue: foo\n\nStatus: bar', null],
['topic mentioned mid-sentence is ignored', 'Issue: the topic: billing came up in chat', null],
])('%s', (_name, content, expected) => {
diff --git a/frontend/src/scenes/max/ticketUtils.ts b/frontend/src/scenes/max/ticketUtils.ts
index ea37d97e821e..cb192e75d40f 100644
--- a/frontend/src/scenes/max/ticketUtils.ts
+++ b/frontend/src/scenes/max/ticketUtils.ts
@@ -23,7 +23,13 @@ export function parseTicketTargetArea(content: string): SupportTicketTargetArea
const line = rawLine.replace(/\*/g, '').trim()
const match = line.match(/^topic:\s*(.+)$/i)
if (match) {
- const area = match[1].trim().toLowerCase()
+ // Keys are single whitespace-free tokens, so take the first token and strip trailing
+ // punctuation — the model sometimes appends a period or parenthetical
+ const area = match[1]
+ .trim()
+ .split(/\s+/)[0]
+ .replace(/[.,;:!?)\]]+$/, '')
+ .toLowerCase()
if (TARGET_AREA_OPTIONS.some((option) => option.value === area)) {
return area as SupportTicketTargetArea
}