Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/session-status-indicators.md
Original file line number Diff line number Diff line change
@@ -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, and a poll that sees a new pause also refreshes the activity time so the dot is not stuck hidden.
2 changes: 1 addition & 1 deletion packages/trueforge-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 8 additions & 4 deletions packages/trueforge-ui/src/atoms/ThreadListRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -124,7 +128,7 @@ export function ThreadListRow({
<span className={cn('truncate text-sm font-normal text-text-primary', running && 'aui-text-shimmer')}>
{title}
</span>
{/* 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 ? (
<span data-slot="session-status-dot" className="shrink-0 md:hidden">
<StatusDot className="size-1.5" colorClassName={statusDotClass} pulse={paused} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -78,6 +79,10 @@ export function AgentSessionListRow({
<span data-slot="session-status-dot" className="shrink-0">
<StatusDot className="size-1.5" colorClassName={statusDotClass} pulse={paused} />
</span>
) : failed ? (
<span data-slot="session-status-failed" className="shrink-0 text-failure-bg" aria-hidden>
<Icon name="circle-exclamation-point" className="size-3.5" />
</span>
) : null}
{statusLabel != null ? <span className="sr-only">{statusLabel}</span> : null}
{scheduleId != null ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
37 changes: 24 additions & 13 deletions packages/trueforge-ui/src/atoms/lib/sessionListPoll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,34 @@ 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<TurnStatus | undefined | null>): 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;
}

type PolledTurn = { id: string; state: { status: string } };

/**
* Apply a first-page poll onto one row.
* Status-only patches used to leave `lastActivityAt` at the original payload, so a
* new pause on a row older than 48 hours stayed hidden.
*/
export function mergePolledSessionRow<T extends { lastActivityAt: string; lastTurnDetails?: PolledTurn | null }>(
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 };
}

/**
Expand Down
59 changes: 55 additions & 4 deletions packages/trueforge-ui/src/atoms/lib/threadListMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Comment thread
harshil-2096 marked this conversation as resolved.
Resolved
return 'bg-warning-bg';
case 'error':
return 'bg-failure-bg';
}
default:
return undefined;
}
Expand Down Expand Up @@ -101,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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helper takes two positional dates

Low Severity

New helper laterActivityAt takes two positional Date | undefined arguments. Same-type positional parameters are easy to swap, and on equal timestamps the function already prefers left. Callers should pass a single options object instead.

Fix in Cursor Fix in Web

Triggered by project rule: TrueForge review rules

Reviewed by Cursor Bugbot for commit 6f5c85e. Configure here.


/** 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;
Expand All @@ -113,6 +160,7 @@ export function readThreadLastTurnStatus(custom: unknown): TurnStatus | undefine
export function threadCustomWithLastTurnStatus(
custom: unknown,
status: TurnStatus | null | undefined,
activityAt?: string,
): Record<string, unknown> {
const base =
custom != null && typeof custom === 'object' && !Array.isArray(custom)
Expand All @@ -122,6 +170,9 @@ export function threadCustomWithLastTurnStatus(
if (status != null) {
base.lastTurnStatus = status;
}
if (activityAt != null) {
base.lastActivityAt = activityAt;
}
return base;
}

Expand Down
19 changes: 14 additions & 5 deletions packages/trueforge-ui/src/containers/ThreadListContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -216,6 +219,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;
Expand Down Expand Up @@ -290,7 +294,7 @@ function ThreadListItemRow({
active={id === mainThreadId && !sidebarNavOpen}
agentName={agentName}
{...(lastTurnStatus == null ? {} : { lastTurnStatus })}
lastMessageAt={lastMessageAt}
{...(activityAt == null ? {} : { lastMessageAt: activityAt })}
onSelect={() => {
track(
AnalyticsEvents.Session.SELECTED,
Expand Down Expand Up @@ -572,7 +576,10 @@ export function ThreadListContainer({
});

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;
Expand All @@ -583,13 +590,15 @@ export function ThreadListContainer({
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -18,15 +23,20 @@ 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);
// 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;
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(() => {
Expand Down Expand Up @@ -56,8 +66,12 @@ 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) ?? lastMessageAtRef.current;
if (statusSame && !isNewerActivityAt(session.updatedAt, prevActivity)) return;
return aui
.threadListItem()
.updateCustom(threadCustomWithLastTurnStatus(latestCustom, nextStatus, session.updatedAt));
})
.catch(() => undefined);

Expand Down
21 changes: 19 additions & 2 deletions packages/trueforge-ui/src/icons/IconRegistry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ChevronsUpDown,
CircleAlert,
CircleCheck,
CircleExclamationPoint,
CircleX,
Clock,
Code2,
Expand All @@ -31,7 +32,6 @@ import {
FileCode2,
FileSpreadsheet,
FileText,
Github,
GripVertical,
History,
Info,
Expand Down Expand Up @@ -110,6 +110,22 @@ function Broom({ size = 24, ...props }: SVGProps<SVGSVGElement> & { size?: strin
);
}

/** GitHub mark — lucide-react 1.x dropped brand icons (incl. `Github`). */
function GitHub({ size = 24, ...props }: SVGProps<SVGSVGElement> & { size?: string | number }) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width={size}
height={size}
viewBox="0 0 24 24"
fill="currentColor"
{...props}
>
<path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12" />
</svg>
);
}

const registry = new Map<string, IconEntry>();

export function registerIcon(name: string, icon: IconEntry): void {
Expand Down Expand Up @@ -157,6 +173,7 @@ const defaults: Record<string, IconEntry> = {
'clock-rotate-left': History,
'circle-exclamation': CircleAlert,
info: Info,
'circle-exclamation-point': CircleExclamationPoint,
'triangle-exclamation': TriangleAlert,
'chevron-down': ChevronDown,
'chevron-left': ChevronLeft,
Expand Down Expand Up @@ -221,7 +238,7 @@ const defaults: Record<string, IconEntry> = {
compress: Minimize2,
'external-link': ExternalLink,
'square-arrow-out-up-right': SquareArrowOutUpRight,
github: Github,
github: GitHub,
monitor: Monitor,
};

Expand Down
Loading
Loading