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.

Show Assistant selected model at turn start

rcourtman52c6f0b60b4e
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index dfcad4c8a0..3461ab9071 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -183,7 +183,7 @@ runtime cost control, and shared AI transport surfaces.
from the disclosure without expanding the default transcript.
Live workflow activity is also active turn state, not disposable waiting
copy. The referenced OpenCode source at fetched `origin/dev` commit
- `4519a1da329c1a4fc384054e7203ba7d06928205` defines model, shell, step,
+ `1025540fcc2a69609a0131a7168300205656d728` defines model, shell, step,
and tool lifecycle events in `packages/core/src/session/event.ts` (model
switched lines 62-70; shell started/ended lines 151-174; tool lifecycle
lines 340-392), projects them into durable message/part rows in
@@ -198,9 +198,16 @@ runtime cost control, and shared AI transport surfaces.
arrives. Burst workflow statuses may still replace one another until a
durable stream boundary appears, and terminal cleanup on done/error/Stop
may remove transient workflow-status rows while preserving typed
- model-switch and tool evidence. The generated frontend SSE contract must
- include workflow `provider` and `model` fields so selected-route activity
- is typed end to end.
+ model-switch and tool evidence. When the selected model route is already
+ known at turn creation, Pulse must seed a selected-model stream event before
+ backend/provider activity arrives so the transcript and active-turn footer
+ show concrete route motion instead of a generic request-start wait.
+ Placeholder `request_start` workflow statuses remain fallback activity only:
+ once selected-model, provider, tool, thinking, approval, question, or content
+ activity is visible, the placeholder must not outrank it in the footer or
+ render beside it as a duplicate transcript row. The generated frontend SSE
+ contract must include workflow `provider` and `model` fields so
+ selected-route activity is typed end to end.
The transcript viewport is part of the same live activity contract. The
referenced OpenCode source at fetched `origin/dev` commit
`1025540fcc2a69609a0131a7168300205656d728` forwards reducer commits into
diff --git a/frontend-modern/src/components/AI/Chat/MessageItem.tsx b/frontend-modern/src/components/AI/Chat/MessageItem.tsx
index 6b740d4c5c..bd2c85af9f 100644
--- a/frontend-modern/src/components/AI/Chat/MessageItem.tsx
+++ b/frontend-modern/src/components/AI/Chat/MessageItem.tsx
@@ -25,7 +25,7 @@ import { QuestionCard } from './QuestionCard';
import { ThinkingBlock } from './ThinkingBlock';
import { getAssistantAnswerText } from './assistantAnswerText';
import { stripAssistantOutputArtifacts } from './assistantOutputHygiene';
-import { formatAssistantWorkflowStatus } from './activeTurnStatus';
+import { formatAssistantWorkflowStatus, isInitialRequestStartStatus } from './activeTurnStatus';
import { groupStreamEventsForDisplay } from './streamEventGrouping';
import {
latestWorkflowStatus,
@@ -261,12 +261,43 @@ export const MessageItem: Component<MessageItemProps> = (props) => {
const groupedEvents = createMemo(() =>
groupStreamEventsForDisplay(props.message.streamEvents || []),
);
+ const isConcreteStreamActivity = (evt: StreamDisplayEvent) => {
+ switch (evt.type) {
+ case 'workflow_status':
+ return (
+ !isInitialRequestStartStatus(evt.workflowStatus) &&
+ !!formatAssistantWorkflowStatus(evt.workflowStatus)
+ );
+ case 'thinking':
+ return !!evt.thinking?.trim();
+ case 'content':
+ return !!stripAssistantOutputArtifacts(evt.content || '').text;
+ case 'tool':
+ return !!evt.tool;
+ case 'pending_tool':
+ return !!evt.pendingTool;
+ case 'model_switch':
+ return !!evt.model?.trim();
+ case 'approval':
+ return !!evt.approval;
+ case 'question':
+ return !!evt.question;
+ default:
+ return false;
+ }
+ };
+ const hasConcreteStreamActivity = createMemo(() =>
+ groupedEvents().some(isConcreteStreamActivity),
+ );
+ const shouldRenderWorkflowStatusEvent = (evt: StreamDisplayEvent) =>
+ !!formatAssistantWorkflowStatus(evt.workflowStatus) &&
+ (!isInitialRequestStartStatus(evt.workflowStatus) || !hasConcreteStreamActivity());
const isRenderableStreamEvent = (evt: StreamDisplayEvent) => {
switch (evt.type) {
case 'thinking':
return !!evt.thinking?.trim();
case 'workflow_status':
- return !!formatAssistantWorkflowStatus(evt.workflowStatus);
+ return shouldRenderWorkflowStatusEvent(evt);
case 'content':
return !!stripAssistantOutputArtifacts(evt.content || '').text;
case 'tool':
@@ -553,7 +584,7 @@ export const MessageItem: Component<MessageItemProps> = (props) => {
<Match
when={
evt.type === 'workflow_status' &&
- formatAssistantWorkflowStatus(evt.workflowStatus)
+ shouldRenderWorkflowStatusEvent(evt)
}
>
<div
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 30a506dda5..52dca28629 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
@@ -4607,6 +4607,49 @@ describe('AIChat', () => {
expect(screen.queryByText('Generating response...')).not.toBeInTheDocument();
});
+ it('prefers the selected model route over placeholder request-start progress', () => {
+ const startedAt = Date.now() - 1_000;
+ mockChat.isLoading.mockReturnValue(true);
+ mockChat.messages.mockReturnValue([
+ {
+ id: 'msg-1',
+ role: 'assistant' as const,
+ content: '',
+ timestamp: new Date(startedAt),
+ isStreaming: true,
+ streamEvents: [
+ {
+ type: 'model_switch',
+ model: 'openrouter:qwen/qwen3.7-plus',
+ modelEvent: 'selected',
+ startedAt,
+ updatedAt: startedAt,
+ },
+ {
+ type: 'workflow_status',
+ workflowStatus: {
+ phase: 'request_start',
+ message: 'Preparing Pulse context.',
+ startedAt,
+ },
+ startedAt,
+ updatedAt: startedAt + 50,
+ },
+ ],
+ workflowStatus: {
+ phase: 'request_start',
+ message: 'Preparing Pulse context.',
+ startedAt,
+ },
+ },
+ ]);
+ renderChat();
+
+ const status = screen.getByLabelText('Assistant active turn status');
+ expect(status).toHaveTextContent('Using Qwen: Qwen3.7 Plus via OpenRouter');
+ expect(status).not.toHaveTextContent('Preparing Pulse context.');
+ });
+
it('shows the latest burst workflow progress immediately in the active turn status footer', () => {
const [isLoading, setIsLoading] = createSignal(false);
const [messages, setMessages] = createSignal<ChatMessage[]>([]);
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 2bbe1c8737..b7f99db69c 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/MessageItem.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/MessageItem.test.tsx
@@ -844,6 +844,49 @@ describe('MessageItem', () => {
).toHaveTextContent('Using Qwen 3.7 Plus via OpenRouter');
});
+ it('hides placeholder request-start rows once the selected model route is visible', () => {
+ const events: StreamDisplayEvent[] = [
+ {
+ type: 'model_switch',
+ model: 'openrouter:qwen/qwen3.7-plus',
+ modelEvent: 'selected',
+ startedAt: 1_000,
+ updatedAt: 1_000,
+ },
+ {
+ type: 'workflow_status',
+ workflowStatus: {
+ phase: 'request_start',
+ message: 'Preparing Pulse context.',
+ startedAt: 1_000,
+ },
+ startedAt: 1_000,
+ updatedAt: 1_050,
+ },
+ ];
+
+ render(() => (
+ <MessageItem
+ message={makeMessage({
+ role: 'assistant',
+ content: '',
+ isStreaming: true,
+ streamEvents: events,
+ workflowStatus: events[1].workflowStatus,
+ })}
+ getModelRouteLabel={(model) =>
+ model === 'openrouter:qwen/qwen3.7-plus' ? 'Qwen 3.7 Plus via OpenRouter' : model
+ }
+ {...makeHandlers()}
+ />
+ ));
+
+ expect(
+ screen.getByRole('status', { name: 'Assistant model route selected' }),
+ ).toHaveTextContent('Using Qwen 3.7 Plus via OpenRouter');
+ expect(screen.queryByText('Preparing Pulse context.')).not.toBeInTheDocument();
+ });
+
it('renders provider fallback model switches with failed and next routes', () => {
const events: StreamDisplayEvent[] = [
{
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 df17b36224..77fcbe4503 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/activeTurnStatus.test.ts
+++ b/frontend-modern/src/components/AI/Chat/__tests__/activeTurnStatus.test.ts
@@ -116,6 +116,48 @@ describe('getAssistantActiveTurnStatus', () => {
});
});
+ it('prefers the selected model route over the generic request-start status', () => {
+ const startedAt = Date.now() - 1_000;
+ expect(
+ getAssistantActiveTurnStatus(
+ [
+ assistantMessage({
+ isStreaming: true,
+ workflowStatus: {
+ phase: 'request_start',
+ message: 'Preparing Pulse context.',
+ startedAt,
+ },
+ streamEvents: [
+ {
+ type: 'model_switch',
+ model: 'openrouter:qwen/qwen3.7-plus',
+ modelEvent: 'selected',
+ startedAt,
+ updatedAt: startedAt,
+ },
+ {
+ type: 'workflow_status',
+ workflowStatus: {
+ phase: 'request_start',
+ message: 'Preparing Pulse context.',
+ startedAt,
+ },
+ startedAt,
+ updatedAt: startedAt + 50,
+ },
+ ],
+ }),
+ ],
+ true,
+ ),
+ ).toEqual({
+ type: 'thinking',
+ text: 'Using Qwen: Qwen3.7 Plus via OpenRouter',
+ startedAt,
+ });
+ });
+
it('surfaces provider retry attempt and backoff metadata in the active footer', () => {
const startedAt = Date.now() - 2_000;
expect(
diff --git a/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts b/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
index e742ee4a7c..a3824eb018 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
+++ b/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
@@ -280,6 +280,42 @@ describe('useChat', () => {
dispose();
});
+ it('shows the selected model route immediately while the first backend event is pending', async () => {
+ let resolveChat!: () => void;
+ mockChat.mockReturnValue(
+ new Promise<void>((resolve) => {
+ resolveChat = resolve;
+ }),
+ );
+
+ const { value: chat, dispose } = withRoot(() =>
+ useChat({ defaultModel: () => 'openrouter:qwen/qwen3.7-plus' }),
+ );
+ const result = chat.sendMessage('hello');
+
+ const assistant = chat.messages()[1];
+ expect(assistant).toMatchObject({
+ role: 'assistant',
+ model: 'openrouter:qwen/qwen3.7-plus',
+ isStreaming: true,
+ workflowStatus: {
+ phase: 'request_start',
+ message: 'Preparing Pulse context.',
+ },
+ });
+ expect(assistant.streamEvents).toEqual([
+ expect.objectContaining({
+ type: 'model_switch',
+ model: 'openrouter:qwen/qwen3.7-plus',
+ modelEvent: 'selected',
+ }),
+ ]);
+
+ resolveChat();
+ await result;
+ dispose();
+ });
+
it('reuses existing session', async () => {
mockChat.mockResolvedValue(undefined);
@@ -1222,17 +1258,24 @@ describe('useChat', () => {
retryAfterMs: 200,
}),
);
- expect(assistant.streamEvents).toEqual([
- expect.objectContaining({
- type: 'workflow_status',
- workflowStatus: expect.objectContaining({
- phase: 'provider_retry',
- attempt: 2,
- maxAttempts: 2,
- retryAfterMs: 200,
+ expect(assistant.streamEvents).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({
+ type: 'model_switch',
+ model: 'openrouter:openai/gpt-4o-mini',
+ modelEvent: 'selected',
}),
- }),
- ]);
+ expect.objectContaining({
+ type: 'workflow_status',
+ workflowStatus: expect.objectContaining({
+ phase: 'provider_retry',
+ attempt: 2,
+ maxAttempts: 2,
+ retryAfterMs: 200,
+ }),
+ }),
+ ]),
+ );
dispose();
});
diff --git a/frontend-modern/src/components/AI/Chat/activeTurnStatus.ts b/frontend-modern/src/components/AI/Chat/activeTurnStatus.ts
index 9dbeeccf74..7f12f8aa3e 100644
--- a/frontend-modern/src/components/AI/Chat/activeTurnStatus.ts
+++ b/frontend-modern/src/components/AI/Chat/activeTurnStatus.ts
@@ -18,6 +18,7 @@ export interface AssistantActiveTurnStatus {
interface AssistantActiveTurnStatusCandidate extends AssistantActiveTurnStatus {
activityAt?: number;
+ placeholder?: boolean;
order: number;
}
@@ -183,6 +184,9 @@ const isFresherStatusCandidate = (
current: AssistantActiveTurnStatusCandidate | null,
): boolean => {
if (!current) return true;
+ if (candidate.placeholder !== current.placeholder) {
+ return current.placeholder === true;
+ }
const candidateTime = candidate.activityAt;
const currentTime = current.activityAt;
if (candidateTime !== undefined && currentTime !== undefined && candidateTime !== currentTime) {
@@ -239,6 +243,7 @@ const latestStreamActivityStatus = (
text,
startedAt: event.workflowStatus?.startedAt || event.startedAt,
activityAt: eventActivityAt(event),
+ placeholder: isInitialRequestStartStatus(event.workflowStatus),
order: index,
};
}
@@ -317,6 +322,9 @@ const workflowStatusCandidate = (
};
};
+export const isInitialRequestStartStatus = (status?: WorkflowStatus): boolean =>
+ status?.phase === 'request_start';
+
const modelSwitchStatusText = (event: StreamDisplayEvent): string => {
const model = event.model?.trim();
if (!model) return '';
@@ -369,7 +377,10 @@ export const getAssistantActiveTurnStatus = (
}
if (assistantMessage.isStreaming !== false) {
const workflowCandidate = workflowStatusCandidate(assistantMessage.workflowStatus);
- if (workflowCandidate) {
+ if (
+ workflowCandidate &&
+ !(isInitialRequestStartStatus(assistantMessage.workflowStatus) && eventStatusCandidate)
+ ) {
statusCandidates.push(workflowCandidate);
}
}
diff --git a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
index 63483c138e..a86e3eaba0 100644
--- a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
+++ b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
@@ -33,10 +33,10 @@ const generateId = () => Math.random().toString(36).substring(2, 9);
type AssistantInterruption = NonNullable<ChatMessage['interruption']>;
const WORKFLOW_STATUS_HISTORY_LIMIT = 8;
-const createInitialAssistantWorkflowStatus = (): WorkflowStatus => ({
+const createInitialAssistantWorkflowStatus = (startedAt = Date.now()): WorkflowStatus => ({
phase: 'request_start',
message: 'Preparing Pulse context.',
- startedAt: Date.now(),
+ startedAt,
});
export interface UseChatOptions {
@@ -1593,26 +1593,39 @@ export function useChat(options: UseChatOptions = {}) {
// Echo the user's message before any network work. Cold sessions can spend
// noticeable time creating the server-side session; the chat surface should
// still feel immediate.
+ const turnStartedAt = Date.now();
const userMessage: ChatMessage = {
id: options?.queuedMessageId || generateId(),
role: 'user',
content: trimmedPrompt,
- timestamp: new Date(),
+ timestamp: new Date(turnStartedAt),
request: buildRequestContext(mentions, findingId, requestSendOptions),
};
const assistantId = generateId();
- const initialWorkflowStatus = createInitialAssistantWorkflowStatus();
+ const initialWorkflowStatus = createInitialAssistantWorkflowStatus(turnStartedAt);
+ const initialStreamEvents: StreamDisplayEvent[] = requestModel
+ ? [
+ withStreamEventTiming(
+ {
+ type: 'model_switch',
+ model: requestModel,
+ modelEvent: 'selected',
+ },
+ turnStartedAt,
+ ),
+ ]
+ : [];
const streamingMessage: ChatMessage = {
id: assistantId,
role: 'assistant',
content: '',
- timestamp: new Date(),
+ timestamp: new Date(turnStartedAt),
model: requestModel || undefined,
isStreaming: true,
pendingTools: [],
toolCalls: [],
- streamEvents: [],
+ streamEvents: initialStreamEvents,
workflowStatus: initialWorkflowStatus,
workflowStatusHistory: [initialWorkflowStatus],
};