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.

Clear stopped Assistant affordances

rcourtman5a92444eb9ef
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 44758a0b52..758ad4da0d 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -129,6 +129,17 @@ runtime cost control, and shared AI transport surfaces.
text, return focus to the composer, and render a neutral transcript marker
rather than persisting synthetic assistant answer text or surfacing the
interruption as a retryable provider failure.
+ The referenced OpenCode source at commit
+ `9ed17da55ab1f7360cc0e01075f763e27fa899e9` routes prompt interruption
+ through the prompt command in
+ `packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx`
+ (`session.interrupt`, lines 379-399) and handles stream interruption in
+ `packages/opencode/src/session/processor.ts` (`Effect.onInterrupt`, lines
+ 977-983; aborted tool state finalization, lines 888-915). Pulse adapts that
+ terminal active-part behavior by clearing unresolved pending tool,
+ approval, and question transcript rows on explicit Stop while preserving
+ already-streamed answer text and completed tool evidence before showing the
+ neutral stopped marker.
Composer prompt history is also drawer-local chat-runtime state: the drawer
may persist a bounded local history of submitted prompt text and structured
mentions for ArrowUp/ArrowDown recall, but that history must not persist or
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 b2899d123d..f2db335200 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
+++ b/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
@@ -1849,6 +1849,70 @@ describe('useChat', () => {
expect(mockChat).toHaveBeenCalledTimes(1);
dispose();
});
+
+ it('removes unresolved interactive stream rows when stopping', async () => {
+ let fireEvent!: TestStreamDispatch;
+ const abortError = new Error('Aborted');
+ abortError.name = 'AbortError';
+ mockChat.mockImplementation(
+ (
+ _prompt: string,
+ _session: string,
+ _model: string | undefined,
+ onEvent: (event: StreamEvent) => void,
+ signal?: AbortSignal,
+ ) => {
+ fireEvent = (event) => dispatchTestStreamEvent(onEvent, event);
+ return new Promise<void>((_resolve, reject) => {
+ signal?.addEventListener('abort', () => reject(abortError));
+ });
+ },
+ );
+
+ const { value: chat, dispose } = withRoot(() => useChat({ sessionId: 's' }));
+ const send = chat.sendMessage('hello');
+ await new Promise((r) => setTimeout(r, 0));
+
+ fireEvent({ type: 'content', data: 'partial response' });
+ fireEvent({ type: 'tool_start', data: { id: 'tool-1', name: 'pulse_read', input: '{}' } });
+ fireEvent({
+ type: 'approval_needed',
+ data: {
+ command: 'systemctl restart nginx',
+ tool_id: 'tool-2',
+ tool_name: 'pulse_control',
+ run_on_host: true,
+ approval_id: 'approval-1',
+ },
+ });
+ fireEvent({
+ type: 'question',
+ data: {
+ question_id: 'question-1',
+ questions: [{ id: 'target', question: 'Which node?' }],
+ },
+ });
+
+ let assistant = chat.messages().find((message) => message.role === 'assistant')!;
+ expect(assistant.streamEvents?.map((event) => event.type)).toEqual([
+ 'content',
+ 'pending_tool',
+ 'approval',
+ 'question',
+ ]);
+
+ chat.stop();
+ await expect(send).resolves.toBe(false);
+
+ assistant = chat.messages().find((message) => message.role === 'assistant')!;
+ expect(assistant.content).toBe('partial response');
+ expect(assistant.interruption).toBe('stopped');
+ expect(assistant.pendingTools).toEqual([]);
+ expect(assistant.pendingApprovals).toEqual([]);
+ expect(assistant.pendingQuestions).toEqual([]);
+ expect(assistant.streamEvents?.map((event) => event.type)).toEqual(['content']);
+ dispose();
+ });
});
// ──────────────────────────────────────────────
diff --git a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
index bfb5ee0bb7..ff7687a700 100644
--- a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
+++ b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
@@ -157,6 +157,17 @@ export function useChat(options: UseChatOptions = {}) {
return promise;
};
+ const streamEventsAfterInterruption = (
+ events: StreamDisplayEvent[] | undefined,
+ interruption?: AssistantInterruption,
+ ): StreamDisplayEvent[] | undefined => {
+ if (!interruption || !events) return events;
+ return events.filter(
+ (event) =>
+ event.type !== 'pending_tool' && event.type !== 'approval' && event.type !== 'question',
+ );
+ };
+
const cancelActiveRequest = (interruption?: AssistantInterruption): Promise<void> | null => {
const hasActiveRequest = isLoading() || abortControllerRef !== null;
if (!hasActiveRequest) return null;
@@ -179,6 +190,7 @@ export function useChat(options: UseChatOptions = {}) {
pendingTools: [],
pendingApprovals: [],
pendingQuestions: [],
+ streamEvents: streamEventsAfterInterruption(msg.streamEvents, interruption),
workflowStatus: undefined,
}
: msg,