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.

Make Assistant new chat a local reset

rcourtmancd24716f903e
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 626699edfa..5d1a3cc66e 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -1200,6 +1200,12 @@ chat runtime binds its active session from that stream event, with `done` and
payloads, rather than issuing a separate `/api/ai/sessions` preflight before
the first user message. Explicit session-management actions may still create a
session through the session endpoint.
+The Assistant drawer's `New` action is a local blank-conversation reset, not a
+backend session creation. It must clear the active transcript, scoped handoff
+context, and browser session ID immediately, leave the model selection intact,
+and avoid adding empty conversations to the session list; the next submitted
+message materializes the durable session through the stream-owned cold-start
+contract above.
The AI transport files are shared with `api-contracts`, not delegated away to
it. `frontend-modern/src/api/ai.ts`,
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 d492ef407d..63c4e5a0e5 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
@@ -24,13 +24,7 @@ const {
stop: vi.fn(),
clearMessages: vi.fn(),
loadSession: vi.fn().mockResolvedValue(true),
- newSession: vi.fn().mockResolvedValue({
- id: 'new-sess',
- title: '',
- created_at: '',
- updated_at: '',
- message_count: 0,
- }),
+ newSession: vi.fn().mockResolvedValue(true),
updateApproval: vi.fn(),
addToolResult: vi.fn(),
updateQuestion: vi.fn(),
@@ -777,7 +771,7 @@ describe('AIChat', () => {
// ── Session management ───────────────────────────────────────────────
describe('session management', () => {
- it('creates a new session on New button click', async () => {
+ it('starts a blank conversation on New button click', async () => {
renderChat();
fireEvent.click(screen.getByText('New'));
await waitFor(() => {
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 fa569c2f6a..0cfbbfa029 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
+++ b/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
@@ -1198,14 +1198,7 @@ describe('useChat', () => {
// newSession
// ──────────────────────────────────────────────
describe('newSession', () => {
- it('creates session and clears messages', async () => {
- mockCreateSession.mockResolvedValue({
- id: 'new-sess-99',
- title: '',
- created_at: '',
- updated_at: '',
- message_count: 0,
- });
+ it('starts a blank conversation without precreating a backend session', async () => {
mockChat.mockResolvedValue(undefined);
const onConversationChanged = vi.fn();
@@ -1216,22 +1209,11 @@ describe('useChat', () => {
const session = await chat.newSession();
- expect(session).toBeDefined();
- expect(session!.id).toBe('new-sess-99');
- expect(chat.sessionId()).toBe('new-sess-99');
+ expect(session).toBe(true);
+ expect(mockCreateSession).not.toHaveBeenCalled();
+ expect(chat.sessionId()).toBe('');
expect(chat.messages()).toEqual([]);
- expect(onConversationChanged).toHaveBeenCalledTimes(2);
- dispose();
- });
-
- it('returns null on failure and notifies', async () => {
- mockCreateSession.mockRejectedValue(new Error('fail'));
-
- const { value: chat, dispose } = withRoot(() => useChat());
- const session = await chat.newSession();
-
- expect(session).toBeNull();
- expect(mockNotifyError).toHaveBeenCalledWith('Failed to create session');
+ expect(onConversationChanged).toHaveBeenCalledTimes(1);
dispose();
});
});
diff --git a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
index b9b68b4e07..df02f0ff07 100644
--- a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
+++ b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
@@ -670,20 +670,13 @@ export function useChat(options: UseChatOptions = {}) {
}
};
- // Create new session
- const newSession = async () => {
+ // Start a blank conversation. The durable backend session is created by the
+ // next chat stream so the UI does not create empty server-side sessions.
+ const newSession = async (): Promise<boolean> => {
void cancelActiveRequest(false);
- try {
- const session = await AIChatAPI.createSession();
- setSessionId(session.id);
- setMessages([]);
- await notifyConversationChanged();
- return session;
- } catch (error) {
- logger.error('[useChat] Failed to create session:', error);
- notificationStore.error('Failed to create session');
- return null;
- }
+ setSessionId('');
+ setMessages([]);
+ return true;
};
// Update pending approval state (e.g., to mark as executing or remove)
diff --git a/frontend-modern/src/components/AI/Chat/index.tsx b/frontend-modern/src/components/AI/Chat/index.tsx
index 26c0f1f87a..3d5fa47f23 100644
--- a/frontend-modern/src/components/AI/Chat/index.tsx
+++ b/frontend-modern/src/components/AI/Chat/index.tsx
@@ -1057,8 +1057,8 @@ export const AIChat: Component<AIChatProps> = (props) => {
// New conversation
const handleNewConversation = async () => {
- const session = await chat.newSession();
- if (!session) return;
+ const started = await chat.newSession();
+ if (!started) return;
aiChatStore.clearContext?.();
setShowSessions(false);
};