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.

Keep restored Assistant handoffs approval-bound

rcourtmanb86051dd60b9
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 90ebe4f8ff..32966a903a 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -280,6 +280,12 @@ runtime cost control, and shared AI transport surfaces.
status, risk level, and timestamp, but it must not expose model-only
handoff text, action preflight/result bodies, remediation descriptions, raw
commands, or approval command payloads.
+ When the Assistant drawer restores any session from that `handoff_summary`,
+ it must restore the scoped request-local approval boundary as well as the
+ safe visible briefing: the next chat turn must carry
+ `autonomous_mode:false` even when the summary is context-only and has no
+ queued action, while the visible badge/action copy must still reflect the
+ actual last-known action state instead of inventing a pending approval.
Proposed-fix command text must stay out of both the persisted chat message
and the model-only handoff context, and command payloads remain
approval-context data, not conversational copy.
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 84f75de1b9..352e121561 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
@@ -658,6 +658,80 @@ describe('AIChat', () => {
expect(restoredContext.handoffActions).toBeUndefined();
});
+ it('keeps restored Patrol handoffs approval-bound without queued actions', async () => {
+ mockAIAPI.getSettings.mockResolvedValue({
+ model: 'gpt-4',
+ chat_model: '',
+ control_level: 'autonomous',
+ autonomous_mode: true,
+ discovery_enabled: true,
+ });
+ mockAIChatAPI.listSessions.mockResolvedValue([
+ {
+ id: 's-patrol-context',
+ title: 'Context-only Patrol follow-up',
+ created_at: '',
+ updated_at: '',
+ message_count: 2,
+ handoff_summary: {
+ kind: 'patrol_finding',
+ finding_id: 'finding-context-only',
+ has_model_context: true,
+ resource_count: 1,
+ primary_resource: {
+ id: 'host:web-server',
+ name: 'web-server',
+ type: 'host',
+ node: 'pve-1',
+ },
+ action_count: 0,
+ requires_approval: false,
+ },
+ },
+ ]);
+
+ renderChat();
+ await waitFor(() => {
+ expect(mockAIChatAPI.listSessions).toHaveBeenCalled();
+ });
+ fireEvent.click(screen.getByTitle('Pulse Assistant sessions'));
+
+ expect(screen.getByText('Pulse Patrol')).toBeInTheDocument();
+ expect(screen.getByText('Context attached')).toBeInTheDocument();
+
+ fireEvent.click(screen.getByText('Context-only Patrol follow-up'));
+
+ await waitFor(() => {
+ expect(mockChat.loadSession).toHaveBeenCalledWith('s-patrol-context');
+ expect(mockAiChatStore.setContext).toHaveBeenCalledWith(
+ expect.objectContaining({
+ findingId: 'finding-context-only',
+ autonomousMode: false,
+ context: expect.objectContaining({
+ actionCount: 0,
+ requiresApproval: false,
+ }),
+ briefing: expect.objectContaining({
+ sourceLabel: 'Pulse Patrol',
+ title: 'Patrol finding on web-server',
+ actionLabel: undefined,
+ }),
+ }),
+ );
+ });
+
+ const textarea = screen.getByPlaceholderText('Ask about your infrastructure...');
+ fireEvent.input(textarea, { target: { value: 'what changed?' } });
+ fireEvent.keyDown(textarea, { key: 'Enter' });
+
+ expect(mockChat.sendMessage).toHaveBeenCalledWith(
+ 'what changed?',
+ undefined,
+ 'finding-context-only',
+ { autonomousMode: false },
+ );
+ });
+
it('clears stale handoff context when loading a plain session', async () => {
mockAiChatStore.context = {
findingId: 'finding-old',
diff --git a/frontend-modern/src/components/AI/Chat/index.tsx b/frontend-modern/src/components/AI/Chat/index.tsx
index 5eeda9338c..ca03779528 100644
--- a/frontend-modern/src/components/AI/Chat/index.tsx
+++ b/frontend-modern/src/components/AI/Chat/index.tsx
@@ -128,7 +128,6 @@ const buildSessionHandoffContext = (session?: ChatSession): AIChatContext | unde
const actionCount = summary.action_count ?? 0;
const resourceCount = summary.resource_count ?? 0;
const findingId = summary.finding_id?.trim() || undefined;
- const requiresApproval = Boolean(summary.requires_approval || actionCount > 0);
const isPatrol = isPatrolSessionHandoff(summary);
const title = isPatrol
? resourceLabel
@@ -157,7 +156,7 @@ const buildSessionHandoffContext = (session?: ChatSession): AIChatContext | unde
updatedAt: summary.updated_at,
},
findingId,
- ...(requiresApproval ? { autonomousMode: false } : {}),
+ autonomousMode: false,
briefing: {
sourceLabel,
title,
diff --git a/tests/integration/tests/73-patrol-assistant-operator-briefing.spec.ts b/tests/integration/tests/73-patrol-assistant-operator-briefing.spec.ts
index 203668780c..32ed96d09f 100644
--- a/tests/integration/tests/73-patrol-assistant-operator-briefing.spec.ts
+++ b/tests/integration/tests/73-patrol-assistant-operator-briefing.spec.ts
@@ -75,6 +75,28 @@ test.describe("Patrol Assistant operator briefing", () => {
updated_at: "2026-05-06T12:08:00Z",
},
};
+ const contextOnlyHandoffSession = {
+ id: "session-context-only",
+ title: "Context-only Patrol follow-up",
+ created_at: "2026-05-06T12:02:00Z",
+ updated_at: "2026-05-06T12:09:00Z",
+ message_count: 1,
+ handoff_summary: {
+ kind: "patrol_finding",
+ finding_id: "finding-context-only",
+ has_model_context: true,
+ resource_count: 1,
+ primary_resource: {
+ id: "host:web-server",
+ name: "web-server",
+ type: "host",
+ node: "pve-1",
+ },
+ action_count: 0,
+ requires_approval: false,
+ updated_at: "2026-05-06T12:09:00Z",
+ },
+ };
await page.route("**/api/security/status", async (route) => {
await route.fulfill({
@@ -171,7 +193,7 @@ test.describe("Patrol Assistant operator briefing", () => {
await route.fulfill({
status: 200,
contentType: "application/json",
- body: JSON.stringify([handoffSession]),
+ body: JSON.stringify([handoffSession, contextOnlyHandoffSession]),
});
});
@@ -571,6 +593,23 @@ test.describe("Patrol Assistant operator briefing", () => {
reloadedAssistantContext.getByText("systemctl restart workload.service"),
).toHaveCount(0);
+ await page.getByTitle("Pulse Assistant sessions").click();
+ await expect(page.getByText("Context-only Patrol follow-up")).toBeVisible();
+ await expect(page.getByText("Context attached").last()).toBeVisible();
+ await page.getByText("Context-only Patrol follow-up").click();
+
+ const contextOnlyAssistantContext = page.getByLabel("Assistant context");
+ await expect(contextOnlyAssistantContext).toBeVisible();
+ await expect(contextOnlyAssistantContext).toContainText(
+ "Patrol finding on web-server",
+ );
+ await expect(contextOnlyAssistantContext).toContainText(
+ "Finding finding-context-only",
+ );
+ await expect(
+ contextOnlyAssistantContext.getByText("systemctl restart workload.service"),
+ ).toHaveCount(0);
+
includePendingApproval = false;
await page.reload({ waitUntil: "domcontentloaded" });
await expect(page.getByRole("button", { name: "Findings" })).toBeVisible();