Skip to content

Commit fbf9048

Browse files
authored
Merge branch 'main' into sd/agents-spending-fix
2 parents 5506371 + 7e6dd43 commit fbf9048

27 files changed

Lines changed: 550 additions & 100 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@truefoundry/trueforge': patch
3+
---
4+
5+
Service-key `assume-user` can list and create turns in TrueFoundry mode without a caller token.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@truefoundry/trueforge-ui': patch
3+
---
4+
5+
Fix the session Context Usage metric, which summed every turn's token spend and so always matched the Tokens tile and could never fall after compaction. Context is now read as a snapshot from the last root model call of each turn.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@truefoundry/trueforge-ui': patch
3+
---
4+
5+
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.

‎.github/workflows/publish-trueforge-dev-packages.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
pnpm --filter @truefoundry/trueforge-ui build
9797
9898
- name: Setup JFrog CLI (OIDC)
99-
uses: jfrog/setup-jfrog-cli@v4
99+
uses: jfrog/setup-jfrog-cli@v5
100100
env:
101101
JF_URL: ${{ env.JF_URL }}
102102
with:

‎packages/trueforge-ui/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"@truefoundry/trueforge-sdk": "workspace:*",
102102
"chart.js": "^4.5.1",
103103
"clsx": "^2.1.1",
104-
"lucide-react": "^0.562.0",
104+
"lucide-react": "^1.73.0",
105105
"monaco-editor": "^0.57.0",
106106
"partial-json": "^0.1.7",
107107
"react-chartjs-2": "^5.3.1",

‎packages/trueforge-ui/src/atoms/ThreadListRow.tsx‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,16 @@ export function ThreadListRow({
8585
className,
8686
}: ThreadListRowProps) {
8787
const isMobile = useIsMobile();
88-
const statusDotClass = lastTurnStatusDotClass(lastTurnStatus);
89-
const statusLabel = lastTurnStatusLabel(lastTurnStatus);
88+
const statusDotClass = lastTurnStatusDotClass({
89+
status: lastTurnStatus,
90+
...(lastMessageAt != null ? { activityAt: lastMessageAt } : {}),
91+
});
9092
const running = isRunningTurnStatus(lastTurnStatus);
9193
const paused = isPausedTurnStatus(lastTurnStatus);
94+
// Chat history keeps paused chrome; failed runs are session-list only.
95+
const statusLabel = running || statusDotClass != null ? lastTurnStatusLabel(lastTurnStatus) : undefined;
9296
const age = lastMessageAt != null ? formatRelativeShort(lastMessageAt) : undefined;
93-
// Paused/error → status dot; running → jumping dots; otherwise relative age.
97+
// Paused → status dot; running → jumping dots; otherwise relative age.
9498
const relative = !running && statusDotClass == null ? age : undefined;
9599
const hasTrailing = running || relative != null || statusDotClass != null || actions != null;
96100

@@ -124,7 +128,7 @@ export function ThreadListRow({
124128
<span className={cn('truncate text-sm font-normal text-text-primary', running && 'aui-text-shimmer')}>
125129
{title}
126130
</span>
127-
{/* Mobile: keep the paused/error dot next to the title when actions own the trailing slot. */}
131+
{/* Mobile: keep the paused dot next to the title when actions own the trailing slot. */}
128132
{statusDotClass != null && actions != null ? (
129133
<span data-slot="session-status-dot" className="shrink-0 md:hidden">
130134
<StatusDot className="size-1.5" colorClassName={statusDotClass} pulse={paused} />

‎packages/trueforge-ui/src/atoms/agent-details/AgentSessionListRow.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export function AgentSessionListRow({
5656
const absolute = formatAbsoluteDateTime(activityAt);
5757
const subjectLabel = createdBySubject != null ? createdByLabel(createdBySubject) : null;
5858
const subjectInitials = subjectLabel != null ? getUserInitials(subjectLabel) || '?' : null;
59-
const statusDotClass = lastTurnStatusDotClass(lastTurnStatus);
59+
const statusDotClass = lastTurnStatusDotClass({ status: lastTurnStatus, activityAt });
60+
const failed = lastTurnStatus === 'error';
6061
const statusLabel = lastTurnStatusLabel(lastTurnStatus);
6162
const running = isRunningTurnStatus(lastTurnStatus);
6263
const paused = isPausedTurnStatus(lastTurnStatus);
@@ -78,6 +79,10 @@ export function AgentSessionListRow({
7879
<span data-slot="session-status-dot" className="shrink-0">
7980
<StatusDot className="size-1.5" colorClassName={statusDotClass} pulse={paused} />
8081
</span>
82+
) : failed ? (
83+
<span data-slot="session-status-failed" className="shrink-0 text-failure-bg" aria-hidden>
84+
<Icon name="circle-exclamation-point" className="size-3.5" />
85+
</span>
8186
) : null}
8287
{statusLabel != null ? <span className="sr-only">{statusLabel}</span> : null}
8388
{scheduleId != null ? (

‎packages/trueforge-ui/src/atoms/agent-details/AgentSessions.tsx‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { EmptyScreen } from '../EmptyScreen.js';
2525
import { cn } from '../lib/cn.js';
2626
import { sessionIsCreateAgent } from '../lib/sessionCreateAgent.js';
2727
import {
28+
mergePolledSessionRow,
2829
mergeSessionListFirstPage,
2930
SESSION_LIST_FIRST_PAGE_LIMIT,
3031
sessionListPollIntervalMs,
@@ -178,14 +179,7 @@ export function AgentSessions({
178179
mergeSessionListFirstPage({
179180
current,
180181
firstPage: page.data,
181-
mergeItem: (prev, next) => {
182-
const prevDetails = prev.lastTurnDetails;
183-
const nextDetails = next.lastTurnDetails;
184-
if (prevDetails?.id === nextDetails?.id && prevDetails?.state.status === nextDetails?.state.status) {
185-
return prev;
186-
}
187-
return { ...prev, lastTurnDetails: nextDetails };
188-
},
182+
mergeItem: mergePolledSessionRow,
189183
}),
190184
);
191185
} catch {

‎packages/trueforge-ui/src/atoms/lib/sessionListPoll.ts‎

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,34 @@ import type { TurnStatus } from '../../server/types.js';
33
/** Matches thread-list / AgentSessions first-page `limit`. */
44
export const SESSION_LIST_FIRST_PAGE_LIMIT = 20;
55

6-
/** Cadence while any listed row is still running. */
7-
export const SESSION_LIST_RUNNING_POLL_INTERVAL_MS = 10_000;
6+
/** Cadence while any listed row is running or paused. */
7+
export const SESSION_LIST_POLL_INTERVAL_MS = 5_000;
88

9-
/** Slower cadence when listed rows are only paused (approvals can wait a long time). */
10-
export const SESSION_LIST_PAUSED_POLL_INTERVAL_MS = 60_000;
11-
12-
/**
13-
* Poll interval for live last-turn status, or `null` when nothing needs polling.
14-
* Running wins over paused so a mixed page stays on the fast cadence.
15-
*/
9+
/** Poll interval for live last-turn status, or `null` when nothing needs polling. */
1610
export function sessionListPollIntervalMs(statuses: ReadonlyArray<TurnStatus | undefined | null>): number | null {
17-
let hasPaused = false;
1811
for (const status of statuses) {
19-
if (status === 'running') return SESSION_LIST_RUNNING_POLL_INTERVAL_MS;
20-
if (status === 'paused') hasPaused = true;
12+
if (status === 'running' || status === 'paused') return SESSION_LIST_POLL_INTERVAL_MS;
2113
}
22-
return hasPaused ? SESSION_LIST_PAUSED_POLL_INTERVAL_MS : null;
14+
return null;
15+
}
16+
17+
type PolledTurn = { id: string; state: { status: string } };
18+
19+
/**
20+
* Apply a first-page poll onto one row.
21+
* Status-only patches used to leave `lastActivityAt` at the original payload, so a
22+
* new pause on a row older than 48 hours stayed hidden.
23+
*/
24+
export function mergePolledSessionRow<T extends { lastActivityAt: string; lastTurnDetails?: PolledTurn | null }>(
25+
prev: T,
26+
next: T,
27+
): T {
28+
const prevDetails = prev.lastTurnDetails;
29+
const nextDetails = next.lastTurnDetails;
30+
const sameTurn = prevDetails?.id === nextDetails?.id && prevDetails?.state.status === nextDetails?.state.status;
31+
if (sameTurn && prev.lastActivityAt === next.lastActivityAt) return prev;
32+
if (sameTurn) return { ...prev, lastActivityAt: next.lastActivityAt };
33+
return { ...prev, lastActivityAt: next.lastActivityAt, lastTurnDetails: nextDetails };
2334
}
2435

2536
/**

‎packages/trueforge-ui/src/atoms/lib/threadListMeta.ts‎

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,34 @@ function isTurnStatus(value: unknown): value is TurnStatus {
99
return typeof value === 'string' && TURN_STATUS_VALUES.has(value);
1010
}
1111

12+
/** Orange paused dots older than this are hidden (AGE-2831). */
13+
export const PAUSED_STATUS_DOT_MAX_AGE_MS = 48 * 60 * 60 * 1000;
14+
15+
function isValidActivityDate(date: Date): boolean {
16+
return !Number.isNaN(date.getTime());
17+
}
18+
1219
/** Tailwind bg class for a last-turn status dot; undefined means hide the dot. */
13-
export function lastTurnStatusDotClass(status: TurnStatus | undefined | null): string | undefined {
20+
export function lastTurnStatusDotClass({
21+
status,
22+
activityAt,
23+
now = new Date(),
24+
}: {
25+
status: TurnStatus | undefined | null;
26+
activityAt?: Date | null;
27+
now?: Date;
28+
}): string | undefined {
1429
switch (status) {
15-
case 'paused':
30+
case 'paused': {
31+
if (
32+
activityAt != null &&
33+
isValidActivityDate(activityAt) &&
34+
now.getTime() - activityAt.getTime() > PAUSED_STATUS_DOT_MAX_AGE_MS
35+
) {
36+
return undefined;
37+
}
1638
return 'bg-warning-bg';
17-
case 'error':
18-
return 'bg-failure-bg';
39+
}
1940
default:
2041
return undefined;
2142
}
@@ -101,6 +122,32 @@ export function readThreadIsMutable(custom: unknown): boolean | undefined {
101122
return typeof value === 'boolean' ? value : undefined;
102123
}
103124

125+
/** Activity time stamped by the status poll. Newer than `lastMessageAt` after a fresh pause. */
126+
export function readThreadLastActivityAt(custom: unknown): Date | undefined {
127+
if (custom == null || typeof custom !== 'object') return undefined;
128+
if (!('lastActivityAt' in custom)) return undefined;
129+
const value = Reflect.get(custom, 'lastActivityAt');
130+
if (typeof value !== 'string') return undefined;
131+
const date = new Date(value);
132+
return Number.isNaN(date.getTime()) ? undefined : date;
133+
}
134+
135+
/** True when `nextIso` is a valid time strictly after `prev`. Missing `prev` counts as newer. */
136+
export function isNewerActivityAt(nextIso: string, prev: Date | undefined): boolean {
137+
const next = new Date(nextIso);
138+
if (Number.isNaN(next.getTime())) return false;
139+
if (prev == null || Number.isNaN(prev.getTime())) return true;
140+
return next.getTime() > prev.getTime();
141+
}
142+
143+
/** Later of the list payload time and a poll stamp. */
144+
export function laterActivityAt(left: Date | undefined, right: Date | undefined): Date | undefined {
145+
if (left == null || Number.isNaN(left.getTime()))
146+
return right != null && !Number.isNaN(right.getTime()) ? right : undefined;
147+
if (right == null || Number.isNaN(right.getTime())) return left;
148+
return right.getTime() > left.getTime() ? right : left;
149+
}
150+
104151
/** Last-turn status stamped on thread-list custom by `sessionToThreadMetadata`. */
105152
export function readThreadLastTurnStatus(custom: unknown): TurnStatus | undefined {
106153
if (custom == null || typeof custom !== 'object') return undefined;
@@ -113,6 +160,7 @@ export function readThreadLastTurnStatus(custom: unknown): TurnStatus | undefine
113160
export function threadCustomWithLastTurnStatus(
114161
custom: unknown,
115162
status: TurnStatus | null | undefined,
163+
activityAt?: string,
116164
): Record<string, unknown> {
117165
const base =
118166
custom != null && typeof custom === 'object' && !Array.isArray(custom)
@@ -122,6 +170,9 @@ export function threadCustomWithLastTurnStatus(
122170
if (status != null) {
123171
base.lastTurnStatus = status;
124172
}
173+
if (activityAt != null) {
174+
base.lastActivityAt = activityAt;
175+
}
125176
return base;
126177
}
127178

0 commit comments

Comments
 (0)