Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Pace burst Assistant workflow statuses

rcourtman621391a12503
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 8c7c70849f..8bd3bdb857 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -714,9 +714,10 @@ timers when the stream already has a newer workflow/tool state.
delaying copy/export, tool boundaries, approvals, or audit evidence.
Live workflow labels follow that same presentation-layer constraint: the
canonical SSE/store state remains the latest typed `workflow_state`, and the
- browser must render that latest status immediately instead of replaying an
- older live-only history. This follows the current OpenCode TUI event
- mutation model at fetched `origin/dev` commit
+ browser must render single fresh status updates immediately while using
+ bounded live-only history only to pace backend/network burst replacements.
+ This follows the current OpenCode TUI event mutation model at fetched
+ `origin/dev` commit
`06d7840d1d42c9815d2d2e45e7fa4090ca4e3577`, especially
`packages/opencode/src/cli/cmd/tui/context/sync-v2.tsx`, where
`session.next.step.started`, text deltas, and tool progress mutate the
diff --git a/frontend-modern/src/api/__tests__/aiChat.test.ts b/frontend-modern/src/api/__tests__/aiChat.test.ts
index 8a87813fa3..9daf5d64f3 100644
--- a/frontend-modern/src/api/__tests__/aiChat.test.ts
+++ b/frontend-modern/src/api/__tests__/aiChat.test.ts
@@ -243,6 +243,50 @@ describe('AIChatAPI', () => {
});
});
+ it('runs the workflow-burst dev stream fixture without opening a provider request', async () => {
+ const onEvent = vi.fn();
+
+ await AIChatAPI.chat(
+ '/fixture workflow-burst',
+ undefined,
+ 'openrouter:qwen/qwen3.7-plus',
+ onEvent,
+ );
+
+ expect(apiFetchMock).not.toHaveBeenCalled();
+ expect(onEvent.mock.calls.map(([event]) => event.type)).toEqual([
+ 'session',
+ 'workflow_state',
+ 'workflow_state',
+ 'workflow_state',
+ 'content',
+ 'done',
+ ]);
+ expect(onEvent.mock.calls[2][0]).toMatchObject({
+ type: 'workflow_state',
+ data: {
+ phase: 'context',
+ message: 'Reading current Pulse inventory with pulse_query.',
+ tool: 'pulse_query',
+ },
+ });
+ expect(onEvent.mock.calls[3][0]).toMatchObject({
+ type: 'workflow_state',
+ data: {
+ phase: 'provider_start',
+ message: 'OpenRouter is starting the response.',
+ model: 'openrouter:qwen/qwen3.7-plus',
+ },
+ });
+ expect(onEvent.mock.calls[5][0]).toMatchObject({
+ type: 'done',
+ data: {
+ session_id: 'dev-fixture-workflow-burst',
+ model: 'openrouter:qwen/qwen3.7-plus',
+ },
+ });
+ });
+
it('keeps the tool-burst fixture running state visible when fixture pacing is enabled', async () => {
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
const onEvent = vi.fn();
diff --git a/frontend-modern/src/api/aiChatDevStreamFixture.ts b/frontend-modern/src/api/aiChatDevStreamFixture.ts
index 9790ca62f1..1a61cdf7e9 100644
--- a/frontend-modern/src/api/aiChatDevStreamFixture.ts
+++ b/frontend-modern/src/api/aiChatDevStreamFixture.ts
@@ -5,6 +5,7 @@ export const AI_CHAT_DEV_STREAM_FIXTURE_PROMPTS = [
'/fixture assistant-stream',
'/fixture send-hold',
'/fixture tool-burst',
+ '/fixture workflow-burst',
'/fixture context-group',
'/fixture status-boundary',
'/fixture pending-tool',
@@ -337,6 +338,51 @@ const buildToolBurstFixtureEvents = (model?: string): AIChatStreamEvent[] => [
},
];
+const buildWorkflowBurstFixtureEvents = (model?: string): AIChatStreamEvent[] => [
+ {
+ type: 'session',
+ data: { id: 'dev-fixture-workflow-burst' },
+ },
+ {
+ type: 'workflow_state',
+ data: {
+ phase: 'request_start',
+ message: 'Preparing Pulse context.',
+ },
+ },
+ {
+ type: 'workflow_state',
+ data: {
+ phase: 'context',
+ message: 'Reading current Pulse inventory with pulse_query.',
+ tool: 'pulse_query',
+ },
+ },
+ {
+ type: 'workflow_state',
+ data: {
+ phase: 'provider_start',
+ message: 'OpenRouter is starting the response.',
+ model: assistantFixtureModel(model),
+ },
+ },
+ {
+ type: 'content',
+ data: {
+ text: 'The workflow-burst fixture held the live status long enough to show paced status movement.',
+ },
+ },
+ {
+ type: 'done',
+ data: {
+ session_id: 'dev-fixture-workflow-burst',
+ model: assistantFixtureModel(model),
+ input_tokens: 41,
+ output_tokens: 18,
+ },
+ },
+];
+
const buildContextGroupFixtureEvents = (model?: string): AIChatStreamEvent[] => [
{
type: 'session',
@@ -863,6 +909,9 @@ const buildFixtureEvents = (prompt: string, model?: string): AIChatStreamEvent[]
if (normalized === '/fixture tool-burst') {
return buildToolBurstFixtureEvents(model);
}
+ if (normalized === '/fixture workflow-burst') {
+ return buildWorkflowBurstFixtureEvents(model);
+ }
if (normalized === '/fixture send-hold') {
return buildSendHoldFixtureEvents(model);
}
@@ -932,6 +981,13 @@ const fixtureStepDelay = (
) {
return 10000;
}
+ if (
+ normalizedPrompt === '/fixture workflow-burst' &&
+ event.type === 'workflow_state' &&
+ event.data.phase === 'provider_start'
+ ) {
+ return 2400;
+ }
if (normalizedPrompt === '/fixture pending-tool') return defaultDelayMs;
if (normalizedPrompt !== '/fixture tool-burst') return defaultDelayMs;
if (event.type === 'tool_start') {
diff --git a/frontend-modern/src/components/AI/Chat/MessageItem.tsx b/frontend-modern/src/components/AI/Chat/MessageItem.tsx
index 55ae560433..bc0c7ea521 100644
--- a/frontend-modern/src/components/AI/Chat/MessageItem.tsx
+++ b/frontend-modern/src/components/AI/Chat/MessageItem.tsx
@@ -27,6 +27,7 @@ import { getAssistantAnswerText } from './assistantAnswerText';
import { stripAssistantOutputArtifacts } from './assistantOutputHygiene';
import { formatAssistantWorkflowStatus } from './activeTurnStatus';
import { groupStreamEventsForDisplay } from './streamEventGrouping';
+import { pacedWorkflowStatusForDisplay } from './workflowStatusPacing';
import type {
ChatMessage,
ModelRouteRecoveryOption,
@@ -388,8 +389,15 @@ export const MessageItem: Component<MessageItemProps> = (props) => {
}
return `${message}${elapsedSuffix}`;
};
+ const displayedWorkflowStatus = (status?: WorkflowStatus) =>
+ pacedWorkflowStatusForDisplay(
+ props.message.workflowStatusHistory,
+ status,
+ groupedEvents(),
+ props.message.isStreaming ? statusNow() : undefined,
+ );
const workflowStatusText = createMemo(() =>
- formatWorkflowStatus(currentWorkflowStatus(), true),
+ formatWorkflowStatus(displayedWorkflowStatus(currentWorkflowStatus()), true),
);
const shouldShowHeaderWorkflowStatus = () =>
props.message.isStreaming &&
@@ -580,7 +588,9 @@ export const MessageItem: Component<MessageItemProps> = (props) => {
const contentText = () =>
stripAssistantOutputArtifacts(evt?.content || '').text;
const visibleWorkflowStatus = () =>
- evt?.type === 'workflow_status' ? evt.workflowStatus : undefined;
+ evt?.type === 'workflow_status'
+ ? displayedWorkflowStatus(evt.workflowStatus)
+ : undefined;
return (
<Switch>
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
index bd68caaa62..b36eb4a2b3 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
@@ -5331,7 +5331,9 @@ describe('AIChat', () => {
expect(status).not.toHaveTextContent('Using Qwen: Qwen3.7 Plus via OpenRouter');
});
- it('shows the latest replacing workflow progress in the active turn status footer', () => {
+ it('paces replacing workflow progress in the active turn status footer', async () => {
+ vi.useFakeTimers();
+ vi.setSystemTime(1_200);
const [isLoading, setIsLoading] = createSignal(false);
const [messages, setMessages] = createSignal<ChatMessage[]>([]);
const workflowStatusHistory = [
@@ -5378,12 +5380,28 @@ describe('AIChat', () => {
]);
const status = screen.getByLabelText('Assistant active turn status');
- expect(status).toHaveTextContent('OpenRouter is starting the response.');
+ expect(status).toHaveTextContent('Preparing Pulse context.');
+ expect(status).not.toHaveTextContent('OpenRouter is starting the response.');
+ expect(status).not.toHaveTextContent('Reading current Pulse inventory.');
+
+ vi.advanceTimersByTime(1_000);
+ await waitFor(() =>
+ expect(status).toHaveTextContent('Reading current Pulse inventory.'),
+ );
+ expect(status).not.toHaveTextContent('Preparing Pulse context.');
+ expect(status).not.toHaveTextContent('OpenRouter is starting the response.');
+
+ vi.advanceTimersByTime(1_000);
+ await waitFor(() =>
+ expect(status).toHaveTextContent('OpenRouter is starting the response.'),
+ );
expect(status).not.toHaveTextContent('Preparing Pulse context.');
expect(status).not.toHaveTextContent('Reading current Pulse inventory.');
});
- it('shows latest replacing workflow progress without dropping queued follow-up pressure', () => {
+ it('paces replacing workflow progress without dropping queued follow-up pressure', async () => {
+ vi.useFakeTimers();
+ vi.setSystemTime(1_200);
const [isLoading, setIsLoading] = createSignal(false);
const [messages, setMessages] = createSignal<ChatMessage[]>([]);
const workflowStatusHistory = [
@@ -5438,9 +5456,18 @@ describe('AIChat', () => {
]);
const status = screen.getByLabelText('Assistant active turn status');
- expect(status).toHaveTextContent('OpenRouter is starting the response. · 1 follow-up queued');
- expect(status).not.toHaveTextContent('Preparing Pulse context.');
+ expect(status).toHaveTextContent('Preparing Pulse context. · 1 follow-up queued');
+ expect(status).not.toHaveTextContent('OpenRouter is starting the response.');
expect(status).not.toHaveTextContent('Reading current Pulse inventory.');
+
+ vi.advanceTimersByTime(1_000);
+ await waitFor(() =>
+ expect(status).toHaveTextContent(
+ 'Reading current Pulse inventory. · 1 follow-up queued',
+ ),
+ );
+ expect(status).not.toHaveTextContent('Preparing Pulse context.');
+ expect(status).not.toHaveTextContent('OpenRouter is starting the response.');
});
it('keeps pending tool progress visible in the active turn status', () => {
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/MessageItem.test.tsx b/frontend-modern/src/components/AI/Chat/__tests__/MessageItem.test.tsx
index e74203243e..6c82525105 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/MessageItem.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/MessageItem.test.tsx
@@ -801,7 +801,7 @@ describe('MessageItem', () => {
).toBeInTheDocument();
});
- it('shows the latest replacing workflow activity in one live transcript row', () => {
+ it('paces replacing workflow activity through one live transcript row', async () => {
vi.useFakeTimers();
vi.setSystemTime(1_200);
@@ -844,7 +844,21 @@ describe('MessageItem', () => {
/>
));
- expect(screen.getByText('OpenRouter is starting the response.')).toBeInTheDocument();
+ expect(screen.getByText('Preparing Pulse context.')).toBeInTheDocument();
+ expect(screen.queryByText(/OpenRouter is starting the response\./)).not.toBeInTheDocument();
+ expect(
+ screen.queryByText(/Reading current Pulse inventory\./),
+ ).not.toBeInTheDocument();
+
+ vi.advanceTimersByTime(1_000);
+ await Promise.resolve();
+ expect(screen.getByText('Reading current Pulse inventory.')).toBeInTheDocument();
+ expect(screen.queryByText(/Preparing Pulse context\./)).not.toBeInTheDocument();
+ expect(screen.queryByText(/OpenRouter is starting the response\./)).not.toBeInTheDocument();
+
+ vi.advanceTimersByTime(1_000);
+ await Promise.resolve();
+ expect(screen.getByText(/OpenRouter is starting the response\./)).toBeInTheDocument();
expect(screen.queryByText(/Preparing Pulse context\./)).not.toBeInTheDocument();
expect(
screen.queryByText(/Reading current Pulse inventory\./),
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/activeTurnStatus.test.ts b/frontend-modern/src/components/AI/Chat/__tests__/activeTurnStatus.test.ts
index 75088a96d9..e7c8b5f78b 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/activeTurnStatus.test.ts
+++ b/frontend-modern/src/components/AI/Chat/__tests__/activeTurnStatus.test.ts
@@ -244,6 +244,58 @@ describe('getAssistantActiveTurnStatus', () => {
});
});
+ it('paces burst workflow progress in the active turn footer', () => {
+ const workflowStatusHistory = [
+ {
+ phase: 'request_start',
+ message: 'Preparing Pulse context.',
+ startedAt: 1_000,
+ },
+ {
+ phase: 'context',
+ message: 'Reading current Pulse inventory with pulse_query.',
+ tool: 'pulse_query',
+ startedAt: 1_100,
+ },
+ {
+ phase: 'provider_start',
+ message: 'OpenRouter is starting the response.',
+ startedAt: 1_200,
+ },
+ ];
+ const messages = [
+ assistantMessage({
+ isStreaming: true,
+ workflowStatusHistory,
+ workflowStatus: workflowStatusHistory[2],
+ streamEvents: [
+ {
+ type: 'workflow_status',
+ workflowStatus: workflowStatusHistory[2],
+ startedAt: 1_200,
+ updatedAt: 1_200,
+ },
+ ],
+ }),
+ ];
+
+ expect(getAssistantActiveTurnStatus(messages, true, 1_200)).toEqual({
+ type: 'thinking',
+ text: 'Preparing Pulse context.',
+ startedAt: 1_000,
+ });
+ expect(getAssistantActiveTurnStatus(messages, true, 1_900)).toEqual({
+ type: 'tool',
+ text: 'Reading current Pulse inventory.',
+ startedAt: 1_100,
+ });
+ expect(getAssistantActiveTurnStatus(messages, true, 2_800)).toEqual({
+ type: 'thinking',
+ text: 'OpenRouter is starting the response.',
+ startedAt: 1_200,
+ });
+ });
+
it('prefers workflow progress over selected model route evidence', () => {
const startedAt = Date.now() - 1_000;
expect(
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/workflowStatusPacing.test.ts b/frontend-modern/src/components/AI/Chat/__tests__/workflowStatusPacing.test.ts
new file mode 100644
index 0000000000..aa2d962f3b
--- /dev/null
+++ b/frontend-modern/src/components/AI/Chat/__tests__/workflowStatusPacing.test.ts
@@ -0,0 +1,113 @@
+import { describe, expect, it } from 'vitest';
+import { pacedWorkflowStatusForDisplay, WORKFLOW_STATUS_PACE_MS } from '../workflowStatusPacing';
+import type { StreamDisplayEvent, WorkflowStatus } from '../types';
+
+const burstStatuses = (): WorkflowStatus[] => [
+ {
+ phase: 'request_start',
+ message: 'Preparing Pulse context.',
+ startedAt: 1_000,
+ },
+ {
+ phase: 'context',
+ message: 'Reading current Pulse inventory with pulse_query.',
+ tool: 'pulse_query',
+ startedAt: 1_100,
+ },
+ {
+ phase: 'provider_start',
+ message: 'OpenRouter is starting the response.',
+ startedAt: 1_200,
+ },
+];
+
+describe('workflowStatusPacing', () => {
+ it('paces burst workflow statuses instead of jumping straight to the latest status', () => {
+ const history = burstStatuses();
+ const events: StreamDisplayEvent[] = [
+ {
+ type: 'workflow_status',
+ workflowStatus: history[2],
+ startedAt: 1_200,
+ updatedAt: 1_200,
+ },
+ ];
+
+ expect(
+ pacedWorkflowStatusForDisplay(history, history[2], events, 1_200),
+ ).toBe(history[0]);
+ expect(
+ pacedWorkflowStatusForDisplay(
+ history,
+ history[2],
+ events,
+ 1_000 + WORKFLOW_STATUS_PACE_MS,
+ ),
+ ).toBe(history[1]);
+ expect(
+ pacedWorkflowStatusForDisplay(
+ history,
+ history[2],
+ events,
+ 1_000 + WORKFLOW_STATUS_PACE_MS * 2,
+ ),
+ ).toBe(history[2]);
+ });
+
+ it('keeps workflow rows tied to their own status after durable transcript evidence', () => {
+ const history = burstStatuses();
+ const events: StreamDisplayEvent[] = [
+ {
+ type: 'workflow_status',
+ workflowStatus: history[0],
+ startedAt: 1_000,
+ updatedAt: 1_000,
+ },
+ {
+ type: 'tool',
+ tool: {
+ name: 'pulse_query',
+ input: '{}',
+ output: '3 devices found',
+ success: true,
+ },
+ startedAt: 1_150,
+ updatedAt: 1_300,
+ },
+ {
+ type: 'workflow_status',
+ workflowStatus: history[2],
+ startedAt: 1_200,
+ updatedAt: 1_200,
+ },
+ ];
+
+ expect(
+ pacedWorkflowStatusForDisplay(history, history[2], events, 1_200),
+ ).toBe(history[2]);
+ });
+
+ it('does not pace status history that was not delivered as a burst', () => {
+ const history: WorkflowStatus[] = [
+ {
+ phase: 'request_start',
+ message: 'Preparing Pulse context.',
+ startedAt: 1_000,
+ },
+ {
+ phase: 'provider_start',
+ message: 'OpenRouter is starting the response.',
+ startedAt: 2_500,
+ },
+ ];
+
+ expect(
+ pacedWorkflowStatusForDisplay(
+ history,
+ history[1],
+ [{ type: 'workflow_status', workflowStatus: history[1] }],
+ 2_500,
+ ),
+ ).toBe(history[1]);
+ });
+});
diff --git a/frontend-modern/src/components/AI/Chat/activeTurnStatus.ts b/frontend-modern/src/components/AI/Chat/activeTurnStatus.ts
index 03ab2e85c5..f38641efac 100644
--- a/frontend-modern/src/components/AI/Chat/activeTurnStatus.ts
+++ b/frontend-modern/src/components/AI/Chat/activeTurnStatus.ts
@@ -8,6 +8,7 @@ import {
parseToolInputSummary,
toolValueText,
} from './toolPresentation';
+import { pacedWorkflowStatusForDisplay } from './workflowStatusPacing';
export type AssistantActiveTurnStatusKind = 'thinking' | 'tool' | 'generating';
@@ -363,6 +364,7 @@ const completedToolStatusText = (event: StreamDisplayEvent): string => {
const latestStreamActivityStatus = (
events?: StreamDisplayEvent[],
now?: number,
+ workflowStatusHistory?: WorkflowStatus[],
): AssistantActiveTurnStatusCandidate | null => {
const completedToolKeys = new Set<string>();
let current: AssistantActiveTurnStatusCandidate | null = null;
@@ -424,14 +426,20 @@ const latestStreamActivityStatus = (
break;
}
case 'workflow_status': {
- const text = formatAssistantWorkflowStatus(event.workflowStatus, now);
+ const workflowStatus = pacedWorkflowStatusForDisplay(
+ workflowStatusHistory,
+ event.workflowStatus,
+ events,
+ now,
+ );
+ const text = formatAssistantWorkflowStatus(workflowStatus, now);
if (text) {
candidate = {
- type: event.workflowStatus?.tool ? 'tool' : 'thinking',
+ type: workflowStatus?.tool ? 'tool' : 'thinking',
text,
- startedAt: event.workflowStatus?.startedAt || event.startedAt,
+ startedAt: workflowStatus?.startedAt || event.startedAt,
activityAt: eventActivityAt(event),
- placeholder: isInitialRequestStartStatus(event.workflowStatus),
+ placeholder: isInitialRequestStartStatus(workflowStatus),
order: index,
};
}
@@ -617,7 +625,11 @@ export const getAssistantActiveTurnStatus = (
if (statePendingToolCandidate) {
statusCandidates.push(statePendingToolCandidate);
}
- const eventStatusCandidate = latestStreamActivityStatus(assistantMessage.streamEvents, now);
+ const eventStatusCandidate = latestStreamActivityStatus(
+ assistantMessage.streamEvents,
+ now,
+ assistantMessage.workflowStatusHistory,
+ );
if (eventStatusCandidate) {
statusCandidates.push(eventStatusCandidate);
} else {
@@ -628,11 +640,17 @@ export const getAssistantActiveTurnStatus = (
}
}
if (assistantMessage.isStreaming !== false) {
- const workflowCandidate = workflowStatusCandidate(assistantMessage.workflowStatus, now);
+ const displayedWorkflowStatus = pacedWorkflowStatusForDisplay(
+ assistantMessage.workflowStatusHistory,
+ assistantMessage.workflowStatus,
+ assistantMessage.streamEvents,
+ now,
+ );
+ const workflowCandidate = workflowStatusCandidate(displayedWorkflowStatus, now);
if (
workflowCandidate &&
!(
- isInitialRequestStartStatus(assistantMessage.workflowStatus) &&
+ isInitialRequestStartStatus(displayedWorkflowStatus) &&
eventStatusCandidate &&
eventStatusCandidate.placeholder !== true
)
diff --git a/frontend-modern/src/components/AI/Chat/workflowStatusPacing.ts b/frontend-modern/src/components/AI/Chat/workflowStatusPacing.ts
new file mode 100644
index 0000000000..28fbc42ff5
--- /dev/null
+++ b/frontend-modern/src/components/AI/Chat/workflowStatusPacing.ts
@@ -0,0 +1,97 @@
+import type { StreamDisplayEvent, WorkflowStatus } from './types';
+
+export const WORKFLOW_STATUS_PACE_MS = 900;
+const WORKFLOW_STATUS_BURST_GAP_MS = 900;
+
+const finiteTime = (value: unknown): number | undefined =>
+ typeof value === 'number' && Number.isFinite(value) ? value : undefined;
+
+const workflowStatusesMatch = (a?: WorkflowStatus, b?: WorkflowStatus) =>
+ !!a &&
+ !!b &&
+ (a.phase || '') === (b.phase || '') &&
+ a.message === b.message &&
+ (a.state || '') === (b.state || '') &&
+ (a.tool || '') === (b.tool || '') &&
+ (a.provider || '') === (b.provider || '') &&
+ (a.model || '') === (b.model || '') &&
+ (a.attempt || 0) === (b.attempt || 0) &&
+ (a.maxAttempts || 0) === (b.maxAttempts || 0) &&
+ (a.retryAfterMs || 0) === (b.retryAfterMs || 0);
+
+const isDurableStreamBoundary = (event: StreamDisplayEvent) =>
+ event.type !== 'workflow_status' && event.type !== 'model_switch';
+
+const latestWorkflowEventIndex = (
+ events: StreamDisplayEvent[] | undefined,
+ currentStatus: WorkflowStatus | undefined,
+): number => {
+ for (let index = (events?.length || 0) - 1; index >= 0; index -= 1) {
+ const event = events?.[index];
+ if (event?.type !== 'workflow_status') continue;
+ if (!currentStatus || workflowStatusesMatch(event.workflowStatus, currentStatus)) {
+ return index;
+ }
+ }
+ return -1;
+};
+
+const hasEarlierDurableBoundary = (
+ events: StreamDisplayEvent[] | undefined,
+ workflowIndex: number,
+) => {
+ if (!events || workflowIndex < 0) return false;
+ for (let index = 0; index < workflowIndex; index += 1) {
+ if (isDurableStreamBoundary(events[index])) return true;
+ }
+ return false;
+};
+
+const burstHistoryUpTo = (
+ history: WorkflowStatus[] | undefined,
+ currentStatus: WorkflowStatus | undefined,
+): WorkflowStatus[] => {
+ if (!history?.length || !currentStatus) return [];
+
+ let currentIndex = -1;
+ for (let index = history.length - 1; index >= 0; index -= 1) {
+ if (workflowStatusesMatch(history[index], currentStatus)) {
+ currentIndex = index;
+ break;
+ }
+ }
+ if (currentIndex <= 0) return [];
+
+ const segment = history.slice(0, currentIndex + 1);
+ for (let index = 1; index < segment.length; index += 1) {
+ const previousAt = finiteTime(segment[index - 1].startedAt);
+ const currentAt = finiteTime(segment[index].startedAt);
+ if (previousAt === undefined || currentAt === undefined) return [];
+ const gap = currentAt - previousAt;
+ if (gap < 0 || gap > WORKFLOW_STATUS_BURST_GAP_MS) return [];
+ }
+ return segment;
+};
+
+export const pacedWorkflowStatusForDisplay = (
+ history: WorkflowStatus[] | undefined,
+ currentStatus: WorkflowStatus | undefined,
+ events: StreamDisplayEvent[] | undefined,
+ now?: number,
+): WorkflowStatus | undefined => {
+ const workflowIndex = latestWorkflowEventIndex(events, currentStatus);
+ if (workflowIndex >= 0 && hasEarlierDurableBoundary(events, workflowIndex)) {
+ return currentStatus;
+ }
+
+ const segment = burstHistoryUpTo(history, currentStatus);
+ if (segment.length <= 1) return currentStatus;
+
+ const start = finiteTime(segment[0].startedAt);
+ const currentTime = finiteTime(now);
+ if (start === undefined || currentTime === undefined) return currentStatus;
+
+ const elapsed = Math.max(0, currentTime - start);
+ const pacedIndex = Math.min(segment.length - 1, Math.floor(elapsed / WORKFLOW_STATUS_PACE_MS));
+ return segment[pacedIndex] || currentStatus;
+};