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 handoff payloads one-shot

rcourtmanead83d19bad8
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 04bd92adbc..390c0b0fe4 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -295,6 +295,13 @@ runtime cost control, and shared AI transport surfaces.
The Assistant drawer must also fetch that current session list before
opening the session picker instead of presenting mount-time cached
summaries as the operator's decision surface.
+ Browser-originated `handoff_context`, `handoff_resources`, and
+ `handoff_actions` are one-shot request seeds for the first successful chat
+ turn. After that send succeeds, the drawer must clear those request payloads
+ while preserving the safe visible briefing and request-local
+ approval-required posture; later turns must rely on backend-owned session
+ model-context hydration and current canonical stores instead of resending
+ stale browser handoff payloads.
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/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index ae11ef502d..8297606513 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -181,7 +181,12 @@ work extends shared components instead of creating new local variants.
`handoff_summary` presentation state from the session list. Loading a plain
session or starting a new conversation must clear stale scoped handoff
briefing state so Patrol and alert context does not visually leak between
- conversations.
+ conversations. Browser-originated model handoff payloads are one-shot
+ request seeds: after the first successful chat send, this store must clear
+ `handoffContext`, `handoffResources`, and `handoffActions` while preserving
+ the safe visible briefing and scoped approval-required posture, so later
+ turns rely on backend session hydration instead of resending stale browser
+ context.
9. `frontend-modern/src/utils/platformSupportManifest.generated.ts` shared with `unified-resources`: the generated platform support projection is both a canonical unified-resource platform union boundary and a shared frontend source/platform vocabulary boundary.
10. `frontend-modern/src/utils/sourcePlatforms.ts` shared with `unified-resources`: the source platform normalizer is both a canonical unified-resource source adapter boundary and a shared frontend source/platform vocabulary boundary.
That shared boundary must preserve `availability` as the agentless
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 3944e1f527..37d42e8a3c 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
@@ -122,7 +122,19 @@ const {
mockAiChatStore.context = emptyChatContext();
}),
clearInitialPrompt: vi.fn(),
- clearFindingId: vi.fn(),
+ clearFindingId: vi.fn(() => {
+ const { findingId: _findingId, ...rest } = mockAiChatStore.context;
+ mockAiChatStore.context = rest;
+ }),
+ clearRequestHandoffPayload: vi.fn(() => {
+ const {
+ handoffContext: _handoffContext,
+ handoffResources: _handoffResources,
+ handoffActions: _handoffActions,
+ ...rest
+ } = mockAiChatStore.context;
+ mockAiChatStore.context = rest;
+ }),
};
const mockByType = vi.fn((_type: string): Array<{ name: string }> => []);
@@ -1400,6 +1412,71 @@ describe('AIChat', () => {
},
);
});
+
+ it('clears request handoff payloads after the first successful turn', async () => {
+ mockAIAPI.getSettings.mockResolvedValue({
+ model: 'gpt-4',
+ chat_model: '',
+ control_level: 'autonomous',
+ autonomous_mode: true,
+ discovery_enabled: true,
+ });
+ mockAiChatStore.context = {
+ initialPrompt: undefined,
+ findingId: 'finding-1',
+ autonomousMode: false,
+ handoffContext: '[Patrol Finding Context]\nFinding ID: finding-1',
+ handoffResources: [
+ {
+ id: 'host:web-server',
+ name: 'web-server',
+ type: 'host',
+ node: 'pve-1',
+ },
+ ],
+ handoffActions: [
+ {
+ findingId: 'finding-1',
+ approvalId: 'approval-1',
+ approvalStatus: 'pending',
+ },
+ ],
+ briefing: {
+ sourceLabel: 'Pulse Patrol',
+ title: 'Patrol finding on web-server',
+ },
+ };
+
+ renderChat();
+
+ const textarea = screen.getByPlaceholderText('Ask about your infrastructure...');
+ fireEvent.input(textarea, { target: { value: 'what happened here?' } });
+ fireEvent.keyDown(textarea, { key: 'Enter' });
+
+ await waitFor(() => {
+ expect(mockAiChatStore.clearFindingId).toHaveBeenCalledTimes(1);
+ expect(mockAiChatStore.clearRequestHandoffPayload).toHaveBeenCalledTimes(1);
+ });
+ expect(mockAiChatStore.context.findingId).toBeUndefined();
+ expect(mockAiChatStore.context.handoffContext).toBeUndefined();
+ expect(mockAiChatStore.context.handoffResources).toBeUndefined();
+ expect(mockAiChatStore.context.handoffActions).toBeUndefined();
+ expect(mockAiChatStore.context.autonomousMode).toBe(false);
+ expect(mockAiChatStore.context.briefing?.title).toBe('Patrol finding on web-server');
+
+ fireEvent.input(textarea, { target: { value: 'what changed next?' } });
+ fireEvent.keyDown(textarea, { key: 'Enter' });
+
+ await waitFor(() => {
+ expect(mockChat.sendMessage).toHaveBeenCalledTimes(2);
+ });
+ expect(mockChat.sendMessage).toHaveBeenLastCalledWith(
+ 'what changed next?',
+ undefined,
+ undefined,
+ { autonomousMode: false },
+ );
+ });
});
// ── Discovery hint ───────────────────────────────────────────────────
diff --git a/frontend-modern/src/components/AI/Chat/index.tsx b/frontend-modern/src/components/AI/Chat/index.tsx
index 7523d290f8..799a7fbfae 100644
--- a/frontend-modern/src/components/AI/Chat/index.tsx
+++ b/frontend-modern/src/components/AI/Chat/index.tsx
@@ -817,10 +817,18 @@ export const AIChat: Component<AIChatProps> = (props) => {
const sendPromise = hasSendOptions
? chat.sendMessage(prompt, mentionsForAPI, findingId, sendOptions)
: chat.sendMessage(prompt, mentionsForAPI, findingId);
+ const hasRequestHandoffPayload =
+ Boolean(ctx.handoffContext?.trim()) ||
+ Boolean(ctx.handoffResources?.length) ||
+ Boolean(ctx.handoffActions?.length);
sendPromise.then((ok) => {
- if (ok && findingId) {
+ if (!ok) return;
+ if (findingId) {
aiChatStore.clearFindingId?.();
}
+ if (hasRequestHandoffPayload) {
+ aiChatStore.clearRequestHandoffPayload?.();
+ }
});
setInput('');
setAccumulatedMentions([]);
diff --git a/frontend-modern/src/stores/__tests__/aiChat.test.ts b/frontend-modern/src/stores/__tests__/aiChat.test.ts
index 75d3772ab9..b70d6f3635 100644
--- a/frontend-modern/src/stores/__tests__/aiChat.test.ts
+++ b/frontend-modern/src/stores/__tests__/aiChat.test.ts
@@ -168,6 +168,33 @@ describe('aiChatStore', () => {
]);
});
+ it('clears request handoff payloads while preserving safe visible context', () => {
+ aiChatStore.openWithPrompt('discuss this incident', {
+ targetType: 'storage',
+ targetId: 'storage-1',
+ autonomousMode: false,
+ findingId: 'finding-1',
+ briefing: {
+ sourceLabel: 'Pulse Patrol',
+ title: 'Patrol finding on tank',
+ },
+ handoffContext:
+ '[Alert Incident Context]\nTimeline Event 1: 2026-05-07T00:02:00Z | Command | Command event recorded',
+ handoffResources: [{ id: 'storage-1', name: 'tank', type: 'storage', node: 'nas-1' }],
+ handoffActions: [{ findingId: 'finding-1', approvalId: 'approval-1' }],
+ });
+
+ aiChatStore.clearRequestHandoffPayload();
+
+ expect(aiChatStore.context.handoffContext).toBeUndefined();
+ expect(aiChatStore.context.handoffResources).toBeUndefined();
+ expect(aiChatStore.context.handoffActions).toBeUndefined();
+ expect(aiChatStore.context.targetId).toBe('storage-1');
+ expect(aiChatStore.context.findingId).toBe('finding-1');
+ expect(aiChatStore.context.autonomousMode).toBe(false);
+ expect(aiChatStore.context.briefing?.title).toBe('Patrol finding on tank');
+ });
+
it('focusInput returns false when closed and true when open with a registered element', () => {
const textarea = document.createElement('textarea');
document.body.appendChild(textarea);
diff --git a/frontend-modern/src/stores/aiChat.ts b/frontend-modern/src/stores/aiChat.ts
index 2b37d31ec0..6fb2a92a7f 100644
--- a/frontend-modern/src/stores/aiChat.ts
+++ b/frontend-modern/src/stores/aiChat.ts
@@ -478,6 +478,23 @@ export const aiChatStore = {
});
},
+ // Clear one-shot request handoff payloads after the backend has persisted
+ // them as model-only session context.
+ clearRequestHandoffPayload() {
+ setAIChatContext((prev) => {
+ if (!prev.handoffContext && !prev.handoffResources?.length && !prev.handoffActions?.length) {
+ return prev;
+ }
+ const {
+ handoffContext: _handoffContext,
+ handoffResources: _handoffResources,
+ handoffActions: _handoffActions,
+ ...rest
+ } = prev;
+ return rest;
+ });
+ },
+
// Register the AI input element (called by AIChat component)
registerInput(ref: HTMLTextAreaElement | null) {
aiInputRef = ref;