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 prompt send status

rcourtman7cf9b8121077
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 047bee8ce7..9099d1f465 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -625,7 +625,7 @@ deriving an older display status from `workflowStatusHistory`.
an opaque `output available` badge when a safe preview can be rendered.
If the UI enters a loading turn before the assistant shell or first
`workflow_state` exists, the active-turn footer must show the active startup
- status `Sending prompt` and derive elapsed time from the submitted, non-queued
+ status `Sending prompt.` and derive elapsed time from the submitted, non-queued
user turn or assistant shell timestamp. Queued follow-up messages must not
reset that active-turn startup clock. The same active-turn footer owns the
Stop affordance while a response is running, so interruption remains attached
@@ -2372,9 +2372,10 @@ maps `turn.send` and `turn.wait` to live footer status at lines 133-145, and
post-send periods to `waiting for assistant` at lines 1350-1357. Pulse keeps
that send/wait distinction in the live chat turn by promoting an unreplaced
local `request_send` status to local `request_wait` / `Waiting for assistant`
-before any backend-visible SSE activity arrives, while preserving the Pulse
-transcript rule that only backend workflow, route, content, and tool evidence
-remain once real activity exists.
+when the browser API client receives an open SSE response but before any parsed
+backend-visible SSE activity arrives, while preserving the Pulse transcript
+rule that only backend workflow, route, content, and tool evidence remain once
+real activity exists.
Assistant drawer shell status follows the same OpenCode-referenced separation
between prompt-adjacent operational status and transcript content. The
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 2f69836d8a..f067356496 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -134,6 +134,12 @@ retry fields, but `provider_fallback`, `failed_provider`, `failed_model`,
`next_provider`, and `next_model` are retired from the generated stream event
contract. Cross-route recovery belongs to explicit failed-turn actions, not
hidden `/api/ai/chat` stream mutation.
+The frontend chat stream client may expose a local stream-open lifecycle hook
+for UI state, but that hook is not a backend `workflow_state` payload. It must
+fire only after `/api/ai/chat` returns an OK event-stream response and before
+the first parsed SSE event is delivered to the reducer, allowing the Assistant
+drawer to promote local `request_send` status to local `request_wait` without
+inventing provider activity.
Assistant local stream fixtures are part of the same frontend API contract:
`frontend-modern/src/api/aiChatDevStreamFixture.ts` may short-circuit only
explicit `/fixture ...` prompts in development or test mode, must emit the same
diff --git a/frontend-modern/src/api/__tests__/aiChat.test.ts b/frontend-modern/src/api/__tests__/aiChat.test.ts
index 0c5bac6bde..bd5a98ba98 100644
--- a/frontend-modern/src/api/__tests__/aiChat.test.ts
+++ b/frontend-modern/src/api/__tests__/aiChat.test.ts
@@ -1007,6 +1007,52 @@ describe('AIChatAPI', () => {
expect(releaseLock).toHaveBeenCalledTimes(1);
});
+ it('notifies when the chat stream opens before delivering stream events', async () => {
+ const encoder = new TextEncoder();
+ const read = vi
+ .fn()
+ .mockResolvedValueOnce({
+ done: false,
+ value: encoder.encode('data: {"type":"content","data":{"text":"First"}}\n\n'),
+ })
+ .mockResolvedValueOnce({ done: true, value: undefined });
+ const releaseLock = vi.fn();
+ const order: string[] = [];
+ const onEvent = vi.fn((event: { type: string }) => {
+ order.push(event.type);
+ });
+ const onStreamOpen = vi.fn(() => {
+ order.push('stream-open');
+ });
+
+ apiFetchMock.mockResolvedValueOnce({
+ ok: true,
+ body: {
+ getReader: () => ({ read, releaseLock }),
+ },
+ } as unknown as Response);
+
+ await AIChatAPI.chat(
+ 'hello',
+ undefined,
+ undefined,
+ onEvent,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ undefined,
+ { onStreamOpen },
+ );
+
+ expect(onStreamOpen).toHaveBeenCalledOnce();
+ expect(order).toEqual(['stream-open', 'content', 'done']);
+ expect(releaseLock).toHaveBeenCalledTimes(1);
+ });
+
it('preserves safe handoff summaries on listed chat sessions', async () => {
const session = {
id: 'session-operator-briefing',
diff --git a/frontend-modern/src/api/aiChat.ts b/frontend-modern/src/api/aiChat.ts
index ea5ae2a4f9..10bbde738e 100644
--- a/frontend-modern/src/api/aiChat.ts
+++ b/frontend-modern/src/api/aiChat.ts
@@ -151,6 +151,10 @@ export interface ToolCall {
export type StreamEvent = AIChatStreamEvent;
+export interface AIChatStreamLifecycle {
+ onStreamOpen?: () => void;
+}
+
const AI_CHAT_STREAM_TEXT_PAINT_CHECKPOINT_INTERVAL = 4;
const AI_CHAT_STREAM_TEXT_EVENT_TYPES = new Set(['content', 'thinking']);
@@ -342,6 +346,7 @@ export class AIChatAPI {
handoffResources?: ChatHandoffResource[],
handoffActions?: ChatHandoffAction[],
handoffMetadata?: ChatHandoffMetadata,
+ lifecycle?: AIChatStreamLifecycle,
): Promise<void> {
logger.debug('[AI Chat] Starting chat stream', { prompt: prompt.substring(0, 50) });
@@ -393,6 +398,7 @@ export class AIChatAPI {
});
await assertAPIResponseOK(response, `Request failed with status ${response.status}`);
+ lifecycle?.onStreamOpen?.();
await consumeJSONEventStream<StreamEvent>(response, {
onEvent: (event) => {
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 bd4d98ff5b..966f139fda 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
@@ -5577,7 +5577,7 @@ describe('AIChat', () => {
]);
renderChat();
expect(screen.getByLabelText('Assistant active turn status')).toHaveTextContent(
- 'Sending prompt (4s)',
+ 'Sending prompt. (4s)',
);
});
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 0d663c20a3..db6f64e983 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/activeTurnStatus.test.ts
+++ b/frontend-modern/src/components/AI/Chat/__tests__/activeTurnStatus.test.ts
@@ -30,7 +30,7 @@ describe('getAssistantActiveTurnStatus', () => {
it('shows an active send state before the first assistant event arrives', () => {
expect(getAssistantActiveTurnStatus([], true)).toEqual({
type: 'thinking',
- text: 'Sending prompt',
+ text: 'Sending prompt.',
});
});
@@ -39,7 +39,7 @@ describe('getAssistantActiveTurnStatus', () => {
getAssistantActiveTurnStatus([userMessage({ timestamp: new Date(1_000) })], true, 4_000),
).toEqual({
type: 'thinking',
- text: 'Sending prompt',
+ text: 'Sending prompt.',
startedAt: 1_000,
});
});
@@ -61,7 +61,7 @@ describe('getAssistantActiveTurnStatus', () => {
),
).toEqual({
type: 'thinking',
- text: 'Sending prompt',
+ text: 'Sending prompt.',
queuedFollowUpCount: 1,
startedAt: 1_000,
});
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 a1c29a8984..dd609b835f 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
+++ b/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
@@ -47,6 +47,10 @@ const mockNotifyError = notificationStore.error as ReturnType<typeof vi.fn>;
type TestStreamEvent = StreamEvent | { type: string; data?: unknown };
type TestStreamDispatch = (event: TestStreamEvent) => void;
+type TestStreamLifecycle = { onStreamOpen?: () => void };
+
+const latestStreamLifecycle = (): TestStreamLifecycle | undefined =>
+ mockChat.mock.calls.at(-1)?.[12] as TestStreamLifecycle | undefined;
function dispatchTestStreamEvent(
onEvent: (event: StreamEvent) => void,
@@ -208,8 +212,8 @@ describe('useChat', () => {
pendingTools: [],
workflowStatusHistory: [],
workflowStatus: {
- phase: 'request_wait',
- message: 'Waiting for assistant.',
+ phase: 'request_send',
+ message: 'Sending prompt.',
},
});
expect(mockCreateSession).not.toHaveBeenCalled();
@@ -224,7 +228,7 @@ describe('useChat', () => {
dispose();
});
- it('starts a quiet sent prompt with local waiting status before backend activity arrives', async () => {
+ it('starts with local prompt-send status and promotes it when the stream opens', async () => {
vi.useFakeTimers();
vi.setSystemTime(1_000);
let resolveChat!: () => void;
@@ -241,24 +245,25 @@ describe('useChat', () => {
role: 'assistant',
isStreaming: true,
workflowStatus: {
- phase: 'request_wait',
- message: 'Waiting for assistant.',
+ phase: 'request_send',
+ message: 'Sending prompt.',
startedAt: 1_000,
},
});
await vi.advanceTimersByTimeAsync(899);
expect(chat.messages()[1].workflowStatus).toMatchObject({
- phase: 'request_wait',
- message: 'Waiting for assistant.',
+ phase: 'request_send',
+ message: 'Sending prompt.',
});
await vi.advanceTimersByTimeAsync(1);
+ latestStreamLifecycle()?.onStreamOpen?.();
expect(chat.messages()[1]).toMatchObject({
workflowStatus: {
phase: 'request_wait',
message: 'Waiting for assistant.',
- startedAt: 1_000,
+ startedAt: 1_900,
},
streamEvents: [
expect.objectContaining({
@@ -361,8 +366,8 @@ describe('useChat', () => {
isStreaming: true,
workflowStatusHistory: [],
workflowStatus: {
- phase: 'request_wait',
- message: 'Waiting for assistant.',
+ phase: 'request_send',
+ message: 'Sending prompt.',
provider: 'openrouter',
model: 'openrouter:qwen/qwen3.7-plus',
},
@@ -376,8 +381,8 @@ describe('useChat', () => {
expect.objectContaining({
type: 'workflow_status',
workflowStatus: expect.objectContaining({
- phase: 'request_wait',
- message: 'Waiting for assistant.',
+ phase: 'request_send',
+ message: 'Sending prompt.',
provider: 'openrouter',
model: 'openrouter:qwen/qwen3.7-plus',
}),
@@ -406,13 +411,22 @@ describe('useChat', () => {
const assistant = chat.messages()[1];
expect(assistant.workflowStatus).toMatchObject({
+ phase: 'request_send',
+ message: 'Sending prompt.',
+ provider: 'openrouter',
+ model: 'openrouter:qwen/qwen3.7-plus',
+ startedAt: 2_000,
+ });
+ latestStreamLifecycle()?.onStreamOpen?.();
+ const openedAssistant = chat.messages()[1];
+ expect(openedAssistant.workflowStatus).toMatchObject({
phase: 'request_wait',
message: 'Waiting for assistant.',
provider: 'openrouter',
model: 'openrouter:qwen/qwen3.7-plus',
startedAt: 2_000,
});
- expect(assistant.streamEvents).toEqual([
+ expect(openedAssistant.streamEvents).toEqual([
expect.objectContaining({
type: 'model_switch',
model: 'openrouter:qwen/qwen3.7-plus',
@@ -1076,7 +1090,17 @@ describe('useChat', () => {
_session: string,
_model: string | undefined,
onEvent: (e: StreamEvent) => void,
+ _signal?: AbortSignal,
+ _mentions?: ChatMention[],
+ _findingId?: string,
+ _autonomousMode?: boolean,
+ _handoffContext?: string,
+ _handoffResources?: unknown[],
+ _handoffActions?: unknown[],
+ _handoffMetadata?: unknown,
+ lifecycle?: TestStreamLifecycle,
) => {
+ lifecycle?.onStreamOpen?.();
fireEvent = (event) => dispatchTestStreamEvent(onEvent, event);
return Promise.resolve();
},
diff --git a/frontend-modern/src/components/AI/Chat/activeTurnStatus.ts b/frontend-modern/src/components/AI/Chat/activeTurnStatus.ts
index be353433fb..5fafb49edd 100644
--- a/frontend-modern/src/components/AI/Chat/activeTurnStatus.ts
+++ b/frontend-modern/src/components/AI/Chat/activeTurnStatus.ts
@@ -529,7 +529,7 @@ const workflowStatusCandidate = (
};
export const isInitialRequestStartStatus = (status?: WorkflowStatus): boolean =>
- status?.phase === 'request_start';
+ status?.phase === 'request_start' || status?.phase === 'request_send';
const modelSwitchStatusText = (event: StreamDisplayEvent): string => {
const model = event.model?.trim();
@@ -584,7 +584,7 @@ const initialRequestStatus = (
const startedAt = activeTurnStartedAt(messages, assistantMessage);
return {
type: 'thinking',
- text: 'Sending prompt',
+ text: 'Sending prompt.',
...(startedAt !== undefined ? { startedAt } : {}),
};
};
diff --git a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
index ed5b03103c..bb620fb941 100644
--- a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
+++ b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
@@ -77,7 +77,19 @@ const routeAwareWorkflowStatusFields = (modelRoute?: string) => {
};
};
-const createAssistantRouteStartWorkflowStatus = (
+const createAssistantRouteSendWorkflowStatus = (
+ modelRoute?: string,
+ startedAt = Date.now(),
+): WorkflowStatus => {
+ return {
+ phase: 'request_send',
+ message: 'Sending prompt.',
+ ...routeAwareWorkflowStatusFields(modelRoute),
+ startedAt,
+ };
+};
+
+const createAssistantRouteWaitWorkflowStatus = (
modelRoute?: string,
startedAt = Date.now(),
): WorkflowStatus => {
@@ -204,6 +216,9 @@ export function useChat(options: UseChatOptions = {}) {
const isStreamIdleWorkflowStatus = (status?: WorkflowStatus) => status?.phase === 'stream_idle';
+ const isLocalPromptProgressStatus = (status?: WorkflowStatus) =>
+ status?.phase === 'request_send' || status?.phase === 'request_wait';
+
const workflowStatusProvider = (
message: Pick<ChatMessage, 'model' | 'workflowStatus'> | undefined,
status: WorkflowStatus | undefined,
@@ -275,8 +290,7 @@ export function useChat(options: UseChatOptions = {}) {
const isLocalPromptProgressEvent = (event: StreamDisplayEvent) =>
event.type === 'workflow_status' &&
- (event.workflowStatus?.phase === 'request_send' ||
- event.workflowStatus?.phase === 'request_wait');
+ isLocalPromptProgressStatus(event.workflowStatus);
const streamEventsWithoutLocalPromptProgressRows = (
events: StreamDisplayEvent[] | undefined,
@@ -295,6 +309,60 @@ export function useChat(options: UseChatOptions = {}) {
);
};
+ const replaceLocalPromptProgressEvent = (
+ events: StreamDisplayEvent[] | undefined,
+ workflowStatus: WorkflowStatus,
+ ): StreamDisplayEvent[] => {
+ const currentEvents = events || [];
+ const now = Date.now();
+ const nextEvent = withStreamEventTiming(
+ {
+ type: 'workflow_status',
+ workflowStatus,
+ startedAt: workflowStatus.startedAt,
+ updatedAt: workflowStatus.startedAt,
+ },
+ now,
+ );
+
+ for (let index = currentEvents.length - 1; index >= 0; index -= 1) {
+ const event = currentEvents[index];
+ if (event.type !== 'workflow_status') continue;
+ if (!isLocalPromptProgressStatus(event.workflowStatus)) break;
+ return [
+ ...currentEvents.slice(0, index),
+ {
+ ...nextEvent,
+ startedAt: nextEvent.startedAt || event.startedAt,
+ },
+ ...currentEvents.slice(index + 1),
+ ];
+ }
+
+ return [...currentEvents, nextEvent];
+ };
+
+ const promoteAssistantRouteWaitStatus = (
+ assistantId: string,
+ requestId: number,
+ modelRoute?: string,
+ ) => {
+ if (requestId !== activeRequestId) return;
+ const workflowStatus = createAssistantRouteWaitWorkflowStatus(modelRoute);
+ setMessages((prev) =>
+ prev.map((msg) => {
+ if (msg.id !== assistantId) return msg;
+ if (msg.isStreaming === false) return msg;
+ if (!isLocalPromptProgressStatus(msg.workflowStatus)) return msg;
+ return {
+ ...msg,
+ streamEvents: replaceLocalPromptProgressEvent(msg.streamEvents, workflowStatus),
+ workflowStatus,
+ };
+ }),
+ );
+ };
+
const cancelActiveRequest = (interruption?: AssistantInterruption): Promise<void> | null => {
const hasActiveRequest = isLoading() || abortControllerRef !== null;
if (!hasActiveRequest) return null;
@@ -1861,7 +1929,7 @@ export function useChat(options: UseChatOptions = {}) {
};
const assistantId = generateId();
- const initialWorkflowStatus = createAssistantRouteStartWorkflowStatus(
+ const initialWorkflowStatus = createAssistantRouteSendWorkflowStatus(
requestModel,
turnStartedAt,
);
@@ -1952,6 +2020,9 @@ export function useChat(options: UseChatOptions = {}) {
requestSendOptions?.handoffResources,
requestSendOptions?.handoffActions,
requestSendOptions?.handoffMetadata,
+ {
+ onStreamOpen: () => promoteAssistantRouteWaitStatus(assistantId, requestId, requestModel),
+ },
);
if (requestId !== activeRequestId) {
return false;
diff --git a/scripts/release_control/subsystem_lookup_test.py b/scripts/release_control/subsystem_lookup_test.py
index 295683521a..121bd6c38b 100644
--- a/scripts/release_control/subsystem_lookup_test.py
+++ b/scripts/release_control/subsystem_lookup_test.py
@@ -2860,7 +2860,7 @@ class SubsystemLookupTest(unittest.TestCase):
{
"heading": "## Shared Boundaries",
"path": "internal/api/access_control_handlers.go",
- "line": 440,
+ "line": 446,
"heading_line": 117,
}
],