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.

Add Assistant live wait heartbeat

rcourtman648e24182d52
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index e5b1e902bd..4f2157d8a5 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -2173,7 +2173,9 @@ referenced OpenCode source at fetched `dev` commit
maps `turn.send` and `turn.wait` to live footer status at lines 133-145, and
`packages/opencode/src/cli/cmd/run/stream.transport.ts` promotes quiet
post-send periods to `waiting for assistant` at lines 1350-1357. Pulse keeps
-that send/wait distinction in the live chat turn while preserving the Pulse
+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.
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 6c3588cc0b..360b5a4b2a 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -134,6 +134,11 @@ 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
typed stream event sequence as live chat, and must never open a provider request.
+Fixtures used for visible stream proof must pace status/tool/content events
+enough for the browser to paint the intermediate state, including keeping the
+`/fixture tool-burst` running tool row visible before the matching `tool_end`;
+unit tests may explicitly disable that pace, but the live dev fixture must not
+collapse to the terminal row.
Fixtures that emit consecutive context/read/query tool events must keep those
events as ordinary typed `tool_start` / `tool_end` activity and must not encode
obsolete grouped-context wording in fixture answer content. The fixture payload
@@ -1076,10 +1081,11 @@ the canonical monitored-system blocked payload.
Assistant chat stream workflow-state payloads are part of this same
frontend API-client boundary. `workflow_state` events must keep `phase`,
`message`, `state`, and `tool` stable, selected-route starts may carry
- `provider` and `model`, and provider fallback transitions may additionally
- carry `failed_provider`, `failed_model`, `next_provider`, and `next_model` so
- diagnostics can identify the exact route change without expanding the visible
- operator message. The selected-route `provider_start` message is operator
+ `provider` and `model`, and selected-route retry may carry `attempt`,
+ `max_attempts`, and `retry_after_ms`; automatic provider fallback metadata
+ (`provider_fallback`, `failed_provider`, `failed_model`, `next_provider`,
+ `next_model`) is retired from `/api/ai/chat` stream payloads. The
+ selected-route `provider_start` message is operator
progress copy and must be active/in-progress wording such as
`<Provider> is starting the response.` while the typed `provider` and `model`
fields carry the exact route identity. The generated
diff --git a/frontend-modern/src/api/__tests__/aiChat.test.ts b/frontend-modern/src/api/__tests__/aiChat.test.ts
index 747f6addbd..c8bbca9154 100644
--- a/frontend-modern/src/api/__tests__/aiChat.test.ts
+++ b/frontend-modern/src/api/__tests__/aiChat.test.ts
@@ -15,6 +15,7 @@ vi.mock('@/utils/logger', () => ({
}));
import { AIChatAPI, createAIChatStreamPaintCheckpointPredicate } from '@/api/aiChat';
+import { maybeRunAIChatDevStreamFixture } from '@/api/aiChatDevStreamFixture';
import { apiFetch, apiFetchJSON } from '@/utils/apiClient';
import { logger } from '@/utils/logger';
@@ -241,6 +242,62 @@ describe('AIChatAPI', () => {
});
});
+ it('keeps the tool-burst fixture running state visible when fixture pacing is enabled', async () => {
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
+ const onEvent = vi.fn();
+
+ const streamPromise = maybeRunAIChatDevStreamFixture({
+ prompt: '/fixture tool-burst',
+ model: 'openrouter:deepseek/deepseek-chat',
+ onEvent,
+ stepDelayMs: 25,
+ });
+
+ await flushMicrotasks();
+ expect(onEvent.mock.calls.map(([event]) => event.type)).toEqual(['session']);
+
+ await vi.advanceTimersByTimeAsync(25);
+ expect(onEvent.mock.calls.map(([event]) => event.type)).toEqual([
+ 'session',
+ 'workflow_state',
+ ]);
+
+ await vi.advanceTimersByTimeAsync(25);
+ expect(onEvent.mock.calls.map(([event]) => event.type)).toEqual([
+ 'session',
+ 'workflow_state',
+ 'workflow_state',
+ ]);
+
+ await vi.advanceTimersByTimeAsync(25);
+ expect(onEvent.mock.calls.map(([event]) => event.type)).toEqual([
+ 'session',
+ 'workflow_state',
+ 'workflow_state',
+ 'tool_start',
+ ]);
+
+ await vi.advanceTimersByTimeAsync(419);
+ expect(onEvent.mock.calls.map(([event]) => event.type)).toEqual([
+ 'session',
+ 'workflow_state',
+ 'workflow_state',
+ 'tool_start',
+ ]);
+
+ await vi.advanceTimersByTimeAsync(1);
+ expect(onEvent.mock.calls.map(([event]) => event.type)).toEqual([
+ 'session',
+ 'workflow_state',
+ 'workflow_state',
+ 'tool_start',
+ 'tool_end',
+ ]);
+
+ await vi.runAllTimersAsync();
+ await expect(streamPromise).resolves.toBe(true);
+ });
+
it('runs the send-hold dev stream fixture without opening a provider request', async () => {
const onEvent = vi.fn();
diff --git a/frontend-modern/src/api/aiChatDevStreamFixture.ts b/frontend-modern/src/api/aiChatDevStreamFixture.ts
index 549d350534..9790ca62f1 100644
--- a/frontend-modern/src/api/aiChatDevStreamFixture.ts
+++ b/frontend-modern/src/api/aiChatDevStreamFixture.ts
@@ -31,6 +31,7 @@ const availableFixtureNames = AI_CHAT_DEV_STREAM_FIXTURE_PROMPTS.map((prompt) =>
const DEFAULT_DEV_FIXTURE_STEP_DELAY_MS = 140;
const TEST_FIXTURE_STEP_DELAY_MS = 0;
+const TOOL_BURST_RUNNING_VISIBLE_MS = 420;
export interface AIChatDevStreamFixtureOptions {
model?: string;
@@ -933,7 +934,9 @@ const fixtureStepDelay = (
}
if (normalizedPrompt === '/fixture pending-tool') return defaultDelayMs;
if (normalizedPrompt !== '/fixture tool-burst') return defaultDelayMs;
- if (event.type === 'tool_start') return 0;
+ if (event.type === 'tool_start') {
+ return Math.max(defaultDelayMs, TOOL_BURST_RUNNING_VISIBLE_MS);
+ }
return defaultDelayMs;
};
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 4829b7fccb..58b6a3e805 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
+++ b/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
@@ -223,6 +223,58 @@ describe('useChat', () => {
dispose();
});
+ it('promotes a quiet sent prompt to a local waiting status before backend activity arrives', async () => {
+ vi.useFakeTimers();
+ vi.setSystemTime(1_000);
+ let resolveChat!: () => void;
+ mockChat.mockReturnValue(
+ new Promise<void>((resolve) => {
+ resolveChat = resolve;
+ }),
+ );
+
+ const { value: chat, dispose } = withRoot(() => useChat());
+ const result = chat.sendMessage('test');
+
+ expect(chat.messages()[1]).toMatchObject({
+ role: 'assistant',
+ isStreaming: true,
+ workflowStatus: {
+ phase: 'request_send',
+ message: 'Sending prompt.',
+ startedAt: 1_000,
+ },
+ });
+
+ await vi.advanceTimersByTimeAsync(899);
+ expect(chat.messages()[1].workflowStatus).toMatchObject({
+ phase: 'request_send',
+ message: 'Sending prompt.',
+ });
+
+ await vi.advanceTimersByTimeAsync(1);
+ expect(chat.messages()[1]).toMatchObject({
+ workflowStatus: {
+ phase: 'request_wait',
+ message: 'Waiting for assistant.',
+ startedAt: 1_000,
+ },
+ streamEvents: [
+ expect.objectContaining({
+ type: 'workflow_status',
+ workflowStatus: expect.objectContaining({
+ phase: 'request_wait',
+ message: 'Waiting for assistant.',
+ }),
+ }),
+ ],
+ });
+
+ resolveChat();
+ await result;
+ dispose();
+ });
+
it('clears the visible active turn before conversation refresh finishes', async () => {
let resolveRefresh!: () => void;
let sendResolved = false;
diff --git a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
index 44f7240587..c3cb672af6 100644
--- a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
+++ b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
@@ -34,6 +34,7 @@ import type {
const generateId = () => Math.random().toString(36).substring(2, 9);
type AssistantInterruption = NonNullable<ChatMessage['interruption']>;
const WORKFLOW_STATUS_HISTORY_LIMIT = 8;
+const LOCAL_ASSISTANT_WAIT_STATUS_DELAY_MS = 900;
const latestExplicitModelRouteFromTranscript = (messages: ChatMessage[]): string => {
for (let index = messages.length - 1; index >= 0; index -= 1) {
@@ -58,6 +59,12 @@ const createInitialAssistantWorkflowStatus = (startedAt = Date.now()): WorkflowS
startedAt,
});
+const createLocalAssistantWaitWorkflowStatus = (startedAt = Date.now()): WorkflowStatus => ({
+ phase: 'request_wait',
+ message: 'Waiting for assistant.',
+ startedAt,
+});
+
export interface UseChatOptions {
sessionId?: string;
model?: string;
@@ -124,6 +131,13 @@ export function useChat(options: UseChatOptions = {}) {
let abortControllerRef: AbortController | null = null;
let activeRequestId = 0;
let pendingBackendAbort: Promise<void> | null = null;
+ let localAssistantWaitStatusTimer: ReturnType<typeof setTimeout> | undefined;
+
+ const clearLocalAssistantWaitStatusTimer = () => {
+ if (localAssistantWaitStatusTimer === undefined) return;
+ clearTimeout(localAssistantWaitStatusTimer);
+ localAssistantWaitStatusTimer = undefined;
+ };
let isDrainingQueuedFollowUps = false;
const suppressedRawContentMessageIds = new Set<string>();
const outputArtifactStreamStates = new Map<string, AssistantOutputArtifactStreamState>();
@@ -251,6 +265,7 @@ export function useChat(options: UseChatOptions = {}) {
abortControllerRef.abort();
abortControllerRef = null;
}
+ clearLocalAssistantWaitStatusTimer();
activeRequestId += 1;
setMessages((prev) =>
@@ -1833,9 +1848,31 @@ export function useChat(options: UseChatOptions = {}) {
abortControllerRef = abortController;
let visibleTurnCompleted = false;
+ const promoteLocalWaitStatus = () => {
+ localAssistantWaitStatusTimer = undefined;
+ if (requestId !== activeRequestId) return;
+ const waitStatus = createLocalAssistantWaitWorkflowStatus(turnStartedAt);
+ setMessages((prev) =>
+ prev.map((msg) => {
+ if (msg.id !== assistantId) return msg;
+ if (msg.isStreaming === false) return msg;
+ if (msg.workflowStatus?.phase !== 'request_send') return msg;
+ const updated = withWorkflowStatusEvent(msg, waitStatus);
+ return { ...updated, workflowStatus: waitStatus };
+ }),
+ );
+ };
+
+ clearLocalAssistantWaitStatusTimer();
+ localAssistantWaitStatusTimer = setTimeout(
+ promoteLocalWaitStatus,
+ LOCAL_ASSISTANT_WAIT_STATUS_DELAY_MS,
+ );
+
const completeVisibleTurn = () => {
if (requestId !== activeRequestId || visibleTurnCompleted) return;
visibleTurnCompleted = true;
+ clearLocalAssistantWaitStatusTimer();
abortControllerRef = null;
setIsLoading(false);
if (options?.drainAfter !== false) {
@@ -1851,6 +1888,9 @@ export function useChat(options: UseChatOptions = {}) {
currentSessionId || undefined,
requestModel || undefined,
(event: StreamEvent) => {
+ if (event.type !== 'session') {
+ clearLocalAssistantWaitStatusTimer();
+ }
processEvent(assistantId, requestId, event);
},
abortController.signal,
diff --git a/scripts/release_control/subsystem_lookup_test.py b/scripts/release_control/subsystem_lookup_test.py
index 216215ae72..842da8eb9b 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": 427,
+ "line": 432,
"heading_line": 117,
}
],