From 6729c66f135a349c1c4d29cb5fb8363e60d19cf7 Mon Sep 17 00:00:00 2001 From: Harshil Vasoya Date: Mon, 16 Nov 2026 12:31:08 +0530 Subject: [PATCH 1/5] chore: enhance session status indicators in chat hisotry and sessions --- .changeset/session-status-indicators.md | 5 +++ packages/trueforge-ui/package.json | 2 +- .../trueforge-ui/src/atoms/ThreadListRow.tsx | 12 ++++--- .../agent-details/AgentSessionListRow.tsx | 7 +++- .../src/atoms/lib/sessionListPoll.ts | 18 +++-------- .../src/atoms/lib/threadListMeta.ts | 29 ++++++++++++++--- .../trueforge-ui/src/icons/IconRegistry.tsx | 21 ++++++++++-- .../test/atoms/AgentSessionListRow.test.tsx | 23 +++++++++---- .../test/atoms/ThreadListRow.test.tsx | 31 ++++++++++++++---- .../test/atoms/lib/sessionListPoll.test.ts | 12 +++---- .../test/atoms/lib/threadListMeta.test.ts | 32 +++++++++++++++---- pnpm-lock.yaml | 19 +++++++++-- 12 files changed, 156 insertions(+), 55 deletions(-) create mode 100644 .changeset/session-status-indicators.md diff --git a/.changeset/session-status-indicators.md b/.changeset/session-status-indicators.md new file mode 100644 index 0000000000..9753d69804 --- /dev/null +++ b/.changeset/session-status-indicators.md @@ -0,0 +1,5 @@ +--- +'@truefoundry/trueforge-ui': patch +--- + +Hide paused status dots after 48 hours of inactivity, and show failed runs with a circle-xmark icon in the agent session list only (no failure chrome in chat history). Session lists poll running and paused rows every 5 seconds. diff --git a/packages/trueforge-ui/package.json b/packages/trueforge-ui/package.json index c7746efc71..d30d3830c2 100644 --- a/packages/trueforge-ui/package.json +++ b/packages/trueforge-ui/package.json @@ -101,7 +101,7 @@ "@truefoundry/trueforge-sdk": "workspace:*", "chart.js": "^4.5.1", "clsx": "^2.1.1", - "lucide-react": "^0.562.0", + "lucide-react": "^1.73.0", "monaco-editor": "^0.57.0", "partial-json": "^0.1.7", "react-chartjs-2": "^5.3.1", diff --git a/packages/trueforge-ui/src/atoms/ThreadListRow.tsx b/packages/trueforge-ui/src/atoms/ThreadListRow.tsx index ec9efcab95..6c75a179e1 100644 --- a/packages/trueforge-ui/src/atoms/ThreadListRow.tsx +++ b/packages/trueforge-ui/src/atoms/ThreadListRow.tsx @@ -85,12 +85,16 @@ export function ThreadListRow({ className, }: ThreadListRowProps) { const isMobile = useIsMobile(); - const statusDotClass = lastTurnStatusDotClass(lastTurnStatus); - const statusLabel = lastTurnStatusLabel(lastTurnStatus); + const statusDotClass = lastTurnStatusDotClass({ + status: lastTurnStatus, + ...(lastMessageAt != null ? { activityAt: lastMessageAt } : {}), + }); const running = isRunningTurnStatus(lastTurnStatus); const paused = isPausedTurnStatus(lastTurnStatus); + // Chat history keeps paused chrome; failed runs are session-list only. + const statusLabel = running || statusDotClass != null ? lastTurnStatusLabel(lastTurnStatus) : undefined; const age = lastMessageAt != null ? formatRelativeShort(lastMessageAt) : undefined; - // Paused/error → status dot; running → jumping dots; otherwise relative age. + // Paused → status dot; running → jumping dots; otherwise relative age. const relative = !running && statusDotClass == null ? age : undefined; const hasTrailing = running || relative != null || statusDotClass != null || actions != null; @@ -124,7 +128,7 @@ export function ThreadListRow({ {title} - {/* Mobile: keep the paused/error dot next to the title when actions own the trailing slot. */} + {/* Mobile: keep the paused dot next to the title when actions own the trailing slot. */} {statusDotClass != null && actions != null ? ( diff --git a/packages/trueforge-ui/src/atoms/agent-details/AgentSessionListRow.tsx b/packages/trueforge-ui/src/atoms/agent-details/AgentSessionListRow.tsx index 0977a9af40..c7c35da6d9 100644 --- a/packages/trueforge-ui/src/atoms/agent-details/AgentSessionListRow.tsx +++ b/packages/trueforge-ui/src/atoms/agent-details/AgentSessionListRow.tsx @@ -56,7 +56,8 @@ export function AgentSessionListRow({ const absolute = formatAbsoluteDateTime(activityAt); const subjectLabel = createdBySubject != null ? createdByLabel(createdBySubject) : null; const subjectInitials = subjectLabel != null ? getUserInitials(subjectLabel) || '?' : null; - const statusDotClass = lastTurnStatusDotClass(lastTurnStatus); + const statusDotClass = lastTurnStatusDotClass({ status: lastTurnStatus, activityAt }); + const failed = lastTurnStatus === 'error'; const statusLabel = lastTurnStatusLabel(lastTurnStatus); const running = isRunningTurnStatus(lastTurnStatus); const paused = isPausedTurnStatus(lastTurnStatus); @@ -78,6 +79,10 @@ export function AgentSessionListRow({ + ) : failed ? ( + + + ) : null} {statusLabel != null ? {statusLabel} : null} {scheduleId != null ? ( diff --git a/packages/trueforge-ui/src/atoms/lib/sessionListPoll.ts b/packages/trueforge-ui/src/atoms/lib/sessionListPoll.ts index 5347724322..38a9ba255c 100644 --- a/packages/trueforge-ui/src/atoms/lib/sessionListPoll.ts +++ b/packages/trueforge-ui/src/atoms/lib/sessionListPoll.ts @@ -3,23 +3,15 @@ import type { TurnStatus } from '../../server/types.js'; /** Matches thread-list / AgentSessions first-page `limit`. */ export const SESSION_LIST_FIRST_PAGE_LIMIT = 20; -/** Cadence while any listed row is still running. */ -export const SESSION_LIST_RUNNING_POLL_INTERVAL_MS = 10_000; +/** Cadence while any listed row is running or paused. */ +export const SESSION_LIST_POLL_INTERVAL_MS = 5_000; -/** Slower cadence when listed rows are only paused (approvals can wait a long time). */ -export const SESSION_LIST_PAUSED_POLL_INTERVAL_MS = 60_000; - -/** - * Poll interval for live last-turn status, or `null` when nothing needs polling. - * Running wins over paused so a mixed page stays on the fast cadence. - */ +/** Poll interval for live last-turn status, or `null` when nothing needs polling. */ export function sessionListPollIntervalMs(statuses: ReadonlyArray): number | null { - let hasPaused = false; for (const status of statuses) { - if (status === 'running') return SESSION_LIST_RUNNING_POLL_INTERVAL_MS; - if (status === 'paused') hasPaused = true; + if (status === 'running' || status === 'paused') return SESSION_LIST_POLL_INTERVAL_MS; } - return hasPaused ? SESSION_LIST_PAUSED_POLL_INTERVAL_MS : null; + return null; } /** diff --git a/packages/trueforge-ui/src/atoms/lib/threadListMeta.ts b/packages/trueforge-ui/src/atoms/lib/threadListMeta.ts index 29c7ab5739..27bd9f7ca1 100644 --- a/packages/trueforge-ui/src/atoms/lib/threadListMeta.ts +++ b/packages/trueforge-ui/src/atoms/lib/threadListMeta.ts @@ -9,13 +9,34 @@ function isTurnStatus(value: unknown): value is TurnStatus { return typeof value === 'string' && TURN_STATUS_VALUES.has(value); } +/** Orange paused dots older than this are hidden (AGE-2831). */ +export const PAUSED_STATUS_DOT_MAX_AGE_MS = 48 * 60 * 60 * 1000; + +function isValidActivityDate(date: Date): boolean { + return !Number.isNaN(date.getTime()); +} + /** Tailwind bg class for a last-turn status dot; undefined means hide the dot. */ -export function lastTurnStatusDotClass(status: TurnStatus | undefined | null): string | undefined { +export function lastTurnStatusDotClass({ + status, + activityAt, + now = new Date(), +}: { + status: TurnStatus | undefined | null; + activityAt?: Date | null; + now?: Date; +}): string | undefined { switch (status) { - case 'paused': + case 'paused': { + if ( + activityAt != null && + isValidActivityDate(activityAt) && + now.getTime() - activityAt.getTime() > PAUSED_STATUS_DOT_MAX_AGE_MS + ) { + return undefined; + } return 'bg-warning-bg'; - case 'error': - return 'bg-failure-bg'; + } default: return undefined; } diff --git a/packages/trueforge-ui/src/icons/IconRegistry.tsx b/packages/trueforge-ui/src/icons/IconRegistry.tsx index 13a5d4cd52..094644f46a 100644 --- a/packages/trueforge-ui/src/icons/IconRegistry.tsx +++ b/packages/trueforge-ui/src/icons/IconRegistry.tsx @@ -17,6 +17,7 @@ import { ChevronsUpDown, CircleAlert, CircleCheck, + CircleExclamationPoint, CircleX, Clock, Code2, @@ -31,7 +32,6 @@ import { FileCode2, FileSpreadsheet, FileText, - Github, GripVertical, History, Info, @@ -110,6 +110,22 @@ function Broom({ size = 24, ...props }: SVGProps & { size?: strin ); } +/** GitHub mark — lucide-react 1.x dropped brand icons (incl. `Github`). */ +function GitHub({ size = 24, ...props }: SVGProps & { size?: string | number }) { + return ( + + + + ); +} + const registry = new Map(); export function registerIcon(name: string, icon: IconEntry): void { @@ -157,6 +173,7 @@ const defaults: Record = { 'clock-rotate-left': History, 'circle-exclamation': CircleAlert, info: Info, + 'circle-exclamation-point': CircleExclamationPoint, 'triangle-exclamation': TriangleAlert, 'chevron-down': ChevronDown, 'chevron-left': ChevronLeft, @@ -221,7 +238,7 @@ const defaults: Record = { compress: Minimize2, 'external-link': ExternalLink, 'square-arrow-out-up-right': SquareArrowOutUpRight, - github: Github, + github: GitHub, monitor: Monitor, }; diff --git a/packages/trueforge-ui/test/atoms/AgentSessionListRow.test.tsx b/packages/trueforge-ui/test/atoms/AgentSessionListRow.test.tsx index ec953963d2..a475901387 100644 --- a/packages/trueforge-ui/test/atoms/AgentSessionListRow.test.tsx +++ b/packages/trueforge-ui/test/atoms/AgentSessionListRow.test.tsx @@ -126,8 +126,10 @@ describe('AgentSessionListRow', () => { expect(container.querySelector('[data-slot="session-status-dot"]')).not.toBeInTheDocument(); }); - it('shows a blinking paused status dot after the title', () => { - const { container } = render(); + it('shows a blinking paused status dot after the title when activity is recent', () => { + const { container } = render( + , + ); const pausedDot = container.querySelector('[data-slot="session-status-dot"]'); expect(pausedDot?.querySelector('.bg-warning-bg')).toBeInTheDocument(); @@ -135,15 +137,24 @@ describe('AgentSessionListRow', () => { expect(screen.getByText('Waiting for input', { selector: '.sr-only' })).toBeInTheDocument(); }); - it('shows a static failure status dot for error and hides cancelled', () => { + it('hides the paused status dot when activity is older than 48 hours', () => { + const { container } = render( + , + ); + + expect(container.querySelector('[data-slot="session-status-dot"]')).not.toBeInTheDocument(); + expect(screen.getByText('Waiting for input', { selector: '.sr-only' })).toBeInTheDocument(); + }); + + it('shows a failure icon for error and hides cancelled', () => { const { container: errorContainer } = render(); - const errorDot = errorContainer.querySelector('[data-slot="session-status-dot"]'); - expect(errorDot?.querySelector('.bg-failure-bg')).toBeInTheDocument(); - expect(errorDot?.querySelector('.motion-safe\\:animate-ping')).not.toBeInTheDocument(); + expect(errorContainer.querySelector('[data-slot="session-status-dot"]')).not.toBeInTheDocument(); + expect(errorContainer.querySelector('[data-slot="session-status-failed"]')).toBeInTheDocument(); expect(screen.getByText('Failed', { selector: '.sr-only' })).toBeInTheDocument(); const { container: cancelledContainer } = render(); expect(cancelledContainer.querySelector('[data-slot="session-status-dot"]')).not.toBeInTheDocument(); + expect(cancelledContainer.querySelector('[data-slot="session-status-failed"]')).not.toBeInTheDocument(); }); it('hides the status dot when last turn is done', () => { diff --git a/packages/trueforge-ui/test/atoms/ThreadListRow.test.tsx b/packages/trueforge-ui/test/atoms/ThreadListRow.test.tsx index ea91a1616a..467ba19cbe 100644 --- a/packages/trueforge-ui/test/atoms/ThreadListRow.test.tsx +++ b/packages/trueforge-ui/test/atoms/ThreadListRow.test.tsx @@ -156,7 +156,7 @@ describe('ThreadListRow', () => { expect(screen.getByRole('tooltip')).toHaveTextContent('18h'); }); - it('replaces the relative age with a paused status dot', () => { + it('replaces the relative age with a paused status dot when activity is recent', () => { const lastMessageAt = new Date(Date.now() - 30 * 60_000); const { container } = render( @@ -177,7 +177,26 @@ describe('ThreadListRow', () => { expect(screen.queryByText('30m')).not.toBeInTheDocument(); }); - it('replaces the relative age with a failure status dot for error', () => { + it('hides the paused status dot and shows relative age when activity is older than 48 hours', () => { + const lastMessageAt = new Date(Date.now() - 49 * 60 * 60_000); + const { container } = render( + + {}} + lastTurnStatus="paused" + lastMessageAt={lastMessageAt} + /> + , + ); + + expect(container.querySelector('[data-slot="session-status-dot"]')).not.toBeInTheDocument(); + expect(screen.queryByText('Waiting for input', { selector: '.sr-only' })).not.toBeInTheDocument(); + expect(screen.getByText('2d')).toBeInTheDocument(); + }); + + it('shows relative age for error with no failure chrome', () => { const lastMessageAt = new Date(Date.now() - 30 * 60_000); const { container } = render( @@ -191,11 +210,9 @@ describe('ThreadListRow', () => { , ); - const errorDot = container.querySelector('[data-slot="session-status-dot"]'); - expect(errorDot?.querySelector('.bg-failure-bg')).toBeInTheDocument(); - expect(errorDot?.querySelector('.motion-safe\\:animate-ping')).not.toBeInTheDocument(); - expect(screen.getByText('Failed', { selector: '.sr-only' })).toBeInTheDocument(); - expect(screen.queryByText('30m')).not.toBeInTheDocument(); + expect(container.querySelector('[data-slot="session-status-dot"]')).not.toBeInTheDocument(); + expect(screen.queryByText('Failed', { selector: '.sr-only' })).not.toBeInTheDocument(); + expect(screen.getByText('30m')).toBeInTheDocument(); }); it('shows a desktop hover tip with the full title and relative age', () => { diff --git a/packages/trueforge-ui/test/atoms/lib/sessionListPoll.test.ts b/packages/trueforge-ui/test/atoms/lib/sessionListPoll.test.ts index 9fdc2989e0..7b04949e30 100644 --- a/packages/trueforge-ui/test/atoms/lib/sessionListPoll.test.ts +++ b/packages/trueforge-ui/test/atoms/lib/sessionListPoll.test.ts @@ -3,18 +3,14 @@ import { describe, expect, it } from 'vitest'; import { mergeSessionListFirstPage, SESSION_LIST_FIRST_PAGE_LIMIT, - SESSION_LIST_PAUSED_POLL_INTERVAL_MS, - SESSION_LIST_RUNNING_POLL_INTERVAL_MS, + SESSION_LIST_POLL_INTERVAL_MS, sessionListPollIntervalMs, } from '@/atoms/lib/sessionListPoll.js'; describe('sessionListPollIntervalMs', () => { - it('returns the running cadence when any status is running', () => { - expect(sessionListPollIntervalMs(['paused', 'running', 'done'])).toBe(SESSION_LIST_RUNNING_POLL_INTERVAL_MS); - }); - - it('returns the paused cadence when statuses are only paused', () => { - expect(sessionListPollIntervalMs(['paused', null, 'done'])).toBe(SESSION_LIST_PAUSED_POLL_INTERVAL_MS); + it('polls while any status is running or paused', () => { + expect(sessionListPollIntervalMs(['paused', 'running', 'done'])).toBe(SESSION_LIST_POLL_INTERVAL_MS); + expect(sessionListPollIntervalMs(['paused', null, 'done'])).toBe(SESSION_LIST_POLL_INTERVAL_MS); }); it('returns null when nothing needs polling', () => { diff --git a/packages/trueforge-ui/test/atoms/lib/threadListMeta.test.ts b/packages/trueforge-ui/test/atoms/lib/threadListMeta.test.ts index c08e64fa41..78915ce4fd 100644 --- a/packages/trueforge-ui/test/atoms/lib/threadListMeta.test.ts +++ b/packages/trueforge-ui/test/atoms/lib/threadListMeta.test.ts @@ -6,6 +6,7 @@ import { isRunningTurnStatus, lastTurnStatusDotClass, lastTurnStatusLabel, + PAUSED_STATUS_DOT_MAX_AGE_MS, readThreadAgentName, readThreadIsMutable, readThreadLastTurnStatus, @@ -43,13 +44,30 @@ describe('readThreadLastTurnStatus', () => { }); describe('lastTurnStatusDotClass', () => { - it('maps paused and error; hides running, cancelled, and done', () => { - expect(lastTurnStatusDotClass('paused')).toBe('bg-warning-bg'); - expect(lastTurnStatusDotClass('error')).toBe('bg-failure-bg'); - expect(lastTurnStatusDotClass('cancelled')).toBeUndefined(); - expect(lastTurnStatusDotClass('running')).toBeUndefined(); - expect(lastTurnStatusDotClass('done')).toBeUndefined(); - expect(lastTurnStatusDotClass(null)).toBeUndefined(); + const now = new Date('2026-11-16T12:00:00.000Z'); + + it('maps recent paused; hides stale paused, error, running, cancelled, and done', () => { + expect( + lastTurnStatusDotClass({ + status: 'paused', + activityAt: new Date(now.getTime() - PAUSED_STATUS_DOT_MAX_AGE_MS), + now, + }), + ).toBe('bg-warning-bg'); + expect( + lastTurnStatusDotClass({ + status: 'paused', + activityAt: new Date(now.getTime() - PAUSED_STATUS_DOT_MAX_AGE_MS - 1), + now, + }), + ).toBeUndefined(); + expect(lastTurnStatusDotClass({ status: 'paused', now })).toBe('bg-warning-bg'); + expect(lastTurnStatusDotClass({ status: 'paused', activityAt: new Date('invalid'), now })).toBe('bg-warning-bg'); + expect(lastTurnStatusDotClass({ status: 'error', now })).toBeUndefined(); + expect(lastTurnStatusDotClass({ status: 'cancelled', now })).toBeUndefined(); + expect(lastTurnStatusDotClass({ status: 'running', now })).toBeUndefined(); + expect(lastTurnStatusDotClass({ status: 'done', now })).toBeUndefined(); + expect(lastTurnStatusDotClass({ status: null, now })).toBeUndefined(); }); }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 45cb250d62..60b2bd1b86 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -454,8 +454,8 @@ importers: specifier: ^2.1.1 version: 2.1.1 lucide-react: - specifier: ^0.562.0 - version: 0.562.0(react@19.3.0) + specifier: ^1.73.0 + version: 1.73.0(@types/react@19.3.0)(react@19.3.0) monaco-editor: specifier: ^0.57.0 version: 0.57.0 @@ -6228,6 +6228,15 @@ packages: peerDependencies: react: ^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0 + lucide-react@1.73.0: + resolution: {integrity: sha512-fVOzGviL9mTfHenG1PbCfIceavyGlnpYNSYr+aGZHLRymAJ7DTP6KHuqt0uBkCKAoenr1UVkwSbDIYt2xIesEQ==} + peerDependencies: + '@types/react': '*' + react: ^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0 + peerDependenciesMeta: + '@types/react': + optional: true + luxon@3.7.2: resolution: {integrity: sha512-vtEhXh/gNjI9Yg1u4jX/0YVPMvxzHuGgCm6tC5kZyb08yjGWGnqAjGJvcXbqQR2P3MyMEFnRbpcdFS6PBcLqew==} engines: {node: '>=12'} @@ -14330,6 +14339,12 @@ snapshots: dependencies: react: 19.3.0 + lucide-react@1.73.0(@types/react@19.3.0)(react@19.3.0): + dependencies: + react: 19.3.0 + optionalDependencies: + '@types/react': 19.3.0 + luxon@3.7.2: {} lz-string@1.5.0: {} From 06cdd9d33feea71c0a3faa8748c3d6a315f33e03 Mon Sep 17 00:00:00 2001 From: Harshil Vasoya Date: Mon, 16 Nov 2026 14:12:43 +0530 Subject: [PATCH 2/5] fix: enhance session polling and activity tracking for agent sessions --- .changeset/session-status-indicators.md | 2 +- .../src/atoms/agent-details/AgentSessions.tsx | 10 ++----- .../src/atoms/lib/sessionListPoll.ts | 19 ++++++++++++ .../src/atoms/lib/threadListMeta.ts | 30 +++++++++++++++++++ .../src/containers/ThreadListContainer.tsx | 19 ++++++++---- .../hooks/useSyncThreadListLastTurnStatus.ts | 20 +++++++++---- .../test/atoms/lib/sessionListPoll.test.ts | 26 ++++++++++++++++ .../test/atoms/lib/threadListMeta.test.ts | 28 +++++++++++++++++ 8 files changed, 135 insertions(+), 19 deletions(-) diff --git a/.changeset/session-status-indicators.md b/.changeset/session-status-indicators.md index 9753d69804..4898d6d354 100644 --- a/.changeset/session-status-indicators.md +++ b/.changeset/session-status-indicators.md @@ -2,4 +2,4 @@ '@truefoundry/trueforge-ui': patch --- -Hide paused status dots after 48 hours of inactivity, and show failed runs with a circle-xmark icon in the agent session list only (no failure chrome in chat history). Session lists poll running and paused rows every 5 seconds. +Hide paused status dots after 48 hours of inactivity, and show failed runs with a circle-xmark icon in the agent session list only (no failure chrome in chat history). Session lists poll running and paused rows every 5 seconds, and a poll that sees a new pause also refreshes the activity time so the dot is not stuck hidden. diff --git a/packages/trueforge-ui/src/atoms/agent-details/AgentSessions.tsx b/packages/trueforge-ui/src/atoms/agent-details/AgentSessions.tsx index e3de65fe93..73ff771a56 100644 --- a/packages/trueforge-ui/src/atoms/agent-details/AgentSessions.tsx +++ b/packages/trueforge-ui/src/atoms/agent-details/AgentSessions.tsx @@ -25,6 +25,7 @@ import { EmptyScreen } from '../EmptyScreen.js'; import { cn } from '../lib/cn.js'; import { sessionIsCreateAgent } from '../lib/sessionCreateAgent.js'; import { + mergePolledSessionRow, mergeSessionListFirstPage, SESSION_LIST_FIRST_PAGE_LIMIT, sessionListPollIntervalMs, @@ -178,14 +179,7 @@ export function AgentSessions({ mergeSessionListFirstPage({ current, firstPage: page.data, - mergeItem: (prev, next) => { - const prevDetails = prev.lastTurnDetails; - const nextDetails = next.lastTurnDetails; - if (prevDetails?.id === nextDetails?.id && prevDetails?.state.status === nextDetails?.state.status) { - return prev; - } - return { ...prev, lastTurnDetails: nextDetails }; - }, + mergeItem: mergePolledSessionRow, }), ); } catch { diff --git a/packages/trueforge-ui/src/atoms/lib/sessionListPoll.ts b/packages/trueforge-ui/src/atoms/lib/sessionListPoll.ts index 38a9ba255c..c7f3053653 100644 --- a/packages/trueforge-ui/src/atoms/lib/sessionListPoll.ts +++ b/packages/trueforge-ui/src/atoms/lib/sessionListPoll.ts @@ -14,6 +14,25 @@ export function sessionListPollIntervalMs(statuses: ReadonlyArray( + prev: T, + next: T, +): T { + const prevDetails = prev.lastTurnDetails; + const nextDetails = next.lastTurnDetails; + const sameTurn = prevDetails?.id === nextDetails?.id && prevDetails?.state.status === nextDetails?.state.status; + if (sameTurn && prev.lastActivityAt === next.lastActivityAt) return prev; + if (sameTurn) return { ...prev, lastActivityAt: next.lastActivityAt }; + return { ...prev, lastActivityAt: next.lastActivityAt, lastTurnDetails: nextDetails }; +} + /** * Patch items that appear on a first-page poll into the full loaded list by id. * Later pages from load-more are left in place; unknown first-page ids are ignored. diff --git a/packages/trueforge-ui/src/atoms/lib/threadListMeta.ts b/packages/trueforge-ui/src/atoms/lib/threadListMeta.ts index 27bd9f7ca1..1c96224ff7 100644 --- a/packages/trueforge-ui/src/atoms/lib/threadListMeta.ts +++ b/packages/trueforge-ui/src/atoms/lib/threadListMeta.ts @@ -122,6 +122,32 @@ export function readThreadIsMutable(custom: unknown): boolean | undefined { return typeof value === 'boolean' ? value : undefined; } +/** Activity time stamped by the status poll. Newer than `lastMessageAt` after a fresh pause. */ +export function readThreadLastActivityAt(custom: unknown): Date | undefined { + if (custom == null || typeof custom !== 'object') return undefined; + if (!('lastActivityAt' in custom)) return undefined; + const value = Reflect.get(custom, 'lastActivityAt'); + if (typeof value !== 'string') return undefined; + const date = new Date(value); + return Number.isNaN(date.getTime()) ? undefined : date; +} + +/** True when `nextIso` is a valid time strictly after `prev`. Missing `prev` counts as newer. */ +export function isNewerActivityAt(nextIso: string, prev: Date | undefined): boolean { + const next = new Date(nextIso); + if (Number.isNaN(next.getTime())) return false; + if (prev == null || Number.isNaN(prev.getTime())) return true; + return next.getTime() > prev.getTime(); +} + +/** Later of the list payload time and a poll stamp. */ +export function laterActivityAt(left: Date | undefined, right: Date | undefined): Date | undefined { + if (left == null || Number.isNaN(left.getTime())) + return right != null && !Number.isNaN(right.getTime()) ? right : undefined; + if (right == null || Number.isNaN(right.getTime())) return left; + return right.getTime() > left.getTime() ? right : left; +} + /** Last-turn status stamped on thread-list custom by `sessionToThreadMetadata`. */ export function readThreadLastTurnStatus(custom: unknown): TurnStatus | undefined { if (custom == null || typeof custom !== 'object') return undefined; @@ -134,6 +160,7 @@ export function readThreadLastTurnStatus(custom: unknown): TurnStatus | undefine export function threadCustomWithLastTurnStatus( custom: unknown, status: TurnStatus | null | undefined, + activityAt?: string, ): Record { const base = custom != null && typeof custom === 'object' && !Array.isArray(custom) @@ -143,6 +170,9 @@ export function threadCustomWithLastTurnStatus( if (status != null) { base.lastTurnStatus = status; } + if (activityAt != null) { + base.lastActivityAt = activityAt; + } return base; } diff --git a/packages/trueforge-ui/src/containers/ThreadListContainer.tsx b/packages/trueforge-ui/src/containers/ThreadListContainer.tsx index cb5977b3a9..796cc0b747 100644 --- a/packages/trueforge-ui/src/containers/ThreadListContainer.tsx +++ b/packages/trueforge-ui/src/containers/ThreadListContainer.tsx @@ -21,8 +21,11 @@ import { useCompactLayout } from '../atoms/lib/CompactLayoutContext.js'; import { SESSION_LIST_FIRST_PAGE_LIMIT, sessionListPollIntervalMs } from '../atoms/lib/sessionListPoll.js'; import { canReuseMutableShell, + isNewerActivityAt, + laterActivityAt, readThreadAgentName, readThreadIsMutable, + readThreadLastActivityAt, readThreadLastTurnStatus, threadCustomWithLastTurnStatus, threadListIndicesByRecency, @@ -214,6 +217,7 @@ function ThreadListItemRow({ const mainThreadId = useAuiState(s => s.threads.mainThreadId); const agentName = readThreadAgentName(custom); const lastTurnStatus = readThreadLastTurnStatus(custom); + const activityAt = laterActivityAt(lastMessageAt, readThreadLastActivityAt(custom)); const showRename = canRenameSession && remoteId != null; const showDelete = canDeleteSession && remoteId != null; const showActions = showRename || showDelete; @@ -288,7 +292,7 @@ function ThreadListItemRow({ active={id === mainThreadId && !sidebarNavOpen} agentName={agentName} {...(lastTurnStatus == null ? {} : { lastTurnStatus })} - lastMessageAt={lastMessageAt} + {...(activityAt == null ? {} : { lastMessageAt: activityAt })} onSelect={() => { track( AnalyticsEvents.Session.SELECTED, @@ -546,7 +550,10 @@ export function ThreadListContainer({ onThreadOpen, variant = 'default' }: Threa }); const statusByRemoteId = new Map( - page.data.map(session => [session.id, session.lastTurnDetails?.state.status] as const), + page.data.map( + session => + [session.id, { status: session.lastTurnDetails?.state.status, updatedAt: session.updatedAt }] as const, + ), ); const threadsState = auiRef.current.threads().getState(); const mainThreadId = threadsState.mainThreadId; @@ -557,13 +564,15 @@ export function ThreadListContainer({ onThreadOpen, variant = 'default' }: Threa continue; } if (item.remoteId == null || !statusByRemoteId.has(item.remoteId)) continue; - const nextStatus = statusByRemoteId.get(item.remoteId); + const polled = statusByRemoteId.get(item.remoteId); + if (polled == null) continue; const prevStatus = readThreadLastTurnStatus(item.custom); - if (nextStatus === prevStatus) continue; + const prevActivity = readThreadLastActivityAt(item.custom) ?? item.lastMessageAt; + if (polled.status === prevStatus && !isNewerActivityAt(polled.updatedAt, prevActivity)) continue; void auiRef.current .threads() .item({ id: item.id }) - .updateCustom(threadCustomWithLastTurnStatus(item.custom, nextStatus ?? null)); + .updateCustom(threadCustomWithLastTurnStatus(item.custom, polled.status ?? null, polled.updatedAt)); } } catch { // Keep showing the last known status on transient poll failures. diff --git a/packages/trueforge-ui/src/hooks/useSyncThreadListLastTurnStatus.ts b/packages/trueforge-ui/src/hooks/useSyncThreadListLastTurnStatus.ts index 156f9bc8ca..98584041e1 100644 --- a/packages/trueforge-ui/src/hooks/useSyncThreadListLastTurnStatus.ts +++ b/packages/trueforge-ui/src/hooks/useSyncThreadListLastTurnStatus.ts @@ -4,7 +4,12 @@ import { useThreadIsRunning } from '@assistant-ui/core/react'; import { useEffect, useRef } from 'react'; import { useAui, useAuiState } from '../assistant-ui.js'; -import { readThreadLastTurnStatus, threadCustomWithLastTurnStatus } from '../atoms/lib/threadListMeta.js'; +import { + isNewerActivityAt, + readThreadLastActivityAt, + readThreadLastTurnStatus, + threadCustomWithLastTurnStatus, +} from '../atoms/lib/threadListMeta.js'; import { useOptionalServer } from '../server/ServerContext.js'; /** @@ -18,6 +23,7 @@ export function useSyncThreadListLastTurnStatus(): void { const server = useOptionalServer(); const aui = useAui(); const remoteId = useAuiState(s => s.threadListItem.remoteId); + const lastMessageAt = useAuiState(s => s.threadListItem.lastMessageAt); const isRunning = useThreadIsRunning(); const wasRunningRef = useRef(false); const prevRemoteIdRef = useRef(remoteId); @@ -26,7 +32,7 @@ export function useSyncThreadListLastTurnStatus(): void { if (!isRunning || remoteId == null) return; const custom = aui.threadListItem().getState().custom; if (readThreadLastTurnStatus(custom) === 'running') return; - void aui.threadListItem().updateCustom(threadCustomWithLastTurnStatus(custom, 'running')); + void aui.threadListItem().updateCustom(threadCustomWithLastTurnStatus(custom, 'running', new Date().toISOString())); }, [aui, isRunning, remoteId]); useEffect(() => { @@ -56,13 +62,17 @@ export function useSyncThreadListLastTurnStatus(): void { if (cancelled) return; const nextStatus = session.lastTurnDetails?.state.status ?? null; const latestCustom = aui.threadListItem().getState().custom; - if (readThreadLastTurnStatus(latestCustom) === nextStatus) return; - return aui.threadListItem().updateCustom(threadCustomWithLastTurnStatus(latestCustom, nextStatus)); + const statusSame = (readThreadLastTurnStatus(latestCustom) ?? null) === nextStatus; + const prevActivity = readThreadLastActivityAt(latestCustom) ?? lastMessageAt; + if (statusSame && !isNewerActivityAt(session.updatedAt, prevActivity)) return; + return aui + .threadListItem() + .updateCustom(threadCustomWithLastTurnStatus(latestCustom, nextStatus, session.updatedAt)); }) .catch(() => undefined); return () => { cancelled = true; }; - }, [aui, isRunning, remoteId, server]); + }, [aui, isRunning, lastMessageAt, remoteId, server]); } diff --git a/packages/trueforge-ui/test/atoms/lib/sessionListPoll.test.ts b/packages/trueforge-ui/test/atoms/lib/sessionListPoll.test.ts index 7b04949e30..04a79e8908 100644 --- a/packages/trueforge-ui/test/atoms/lib/sessionListPoll.test.ts +++ b/packages/trueforge-ui/test/atoms/lib/sessionListPoll.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from 'vitest'; import { + mergePolledSessionRow, mergeSessionListFirstPage, SESSION_LIST_FIRST_PAGE_LIMIT, SESSION_LIST_POLL_INTERVAL_MS, @@ -19,6 +20,31 @@ describe('sessionListPollIntervalMs', () => { }); }); +describe('mergePolledSessionRow', () => { + const paused = { id: 'turn-1', state: { status: 'paused' } }; + + it('keeps the row when the turn and activity time are unchanged', () => { + const prev = { id: 'a', lastActivityAt: '2026-11-01T00:00:00.000Z', lastTurnDetails: paused }; + expect(mergePolledSessionRow(prev, { ...prev })).toBe(prev); + }); + + it('refreshes activity time when a paused turn is touched again', () => { + const prev = { id: 'a', lastActivityAt: '2026-11-01T00:00:00.000Z', lastTurnDetails: paused }; + const next = { ...prev, lastActivityAt: '2026-11-16T00:00:00.000Z' }; + expect(mergePolledSessionRow(prev, next)).toEqual(next); + }); + + it('copies status and activity time together', () => { + const prev = { + id: 'a', + lastActivityAt: '2026-11-01T00:00:00.000Z', + lastTurnDetails: { id: 'turn-1', state: { status: 'running' } }, + }; + const next = { ...prev, lastActivityAt: '2026-11-16T00:00:00.000Z', lastTurnDetails: paused }; + expect(mergePolledSessionRow(prev, next)).toEqual(next); + }); +}); + describe('mergeSessionListFirstPage', () => { it('patches matching ids and leaves later pages untouched', () => { const current = [ diff --git a/packages/trueforge-ui/test/atoms/lib/threadListMeta.test.ts b/packages/trueforge-ui/test/atoms/lib/threadListMeta.test.ts index 78915ce4fd..729bcf9ffe 100644 --- a/packages/trueforge-ui/test/atoms/lib/threadListMeta.test.ts +++ b/packages/trueforge-ui/test/atoms/lib/threadListMeta.test.ts @@ -3,12 +3,15 @@ import { describe, expect, it } from 'vitest'; import { canReuseMutableShell, formatRelativeShort, + isNewerActivityAt, isRunningTurnStatus, lastTurnStatusDotClass, lastTurnStatusLabel, + laterActivityAt, PAUSED_STATUS_DOT_MAX_AGE_MS, readThreadAgentName, readThreadIsMutable, + readThreadLastActivityAt, readThreadLastTurnStatus, threadCustomWithLastTurnStatus, threadListIndicesByRecency, @@ -98,6 +101,11 @@ describe('threadCustomWithLastTurnStatus', () => { }); expect(custom).toEqual({ isMutable: true, lastTurnStatus: 'running' }); expect(threadCustomWithLastTurnStatus(custom, null)).toEqual({ isMutable: true }); + expect(threadCustomWithLastTurnStatus(custom, 'paused', '2026-11-16T00:00:00.000Z')).toEqual({ + isMutable: true, + lastTurnStatus: 'paused', + lastActivityAt: '2026-11-16T00:00:00.000Z', + }); expect(threadCustomWithLastTurnStatus(undefined, 'error')).toEqual({ lastTurnStatus: 'error' }); }); @@ -107,6 +115,26 @@ describe('threadCustomWithLastTurnStatus', () => { }); }); +describe('readThreadLastActivityAt', () => { + it('reads a valid poll stamp and ignores anything else', () => { + expect(readThreadLastActivityAt({ lastActivityAt: '2026-11-16T00:00:00.000Z' })?.toISOString()).toBe( + '2026-11-16T00:00:00.000Z', + ); + expect(readThreadLastActivityAt({ lastActivityAt: 'nope' })).toBeUndefined(); + expect(readThreadLastActivityAt({})).toBeUndefined(); + }); + + it('treats a later stamp as newer and prefers it over the list payload', () => { + const older = new Date('2026-11-01T00:00:00.000Z'); + const newer = new Date('2026-11-16T00:00:00.000Z'); + expect(isNewerActivityAt('2026-11-16T00:00:00.000Z', older)).toBe(true); + expect(isNewerActivityAt('2026-11-01T00:00:00.000Z', newer)).toBe(false); + expect(isNewerActivityAt('nope', older)).toBe(false); + expect(laterActivityAt(older, newer)).toBe(newer); + expect(laterActivityAt(newer, undefined)).toBe(newer); + }); +}); + describe('threadListItemIsMutable', () => { it('prefers custom.isMutable over agentName presence', () => { expect(readThreadIsMutable({ isMutable: false })).toBe(false); From 74424a51e1f23091469fd7788a51b2ca77abed59 Mon Sep 17 00:00:00 2001 From: Harshil Vasoya Date: Mon, 16 Nov 2026 14:49:52 +0530 Subject: [PATCH 3/5] fix: improve handling of lastMessageAt during session updates in useSyncThreadListLastTurnStatus --- .../hooks/useSyncThreadListLastTurnStatus.ts | 8 ++- .../useSyncThreadListLastTurnStatus.test.ts | 60 +++++++++++++++++-- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/packages/trueforge-ui/src/hooks/useSyncThreadListLastTurnStatus.ts b/packages/trueforge-ui/src/hooks/useSyncThreadListLastTurnStatus.ts index 98584041e1..2d12c028c7 100644 --- a/packages/trueforge-ui/src/hooks/useSyncThreadListLastTurnStatus.ts +++ b/packages/trueforge-ui/src/hooks/useSyncThreadListLastTurnStatus.ts @@ -27,6 +27,10 @@ export function useSyncThreadListLastTurnStatus(): void { const isRunning = useThreadIsRunning(); const wasRunningRef = useRef(false); const prevRemoteIdRef = useRef(remoteId); + // Read inside the finished-turn effect. A dep would rerun it after isRunning + // flips false, cancel the in-flight getSession, and skip the paused/error stamp. + const lastMessageAtRef = useRef(lastMessageAt); + lastMessageAtRef.current = lastMessageAt; useEffect(() => { if (!isRunning || remoteId == null) return; @@ -63,7 +67,7 @@ export function useSyncThreadListLastTurnStatus(): void { const nextStatus = session.lastTurnDetails?.state.status ?? null; const latestCustom = aui.threadListItem().getState().custom; const statusSame = (readThreadLastTurnStatus(latestCustom) ?? null) === nextStatus; - const prevActivity = readThreadLastActivityAt(latestCustom) ?? lastMessageAt; + const prevActivity = readThreadLastActivityAt(latestCustom) ?? lastMessageAtRef.current; if (statusSame && !isNewerActivityAt(session.updatedAt, prevActivity)) return; return aui .threadListItem() @@ -74,5 +78,5 @@ export function useSyncThreadListLastTurnStatus(): void { return () => { cancelled = true; }; - }, [aui, isRunning, lastMessageAt, remoteId, server]); + }, [aui, isRunning, remoteId, server]); } diff --git a/packages/trueforge-ui/test/hooks/useSyncThreadListLastTurnStatus.test.ts b/packages/trueforge-ui/test/hooks/useSyncThreadListLastTurnStatus.test.ts index 07c8918431..72f5a05537 100644 --- a/packages/trueforge-ui/test/hooks/useSyncThreadListLastTurnStatus.test.ts +++ b/packages/trueforge-ui/test/hooks/useSyncThreadListLastTurnStatus.test.ts @@ -8,15 +8,16 @@ const updateCustom = vi.fn(async () => undefined); const getState = vi.fn(() => ({ custom: { isMutable: true } as Record })); const getSession = vi.fn(); const useOptionalServer = vi.fn((): { getSession: typeof getSession } | null => null); +const aui = { + threadListItem: () => ({ updateCustom, getState }), +}; vi.mock('@assistant-ui/core/react', () => ({ useThreadIsRunning: () => useThreadIsRunning(), })); vi.mock('@/assistant-ui.js', () => ({ - useAui: () => ({ - threadListItem: () => ({ updateCustom, getState }), - }), + useAui: () => aui, useAuiState: (selector: (state: unknown) => unknown) => useAuiState(selector), })); @@ -45,8 +46,13 @@ describe('useSyncThreadListLastTurnStatus', () => { renderHook(() => useSyncThreadListLastTurnStatus()); await waitFor(() => { - expect(updateCustom).toHaveBeenCalledWith({ isMutable: true, lastTurnStatus: 'running' }); + expect(updateCustom).toHaveBeenCalledWith( + expect.objectContaining({ isMutable: true, lastTurnStatus: 'running' }), + ); }); + const stamped = updateCustom.mock.calls[0]?.[0] as { lastActivityAt?: string }; + expect(stamped.lastActivityAt).toEqual(expect.any(String)); + expect(Number.isNaN(new Date(stamped.lastActivityAt ?? '').getTime())).toBe(false); }); it('does not stamp running before the thread has a remote session id', async () => { @@ -137,4 +143,50 @@ describe('useSyncThreadListLastTurnStatus', () => { expect(updateCustom).not.toHaveBeenCalled(); expect(getSession).not.toHaveBeenCalled(); }); + + it('still stamps the finished status when lastMessageAt changes while getSession is in flight', async () => { + getState.mockReturnValue({ custom: { isMutable: true, lastTurnStatus: 'running' } }); + let resolveSession: (session: { + id: string; + updatedAt: string; + lastTurnDetails: { id: string; state: { status: 'paused' } }; + }) => void = () => undefined; + getSession.mockReturnValue( + new Promise(resolve => { + resolveSession = resolve; + }), + ); + + useThreadIsRunning.mockReturnValue(true); + const { rerender } = renderHook(() => useSyncThreadListLastTurnStatus()); + updateCustom.mockClear(); + + useThreadIsRunning.mockReturnValue(false); + rerender(); + + await waitFor(() => { + expect(getSession).toHaveBeenCalledTimes(1); + }); + + useAuiState.mockImplementation((selector: (state: unknown) => unknown) => + selector({ + threadListItem: { remoteId: 'sess-1', lastMessageAt: new Date('2026-11-16T12:00:00.000Z') }, + }), + ); + rerender(); + + resolveSession({ + id: 'sess-1', + updatedAt: '2026-11-16T12:00:01.000Z', + lastTurnDetails: { id: 'turn-1', state: { status: 'paused' } }, + }); + + await waitFor(() => { + expect(updateCustom).toHaveBeenCalledWith({ + isMutable: true, + lastTurnStatus: 'paused', + lastActivityAt: '2026-11-16T12:00:01.000Z', + }); + }); + }); }); From 13247a4d17e6c74b53831e3a16ef92f0bc1f4fc3 Mon Sep 17 00:00:00 2001 From: Harshil Vasoya Date: Mon, 16 Nov 2026 14:53:24 +0530 Subject: [PATCH 4/5] fix: type the running-stamp assertion so UI test typecheck passes Co-authored-by: Cursor --- .../hooks/useSyncThreadListLastTurnStatus.test.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/trueforge-ui/test/hooks/useSyncThreadListLastTurnStatus.test.ts b/packages/trueforge-ui/test/hooks/useSyncThreadListLastTurnStatus.test.ts index 72f5a05537..ab67fbbcbf 100644 --- a/packages/trueforge-ui/test/hooks/useSyncThreadListLastTurnStatus.test.ts +++ b/packages/trueforge-ui/test/hooks/useSyncThreadListLastTurnStatus.test.ts @@ -4,7 +4,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'; const useThreadIsRunning = vi.fn(() => false); const useAuiState = vi.fn(); -const updateCustom = vi.fn(async () => undefined); +const updateCustom = vi.fn(async (_custom: Record) => undefined); const getState = vi.fn(() => ({ custom: { isMutable: true } as Record })); const getSession = vi.fn(); const useOptionalServer = vi.fn((): { getSession: typeof getSession } | null => null); @@ -50,9 +50,12 @@ describe('useSyncThreadListLastTurnStatus', () => { expect.objectContaining({ isMutable: true, lastTurnStatus: 'running' }), ); }); - const stamped = updateCustom.mock.calls[0]?.[0] as { lastActivityAt?: string }; - expect(stamped.lastActivityAt).toEqual(expect.any(String)); - expect(Number.isNaN(new Date(stamped.lastActivityAt ?? '').getTime())).toBe(false); + const activityAt = updateCustom.mock.calls[0]?.[0]?.lastActivityAt; + expect(typeof activityAt).toBe('string'); + if (typeof activityAt !== 'string') { + throw new Error('expected lastActivityAt string'); + } + expect(Number.isNaN(new Date(activityAt).getTime())).toBe(false); }); it('does not stamp running before the thread has a remote session id', async () => { From f0d3551aad82ba6c0e2ab01963cf8951035720f2 Mon Sep 17 00:00:00 2001 From: Harshil Vasoya Date: Mon, 16 Nov 2026 14:58:59 +0530 Subject: [PATCH 5/5] fix: expect activity time on polled chat-history status writes Co-authored-by: Cursor --- .../trueforge-ui/test/containers/ThreadListContainer.test.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/trueforge-ui/test/containers/ThreadListContainer.test.tsx b/packages/trueforge-ui/test/containers/ThreadListContainer.test.tsx index 88e94a7213..7dbf969625 100644 --- a/packages/trueforge-ui/test/containers/ThreadListContainer.test.tsx +++ b/packages/trueforge-ui/test/containers/ThreadListContainer.test.tsx @@ -464,9 +464,11 @@ describe('ThreadListContainer', () => { await waitFor(() => { expect(onUpdateCustom).toHaveBeenCalledWith('thread-other', { lastTurnStatus: 'paused', + lastActivityAt: '2026-01-01T00:00:00.000Z', }); expect(onUpdateCustom).toHaveBeenCalledWith('thread-main', { lastTurnStatus: 'done', + lastActivityAt: '2026-01-01T00:00:00.000Z', }); }); });