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.

perf(max): avoid quadratic error filtering in the legacy thread (#123066)

Paul D'Ambra51e3e15de25e
diff --git a/frontend/src/scenes/max/Thread.tsx b/frontend/src/scenes/max/Thread.tsx
index c0372f98c634..d20794796bdb 100644
--- a/frontend/src/scenes/max/Thread.tsx
+++ b/frontend/src/scenes/max/Thread.tsx
@@ -251,6 +251,8 @@ function LegacyThread({ showTrailers }: { showTrailers: boolean }): JSX.Element
[threadGrouped, streamingActive, canCreateTicket]
)
+ const lastErrorIndex = useMemo(() => threadGrouped.findLastIndex(isErrorMessage), [threadGrouped])
+
return (conversationLoading || messagesLoading) && threadGrouped.length === 0 ? (
<>
<MessageGroupSkeleton groupType="human" />
@@ -279,11 +281,8 @@ function LegacyThread({ showTrailers }: { showTrailers: boolean }): JSX.Element
}
// Hide old failed attempts - only show the most recent error
- if (isErrorMessage(message)) {
- const hasNewerError = threadGrouped.slice(index + 1).some(isErrorMessage)
- if (hasNewerError) {
- return null
- }
+ if (isErrorMessage(message) && index < lastErrorIndex) {
+ return null
}
// Hide duplicate human messages from retry pattern: Human → AI Error → Human (duplicate)