: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(mobile): collapse long agent task notices (#128291)
Chris Volzer227cbdda021e
diff --git a/products/mobile/docs/CHAT.md b/products/mobile/docs/CHAT.mdindex 8ff714004081..61c62110cd9d 100644--- a/products/mobile/docs/CHAT.md+++ b/products/mobile/docs/CHAT.md@@ -391,6 +391,10 @@ New chat drops it.`html: false`; images are dropped. Relative links open on the signed-in host; only http(s) links open.- The status line shows the current stage or tool, "Thinking…", or "Reconnecting…".- Thoughts and tool calls fold into activity rows. Every row starts closed, also while it runs. `mobile_chat_activity_expanded` is captured with `running` and `tool_count` when the person opens one.+- Background-task notices (including checkmarked completion summaries) align left and show at most two lines by default.+ Notices that wrap beyond two lines offer Show more to read the full text and Show less to return to the preview.+ Expanding or collapsing a notice pauses automatic scrolling so it stays in view.+ Scrolling back also pauses automatic scrolling; scroll to the bottom to follow new messages again.- Known PRs remain available while execution is active, idle or terminal. Their state is separatefrom execution; a discovered URL starts unknown until the report supplies authoritative state.- Report task status opens that implementation task, including idle and completed runs that candiff --git a/products/mobile/src/features/chat/session/NoticeRow.test.tsx b/products/mobile/src/features/chat/session/NoticeRow.test.tsxnew file mode 100644index 000000000000..f42debe21efc--- /dev/null+++ b/products/mobile/src/features/chat/session/NoticeRow.test.tsx@@ -0,0 +1,57 @@+import { fireEvent, render, screen } from '@testing-library/react-native'++import { NoticeRow } from './NoticeRow'+import type { SessionNoticeItem } from './types'++const NOTICE: SessionNoticeItem = {+ kind: 'notice',+ id: 'background-review',+ tone: 'completed',+ text: 'The background review finished. The report filters and export dialog are ready to inspect.',+}++function measureLines(count: number): void {+ fireEvent(+ screen.getByTestId(`session-notice-measure-${NOTICE.id}`, { includeHiddenElements: true }),+ 'textLayout',+ {+ nativeEvent: { lines: Array.from({ length: count }, () => ({ text: 'A measured line' })) },+ }+ )+}++describe('NoticeRow', () => {+ test('previews long notices, expands their full text, and collapses them again', () => {+ render(<NoticeRow item={NOTICE} />)+ measureLines(4)++ expect(screen.getAllByText(NOTICE.text)).toHaveLength(1)+ expect(screen.getByText(NOTICE.text)).toHaveProp('numberOfLines', 2)+ expect(screen.getByRole('button')).toHaveProp('accessibilityState', { expanded: false })++ fireEvent.press(screen.getByText('Show more'))+ expect(screen.getByText(NOTICE.text).props.numberOfLines).toBeUndefined()+ expect(screen.getByRole('button')).toHaveProp('accessibilityState', { expanded: true })++ fireEvent.press(screen.getByText('Show less'))+ expect(screen.getByText(NOTICE.text)).toHaveProp('numberOfLines', 2)+ expect(screen.getByText('Show more')).toBeTruthy()+ })++ test.each([1, 2])('keeps a %i-line notice plain and responds when wrapping changes', (lines) => {+ render(<NoticeRow item={NOTICE} />)+ measureLines(lines)+ expect(screen.queryByRole('button')).toBeNull()++ measureLines(3)+ fireEvent.press(screen.getByText('Show more'))+ expect(screen.getByText('Show less')).toBeTruthy()++ measureLines(lines)+ expect(screen.queryByRole('button')).toBeNull()+ expect(screen.getByText(NOTICE.text)).toHaveProp('numberOfLines', 2)++ measureLines(3)+ expect(screen.getByRole('button')).toHaveProp('accessibilityState', { expanded: false })+ })+})diff --git a/products/mobile/src/features/chat/session/NoticeRow.tsx b/products/mobile/src/features/chat/session/NoticeRow.tsxindex 155e516eeb97..26ca88c9e2c7 100644--- a/products/mobile/src/features/chat/session/NoticeRow.tsx+++ b/products/mobile/src/features/chat/session/NoticeRow.tsx@@ -1,8 +1,9 @@-import { memo, type ReactElement } from 'react'+import { memo, type ReactElement, useState } from 'react'import { ActivityIndicator, Text, View } from 'react-native'import { CheckIcon } from '@/ui/icons/CheckIcon'import { WarningIcon } from '@/ui/icons/WarningIcon'+import { Pressable44 } from '@/ui/Pressable44'import { createStyles, useColors } from '@/ui/theme'import { iconSizes, type } from '@/ui/tokens'@@ -10,6 +11,7 @@ import type { SessionNoticeItem } from './types'interface NoticeRowProps {item: SessionNoticeItem+ onToggle?: () => void}function NoticeIcon({ item }: NoticeRowProps): ReactElement | null {@@ -26,12 +28,49 @@ function NoticeIcon({ item }: NoticeRowProps): ReactElement | null {return null}-export const NoticeRow = memo(function NoticeRow({ item }: NoticeRowProps): ReactElement {+export const NoticeRow = memo(function NoticeRow({ item, onToggle }: NoticeRowProps): ReactElement {const styles = useStyles()+ const [expanded, setExpanded] = useState(false)+ const [overflows, setOverflows] = useState(false)+return (- <View style={styles.row} accessibilityRole="text" testID={`session-notice-${item.id}`}>+ <View style={styles.row} testID={`session-notice-${item.id}`}><NoticeIcon item={item} />- <Text style={styles.text}>{item.text}</Text>+ <View style={styles.body}>+ <Text style={styles.text} numberOfLines={expanded ? undefined : 2} ellipsizeMode="tail">+ {item.text}+ </Text>+ {/* Measure without a line limit so truncation cannot hide overflow from the toggle. */}+ <Text+ style={[styles.text, styles.measure]}+ accessible={false}+ accessibilityElementsHidden+ importantForAccessibility="no-hide-descendants"+ pointerEvents="none"+ onTextLayout={({ nativeEvent }) => {+ const nextOverflows = nativeEvent.lines.length > 2+ setOverflows(nextOverflows)+ if (!nextOverflows) {+ setExpanded(false)+ }+ }}+ testID={`session-notice-measure-${item.id}`}+ >+ {item.text}+ </Text>+ {overflows ? (+ <Pressable44+ onPress={() => {+ onToggle?.()+ setExpanded(!expanded)+ }}+ accessibilityState={{ expanded }}+ style={styles.toggle}+ >+ <Text style={styles.toggleText}>{expanded ? 'Show less' : 'Show more'}</Text>+ </Pressable44>+ ) : null}+ </View></View>)})@@ -39,15 +78,32 @@ export const NoticeRow = memo(function NoticeRow({ item }: NoticeRowProps): Reacconst useStyles = createStyles(({ colors }) => ({row: {flexDirection: 'row',- alignItems: 'center',- justifyContent: 'center',+ alignItems: 'flex-start',gap: 6,- paddingHorizontal: 12,+ },+ body: {+ flex: 1,+ minWidth: 0,},text: {...type.meta,color: colors.muted,- textAlign: 'center',- flexShrink: 1,+ textAlign: 'left',+ },+ measure: {+ position: 'absolute',+ top: 0,+ left: 0,+ right: 0,+ opacity: 0,+ },+ toggle: {+ alignSelf: 'flex-start',+ minHeight: 32,+ justifyContent: 'center',+ },+ toggleText: {+ ...type.meta,+ color: colors.blue,},}))diff --git a/products/mobile/src/features/chat/session/SessionThread.test.tsx b/products/mobile/src/features/chat/session/SessionThread.test.tsxindex 2f57dfa11cc1..4b8a2e2a04dd 100644--- a/products/mobile/src/features/chat/session/SessionThread.test.tsx+++ b/products/mobile/src/features/chat/session/SessionThread.test.tsx@@ -1,4 +1,5 @@import { fireEvent, render, screen } from '@testing-library/react-native'+import { ScrollView } from 'react-native'import { SessionThread } from './SessionThread'import type { Session, SessionThreadItem, SessionToolInvocation } from './types'@@ -69,6 +70,56 @@ const TWO_GROUPS: SessionThreadItem[] = []describe('SessionThread', () => {+ afterEach(() => jest.restoreAllMocks())++ test.each([+ ['above newer messages', 200],+ ['at the bottom', 1300],+ ])('preserves the viewport when toggling a notice %s', (_name, offset) => {+ const scrollToEnd = jest.spyOn(ScrollView.prototype, 'scrollToEnd')+ const items: SessionThreadItem[] = [+ { kind: 'notice', id: 'n1', text: 'The background review finished.', tone: 'completed' },+ ...TWO_GROUPS,+ ]+ render(<SessionThread session={session({ items })} onRetryHistory={jest.fn()} />)+ const thread = screen.getByTestId('session-thread')+ fireEvent(screen.getByTestId('session-notice-measure-n1', { includeHiddenElements: true }), 'textLayout', {+ nativeEvent: { lines: [{ text: 'First line' }, { text: 'Second line' }, { text: 'Third line' }] },+ })+ fireEvent(thread, 'contentSizeChange', 400, 1800)+ expect(scrollToEnd).toHaveBeenLastCalledWith({ animated: false })+ fireEvent(thread, 'contentSizeChange', 400, 1850)+ expect(scrollToEnd).toHaveBeenLastCalledWith({ animated: true })+ scrollToEnd.mockClear()++ fireEvent(thread, 'scrollBeginDrag')+ fireEvent(thread, 'scrollEndDrag', {+ nativeEvent: {+ contentOffset: { y: offset },+ contentSize: { height: 1800 },+ layoutMeasurement: { height: 500 },+ },+ })+ fireEvent.press(screen.getByText('Show more'))+ fireEvent(thread, 'contentSizeChange', 400, 2000)+ fireEvent.press(screen.getByText('Show less'))+ fireEvent(thread, 'contentSizeChange', 400, 1800)+ fireEvent(thread, 'contentSizeChange', 400, 1850)+ expect(scrollToEnd).not.toHaveBeenCalled()++ fireEvent(thread, 'scrollBeginDrag')+ fireEvent(thread, 'momentumScrollEnd', {+ nativeEvent: {+ contentOffset: { y: 1350 },+ contentSize: { height: 1850 },+ layoutMeasurement: { height: 500 },+ },+ })+ fireEvent(thread, 'contentSizeChange', 400, 1900)+ expect(scrollToEnd).toHaveBeenCalledTimes(1)+ expect(scrollToEnd).toHaveBeenCalledWith({ animated: true })+ })+test('shows a retry state when the history fails to load', () => {const onRetryHistory = jest.fn()render(diff --git a/products/mobile/src/features/chat/session/SessionThread.tsx b/products/mobile/src/features/chat/session/SessionThread.tsxindex d72b5a086b37..e3302b75e89d 100644--- a/products/mobile/src/features/chat/session/SessionThread.tsx+++ b/products/mobile/src/features/chat/session/SessionThread.tsx@@ -1,5 +1,5 @@-import { memo, type ReactElement, type ReactNode, useMemo, useRef } from 'react'-import { ScrollView, Text, View } from 'react-native'+import { memo, type ReactElement, type ReactNode, useCallback, useMemo, useRef } from 'react'+import { type NativeScrollEvent, type NativeSyntheticEvent, ScrollView, Text, View } from 'react-native'import { PullRequestCard } from '@/features/handoff/PullRequestCard'import { WarningIcon } from '@/ui/icons/WarningIcon'@@ -57,10 +57,19 @@ export function SessionThread({ session, onRetryHistory, topInset = 0 }: Sessionconst styles = useStyles()const scroll = useRef<ScrollView>(null)const positioned = useRef(false)+ const following = useRef(true)const displayItems = useMemo(() => groupSessionItems(session.items), [session.items])+ const pauseFollowing = useCallback((): void => {+ following.current = false+ }, [])+ const updateFollowing = (event: NativeSyntheticEvent<NativeScrollEvent>): void => {+ const { contentOffset, contentSize, layoutMeasurement } = event.nativeEvent+ following.current = contentSize.height - contentOffset.y - layoutMeasurement.height <= 24+ }if (session.history.status === 'loading') {positioned.current = false+ following.current = truereturn (<View style={[styles.scroll, { paddingTop: topInset }]}><LoadingView label="Loading session" />@@ -102,7 +111,7 @@ export function SessionThread({ session, onRetryHistory, topInset = 0 }: Sessioncase 'error':return <ErrorRow key={item.id} item={item} />case 'notice':- return <NoticeRow key={item.id} item={item} />+ return <NoticeRow key={item.id} item={item} onToggle={pauseFollowing} />case 'progress':return <ProgressRow key={item.id} item={item} />}@@ -118,7 +127,13 @@ export function SessionThread({ session, onRetryHistory, topInset = 0 }: Sessionstyle={styles.scroll}contentContainerStyle={[styles.content, { paddingTop: topInset + 12 }]}scrollIndicatorInsets={{ top: topInset }}+ onScrollBeginDrag={pauseFollowing}+ onScrollEndDrag={updateFollowing}+ onMomentumScrollEnd={updateFollowing}onContentSizeChange={() => {+ if (!following.current) {+ return+ }scroll.current?.scrollToEnd({ animated: positioned.current })positioned.current = true}}