Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(tracing): r3-h1 isolate replay page ordering

Josué633bf0f582e0
diff --git a/control-ui/components/GovernedTraceSurface/SessionReplay/index.tsx b/control-ui/components/GovernedTraceSurface/SessionReplay/index.tsx
index 9e60b9363..b91a67769 100644
--- a/control-ui/components/GovernedTraceSurface/SessionReplay/index.tsx
+++ b/control-ui/components/GovernedTraceSurface/SessionReplay/index.tsx
@@ -1,6 +1,6 @@
'use client'
-import { useEffect, useMemo, useState } from 'react'
+import { useEffect, useMemo, useRef, useState } from 'react'
import { DataTable } from '@clerum/frontend-table-system'
import { TableHeaderRow } from '@components/TableHeaderRow'
import type { TableHeaderColumn } from '@components/TableHeaderRow/types'
@@ -47,6 +47,7 @@ export function SessionReplay({
const [openFilterId, setOpenFilterId] = useState<string | null>(null)
const [copiedSessionKey, setCopiedSessionKey] = useState<string | null>(null)
const [order, setOrder] = useState<'oldest' | 'latest'>('latest')
+ const loadMoreGeneration = useRef(0)
const columns = useMemo<TableHeaderColumn[]>(
() =>
@@ -55,7 +56,11 @@ export function SessionReplay({
...(column.key === 'activity'
? {
activeDirection: order === 'latest' ? ('desc' as const) : ('asc' as const),
- onSort: () => setOrder(current => (current === 'latest' ? 'oldest' : 'latest')),
+ onSort: () => {
+ loadMoreGeneration.current += 1
+ setLoadingMore(false)
+ setOrder(current => (current === 'latest' ? 'oldest' : 'latest'))
+ },
sortLabel: column.label,
}
: {}),
@@ -71,6 +76,8 @@ export function SessionReplay({
)
useEffect(() => {
+ loadMoreGeneration.current += 1
+ setLoadingMore(false)
setPage(null)
setSessions([])
setError(null)
@@ -90,11 +97,15 @@ export function SessionReplay({
.finally(() => {
if (!controller.signal.aborted) setLoading(false)
})
- return () => controller.abort()
+ return () => {
+ controller.abort()
+ loadMoreGeneration.current += 1
+ }
}, [apiQuery, boundaryEpoch, order, stateKey])
async function loadMore() {
if (!apiQuery || !page?.nextCursor) return
+ const generation = ++loadMoreGeneration.current
setLoadingMore(true)
setError(null)
try {
@@ -103,12 +114,15 @@ export function SessionReplay({
cursor: page.nextCursor,
order,
})
+ if (generation !== loadMoreGeneration.current) return
setPage(next)
setSessions(current => [...current, ...next.sessions])
} catch (readError) {
- setError(readError instanceof Error ? readError.message : 'Unable to load more sessions.')
+ if (generation === loadMoreGeneration.current) {
+ setError(readError instanceof Error ? readError.message : 'Unable to load more sessions.')
+ }
} finally {
- setLoadingMore(false)
+ if (generation === loadMoreGeneration.current) setLoadingMore(false)
}
}
diff --git a/control-ui/components/__tests__/GovernedSessionReplay.test.tsx b/control-ui/components/__tests__/GovernedSessionReplay.test.tsx
index dedfb1a61..a3f9baa9e 100644
--- a/control-ui/components/__tests__/GovernedSessionReplay.test.tsx
+++ b/control-ui/components/__tests__/GovernedSessionReplay.test.tsx
@@ -1,5 +1,5 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
-import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
+import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
import {
getGovernedApprovalPromptHistory,
getGovernedTraceSessionDetail,
@@ -296,6 +296,46 @@ describe('SessionReplay', () => {
expect(screen.getByText('0 calls · no central usage events')).toBeInTheDocument()
expect(screen.queryByText('unavailable')).not.toBeInTheDocument()
})
+
+ it('does not append an in-flight page after the activity order changes', async () => {
+ let resolveStalePage:
+ | ((page: Awaited<ReturnType<typeof getGovernedTraceSessions>>) => void)
+ | null = null
+ const stalePage = new Promise<Awaited<ReturnType<typeof getGovernedTraceSessions>>>(resolve => {
+ resolveStalePage = resolve
+ })
+ mockGetSessions
+ .mockResolvedValueOnce({
+ sessions: [SESSION],
+ nextCursor: 'latest-page-2',
+ capturedHighWatermark: '10',
+ })
+ .mockImplementationOnce(() => stalePage)
+ .mockResolvedValueOnce({
+ sessions: [{ ...SESSION, sessionId: 'oldest-session' }],
+ nextCursor: null,
+ capturedHighWatermark: '10',
+ })
+
+ render(<SessionReplay />)
+
+ fireEvent.click(await screen.findByRole('button', { name: 'Load more' }))
+ await waitFor(() => expect(mockGetSessions).toHaveBeenCalledTimes(2))
+ fireEvent.click(screen.getByRole('button', { name: 'Sort by Activity ascending' }))
+ expect(await screen.findByText('oldest-session')).toBeInTheDocument()
+
+ await act(async () => {
+ resolveStalePage?.({
+ sessions: [{ ...SESSION, sessionId: 'stale-latest-session' }],
+ nextCursor: null,
+ capturedHighWatermark: '10',
+ })
+ await stalePage
+ })
+
+ expect(screen.queryByText('stale-latest-session')).not.toBeInTheDocument()
+ expect(screen.queryByText('session-42')).not.toBeInTheDocument()
+ })
})
describe('SessionReplayDetail protected prompt evidence', () => {
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index e542bdb86..cd9d1001f 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.494",
+ "version": "0.1.495",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.494",
+ "version": "0.1.495",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-table-system": "file:../packages/frontend-table-system",
diff --git a/control-ui/package.json b/control-ui/package.json
index 421b2ebcc..85c255707 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.494",
+ "version": "0.1.495",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",