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.

Carry structured Patrol actions into Assistant handoffs

rcourtmana66b80ceb911
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index a211f3c25a..b1d99987e2 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -1109,11 +1109,12 @@ resource, or action context, the backend-enforced `autonomous_mode:false`
clamp is Assistant action-governance, not agent readiness, fleet command
reachability, or enrollment health.
Scoped Assistant handoffs from alert or incident surfaces may also send
-bounded `handoff_context` and `handoff_resources` through `/api/ai/chat`
-without a `finding_id`; lifecycle-adjacent surfaces may treat those references
-as AI/runtime explanation context only, and must not reinterpret them as agent
-readiness, install status, command reachability, enrollment health, or fleet
-execution authority.
+bounded `handoff_context`, `handoff_resources`, and Patrol assessment
+`handoff_actions` through `/api/ai/chat` without a `finding_id`;
+lifecycle-adjacent surfaces may treat those references as AI/runtime
+explanation context only, and must not reinterpret them as agent readiness,
+install status, command reachability, enrollment health, fleet execution
+authority, or agent command grants.
That same shared `internal/api/` dependency also now assumes SSO test and
metadata-preview routes fail closed on validated outbound URL handling.
Lifecycle-adjacent setup and hosted bootstrap surfaces may depend on those
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index c7e42d795f..941635d9fc 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -1084,12 +1084,13 @@ only governed prompt/context data, but the submitted chat request must set
control-level setting, and disclose the temporary approval-required mode in
the drawer instead of showing the generic Autonomous warning.
Scoped Assistant handoffs that originate in owned product surfaces may also
-send bounded `handoff_context` text plus structured `handoff_resources` through
-`frontend-modern/src/api/aiChat.ts` and `/api/ai/chat`. That context is
-model-only session metadata, not saved user-authored message text, and the
-backend must clamp the exchange to approval-required mode whenever such scoped
-handoff context or resources are present. Patrol finding IDs remain stricter:
-when `finding_id` resolves, backend-refreshed durable Patrol context replaces
+send bounded `handoff_context` text, structured `handoff_resources`, and safe
+structured `handoff_actions` through `frontend-modern/src/api/aiChat.ts` and
+`/api/ai/chat`. That context is model-only session metadata, not saved
+user-authored message text, and the backend must clamp the exchange to
+approval-required mode whenever such scoped handoff context, resources, or
+action references are present. Patrol finding IDs remain stricter: when
+`finding_id` resolves, backend-refreshed durable Patrol context replaces
browser-supplied handoff text.
Direct alert-investigation runtime handoffs follow the same rule even when
they bypass the chat drawer. `/api/ai/investigate-alert` must set
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index f56ab2a2f0..c8ea56960d 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -456,8 +456,9 @@ the canonical monitored-system blocked payload.
verification, latest-run, supporting-context evidence, active-finding, and
resource reference context plus safe source-owned suggested prompts; active
finding entries may carry live pending Patrol approval posture only as safe
- approval ID/status/risk/target/request/expiry metadata and command counts
- instead of pasting page-local UI text or raw command payloads into chat
+ structured handoff actions with approval ID/status/risk/target/request/expiry
+ metadata, action plan identity/policy/expiry, dry-run posture, and command
+ counts instead of pasting page-local UI text or raw command payloads into chat
and that same Patrol investigation-context owner, so visible Assistant
drawer handoffs may include live pending-approval metadata only as safe
operator context: approval ID, status, risk, requested/expiry timestamps,
@@ -1866,13 +1867,15 @@ execution for that exchange, but the transport must treat the field as a
request override only and must not mutate the user's persistent AI control
setting.
The same chat payload boundary now carries scoped product handoff context:
-`handoff_context` is bounded model-only text and `handoff_resources` are
-structured resource references used to seed canonical resource-policy, state,
-relationship, and timeline hydration. Frontend handoff builders may send these
-fields for owned alert or incident context, but the backend must not persist
-them as user-authored message text and must treat them as explanation/review
-context only. When a Patrol `finding_id` resolves, backend-refreshed durable
-finding context replaces any browser-supplied handoff text so the model cannot
+`handoff_context` is bounded model-only text, `handoff_resources` are structured
+resource references used to seed canonical resource-policy, state, relationship,
+and timeline hydration, and `handoff_actions` are structured approval/action
+references used to seed canonical approval and action-audit refresh. Frontend
+handoff builders may send these fields for owned alert, incident, or Patrol
+assessment context, but the backend must not persist them as user-authored
+message text and must treat them as explanation/review context only. When a
+Patrol `finding_id` resolves, backend-refreshed durable finding context replaces
+any browser-supplied handoff text or action references so the model cannot
continue from stale or spoofed Patrol context.
Patrol finding handoffs are stricter than ordinary chat requests: when
`finding_id` resolves to model-only Patrol briefing, resource, or action
@@ -3033,9 +3036,11 @@ frontend Assistant drawer briefing must use that same operator frame for
visible handoffs from findings, while the downstream chat
service hydrates live resource state, timeline, and action audit context around
that same handoff. Frontend Patrol handoff helpers may consume current pending
-approval list payloads only as safe metadata for that visible briefing: approval
-ID, status, risk, request/expiry timestamps, and target label are allowed, while
-approval command text remains inside the governed approval/remediation surface.
+approval list payloads only as safe metadata for that visible briefing and any
+structured `handoff_actions`: approval ID, status, risk, request/expiry
+timestamps, target label, action ID, approval policy, plan expiry, and dry-run
+summary are allowed, while approval command text remains inside the governed
+approval/remediation surface.
Patrol approval-row Assistant prompts must use the same safe metadata boundary
and set `autonomousMode:false` for the request-local chat handoff; they must not
paste raw approval or proposed-fix command text into the authored chat prompt.
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index d5737137e3..1132a717f9 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -814,9 +814,12 @@ frontend primitive boundary.
verification, latest-run, supporting-context evidence, active-finding, and
resource reference context while forcing request-local approval-required
mode. Active-finding entries in that assessment handoff may add live pending
- approval posture only as safe metadata: approval ID, pending status, risk,
- target, requested/expiry timestamps, and command count. The shared drawer
- stays a generic shell rather than a Patrol summary prompt builder. The
+ approval posture only as safe structured metadata: approval ID, pending
+ status, risk, target, requested/expiry timestamps, action plan identity,
+ approval policy, plan expiry, dry-run posture, and command count. Those
+ entries may be passed through shared chat transport as `handoff_actions` for
+ model-only refresh, but the shared drawer stays a generic shell rather than
+ a Patrol summary prompt builder. The
drawer may render a generic
context-briefing band from `frontend-modern/src/stores/aiChat.ts`, but
feature-owned helpers must provide the source labels, attention reason,
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
index c9c6dc5417..6f5c45d776 100644
--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
@@ -217,13 +217,15 @@ Patrol-specific presentation helpers.
The summary action may pass the current assessment title, health score,
verification recency, latest run, secondary investigation context, bounded
recent-change and learned-correlation evidence, active-finding summaries,
- structured resource references, and safe source-owned suggested prompts as
- model-only context. Active-finding summaries may include live pending
- approval posture only as safe metadata: approval ID, pending status, risk,
- target, requested/expiry timestamps, and command count. They must force
- request-local approval-required mode, keep raw command and approval payloads
- out of prompt and drawer copy, and frame Assistant as explanation,
- prioritization, and safe next-step review rather than a generic reactive chat
+ structured resource references, structured approval/action references, and
+ safe source-owned suggested prompts as model-only context. Active-finding
+ summaries may include live pending approval posture only as safe metadata:
+ approval ID, pending status, risk, target, requested/expiry timestamps,
+ action plan identity, approval policy, plan expiry, dry-run posture, and
+ command count. They must force request-local approval-required mode, keep raw
+ command and approval payloads out of prompt and drawer copy, and frame
+ Assistant as explanation, prioritization, and safe next-step review rather
+ than a generic reactive chat
box.
## Current State
@@ -279,9 +281,10 @@ opens Assistant through
packages the current Patrol assessment, verification posture, latest run,
secondary investigation context, bounded recent-change and learned-correlation
evidence, bounded active-finding summaries, source-owned suggested prompts, and
-deduped resource references as model-only context while forcing
-`autonomousMode:false` and summarizing proposed-fix command-bearing records and
-command-bearing change events without raw command text.
+deduped resource references plus safe structured approval/action references as
+model-only context while forcing `autonomousMode:false` and summarizing
+proposed-fix command-bearing records and command-bearing change events without
+raw command text.
That active-runtime label must stay operational rather than verdict-like: the
header chip should communicate that Patrol is enabled or available, not imply
that infrastructure health is currently good merely because the runtime is on.
diff --git a/docs/release-control/v6/internal/subsystems/security-privacy.md b/docs/release-control/v6/internal/subsystems/security-privacy.md
index 15a0bd547e..adc92246fe 100644
--- a/docs/release-control/v6/internal/subsystems/security-privacy.md
+++ b/docs/release-control/v6/internal/subsystems/security-privacy.md
@@ -443,6 +443,10 @@ Assistant handoff context may hydrate those normalized action-audit facts for
review, but that read is still model-only context: it must remain org-scoped,
must not expose raw command text or raw execution output, and must not grant
approval or execution authority.
+Scoped Assistant `handoff_actions` from Patrol assessment handoffs may carry
+only safe approval/action metadata for model-only refresh, including approval
+IDs, action IDs, policy, expiry, dry-run posture, and proposed-fix labels; they
+must not expose raw command or execution payloads or become an approval bypass.
Assistant operator briefings generated from Patrol findings follow the same
boundary: they may summarize approval IDs, proposed-fix IDs, risk, destructive
posture, and recommended next steps for review, but they must not expose raw
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index ae6e8af5a5..dcb34200bc 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -403,13 +403,13 @@ bypass the API fail-closed execution gate.
`finding_id` handoffs with model-only Patrol briefing, resource, or action
context is Assistant action-governance, not a storage/recovery approval,
recovery freshness, or restore-command signal.
- Alert and incident Assistant handoffs that send bounded model-only
- `handoff_context` and `handoff_resources` through `/api/ai/chat` without a
- `finding_id` stay on that same adjacent AI/runtime boundary. Storage and
- recovery surfaces may consume the explanation context, but must not treat
- the handoff resource reference as backup freshness, restore eligibility,
- recovery execution authority, storage health truth, or a storage-local
- approval shortcut.
+ Alert, incident, and Patrol assessment Assistant handoffs that send bounded
+ model-only `handoff_context`, `handoff_resources`, or `handoff_actions`
+ through `/api/ai/chat` without a `finding_id` stay on that same adjacent
+ AI/runtime boundary. Storage and recovery surfaces may consume the
+ explanation context, but must not treat the handoff resource or action
+ reference as backup freshness, restore eligibility, recovery execution
+ authority, storage health truth, or a storage-local approval shortcut.
That same adjacent boundary also keeps the retired Patrol quickstart
contract out of storage/recovery ownership: shared AI handlers no longer
expose active quickstart credit, token, or hosted-model provider state, and
diff --git a/frontend-modern/src/api/__tests__/aiChat.test.ts b/frontend-modern/src/api/__tests__/aiChat.test.ts
index c071c0367d..9d74da5f62 100644
--- a/frontend-modern/src/api/__tests__/aiChat.test.ts
+++ b/frontend-modern/src/api/__tests__/aiChat.test.ts
@@ -173,6 +173,24 @@ describe('AIChatAPI', () => {
node: 'nas-1',
},
],
+ [
+ {
+ findingId: 'finding-1',
+ approvalId: 'approval-1',
+ approvalStatus: 'pending',
+ approvalRequestedAt: '2026-05-06T12:00:00Z',
+ approvalExpiresAt: '2026-05-06T12:10:00Z',
+ actionId: 'action-1',
+ actionApprovalPolicy: 'admin',
+ actionRequiresApproval: true,
+ actionPlanExpiresAt: '2026-05-06T12:10:00Z',
+ actionDryRunSummary: 'No provider-supported dry run is available for this action.',
+ riskLevel: 'high',
+ targetResourceId: 'vm-100',
+ targetResourceName: 'web-server',
+ targetResourceType: 'vm',
+ },
+ ],
);
expect(apiFetchMock).toHaveBeenCalledWith(
@@ -192,6 +210,39 @@ describe('AIChatAPI', () => {
node: 'nas-1',
},
],
+ handoff_actions: [
+ {
+ finding_id: 'finding-1',
+ record_id: undefined,
+ approval_id: 'approval-1',
+ approval_status: 'pending',
+ approval_requested_at: '2026-05-06T12:00:00Z',
+ approval_expires_at: '2026-05-06T12:10:00Z',
+ approval_decided_at: undefined,
+ approval_consumed: undefined,
+ action_id: 'action-1',
+ action_state: undefined,
+ action_updated_at: undefined,
+ action_requested_by: undefined,
+ action_capability: undefined,
+ action_approval_policy: 'admin',
+ action_requires_approval: true,
+ action_plan_expires_at: '2026-05-06T12:10:00Z',
+ action_plan_message: undefined,
+ action_preflight: undefined,
+ action_dry_run_summary: 'No provider-supported dry run is available for this action.',
+ action_result: undefined,
+ fix_id: undefined,
+ description: undefined,
+ risk_level: 'high',
+ destructive: undefined,
+ target_host: undefined,
+ target_resource_id: 'vm-100',
+ target_resource_name: 'web-server',
+ target_resource_type: 'vm',
+ target_node: undefined,
+ },
+ ],
}),
}),
);
diff --git a/frontend-modern/src/api/aiChat.ts b/frontend-modern/src/api/aiChat.ts
index c1a53ae2c1..40c5b0395f 100644
--- a/frontend-modern/src/api/aiChat.ts
+++ b/frontend-modern/src/api/aiChat.ts
@@ -30,6 +30,38 @@ export interface ChatHandoffResource {
node?: string;
}
+export interface ChatHandoffAction {
+ findingId?: string;
+ recordId?: string;
+ approvalId?: string;
+ approvalStatus?: string;
+ approvalRequestedAt?: string;
+ approvalExpiresAt?: string;
+ approvalDecidedAt?: string;
+ approvalConsumed?: boolean;
+ actionId?: string;
+ actionState?: string;
+ actionUpdatedAt?: string;
+ actionRequestedBy?: string;
+ actionCapability?: string;
+ actionApprovalPolicy?: string;
+ actionRequiresApproval?: boolean;
+ actionPlanExpiresAt?: string;
+ actionPlanMessage?: string;
+ actionPreflight?: string;
+ actionDryRunSummary?: string;
+ actionResult?: string;
+ fixId?: string;
+ description?: string;
+ riskLevel?: string;
+ destructive?: boolean;
+ targetHost?: string;
+ targetResourceId?: string;
+ targetResourceName?: string;
+ targetResourceType?: string;
+ targetNode?: string;
+}
+
export interface ChatMessage {
id: string;
role: 'user' | 'assistant';
@@ -209,6 +241,7 @@ export class AIChatAPI {
autonomousMode?: boolean,
handoffContext?: string,
handoffResources?: ChatHandoffResource[],
+ handoffActions?: ChatHandoffAction[],
): Promise<void> {
logger.debug('[AI Chat] Starting chat stream', { prompt: prompt.substring(0, 50) });
@@ -232,6 +265,9 @@ export class AIChatAPI {
if (handoffResources && handoffResources.length > 0) {
body.handoff_resources = handoffResources;
}
+ if (handoffActions && handoffActions.length > 0) {
+ body.handoff_actions = handoffActions.map(serializeChatHandoffAction);
+ }
const response = await apiFetch(`${this.baseUrl}/chat`, {
method: 'POST',
@@ -266,3 +302,37 @@ export class AIChatAPI {
});
}
}
+
+function serializeChatHandoffAction(action: ChatHandoffAction): Record<string, unknown> {
+ return {
+ finding_id: action.findingId,
+ record_id: action.recordId,
+ approval_id: action.approvalId,
+ approval_status: action.approvalStatus,
+ approval_requested_at: action.approvalRequestedAt,
+ approval_expires_at: action.approvalExpiresAt,
+ approval_decided_at: action.approvalDecidedAt,
+ approval_consumed: action.approvalConsumed,
+ action_id: action.actionId,
+ action_state: action.actionState,
+ action_updated_at: action.actionUpdatedAt,
+ action_requested_by: action.actionRequestedBy,
+ action_capability: action.actionCapability,
+ action_approval_policy: action.actionApprovalPolicy,
+ action_requires_approval: action.actionRequiresApproval,
+ action_plan_expires_at: action.actionPlanExpiresAt,
+ action_plan_message: action.actionPlanMessage,
+ action_preflight: action.actionPreflight,
+ action_dry_run_summary: action.actionDryRunSummary,
+ action_result: action.actionResult,
+ fix_id: action.fixId,
+ description: action.description,
+ risk_level: action.riskLevel,
+ destructive: action.destructive,
+ target_host: action.targetHost,
+ target_resource_id: action.targetResourceId,
+ target_resource_name: action.targetResourceName,
+ target_resource_type: action.targetResourceType,
+ target_node: action.targetNode,
+ };
+}
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 50c9c51974..cd08713434 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
+++ b/frontend-modern/src/components/AI/Chat/__tests__/AIChat.test.tsx
@@ -82,6 +82,7 @@ const {
briefing: undefined,
handoffContext: undefined,
handoffResources: undefined,
+ handoffActions: undefined,
} as {
initialPrompt?: string;
findingId?: string;
@@ -94,6 +95,11 @@ const {
type?: string;
node?: string;
}>;
+ handoffActions?: Array<{
+ findingId?: string;
+ approvalId?: string;
+ approvalStatus?: string;
+ }>;
briefing?: {
sourceLabel: string;
title: string;
@@ -1128,6 +1134,13 @@ describe('AIChat', () => {
node: 'nas-1',
},
],
+ handoffActions: [
+ {
+ findingId: 'finding-1',
+ approvalId: 'approval-1',
+ approvalStatus: 'pending',
+ },
+ ],
briefing: {
sourceLabel: 'Pulse Alerts',
title: 'Incident timeline attached',
@@ -1156,6 +1169,13 @@ describe('AIChat', () => {
node: 'nas-1',
},
],
+ handoffActions: [
+ {
+ findingId: 'finding-1',
+ approvalId: 'approval-1',
+ approvalStatus: 'pending',
+ },
+ ],
},
);
});
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 ae1f4f2992..b17bb95f86 100644
--- a/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
+++ b/frontend-modern/src/components/AI/Chat/__tests__/useChat.test.ts
@@ -245,6 +245,13 @@ describe('useChat', () => {
node: 'nas-1',
},
],
+ handoffActions: [
+ {
+ findingId: 'finding-1',
+ approvalId: 'approval-1',
+ approvalStatus: 'pending',
+ },
+ ],
});
const chatCall = mockChat.mock.calls[0];
@@ -258,6 +265,13 @@ describe('useChat', () => {
node: 'nas-1',
},
]);
+ expect(chatCall[10]).toEqual([
+ {
+ findingId: 'finding-1',
+ approvalId: 'approval-1',
+ approvalStatus: 'pending',
+ },
+ ]);
dispose();
});
diff --git a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
index f56a2fcec8..19c4528bdd 100644
--- a/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
+++ b/frontend-modern/src/components/AI/Chat/hooks/useChat.ts
@@ -1,6 +1,7 @@
import { createSignal, onCleanup } from 'solid-js';
import {
AIChatAPI,
+ type ChatHandoffAction,
type ChatHandoffResource,
type ChatMention,
type StreamEvent,
@@ -29,6 +30,7 @@ export interface SendMessageOptions {
autonomousMode?: boolean;
handoffContext?: string;
handoffResources?: ChatHandoffResource[];
+ handoffActions?: ChatHandoffAction[];
}
export function useChat(options: UseChatOptions = {}) {
@@ -569,6 +571,7 @@ export function useChat(options: UseChatOptions = {}) {
sendOptions?.autonomousMode,
sendOptions?.handoffContext,
sendOptions?.handoffResources,
+ sendOptions?.handoffActions,
);
await notifyConversationChanged();
return true;
diff --git a/frontend-modern/src/components/AI/Chat/index.tsx b/frontend-modern/src/components/AI/Chat/index.tsx
index a2b399b694..b332a17d47 100644
--- a/frontend-modern/src/components/AI/Chat/index.tsx
+++ b/frontend-modern/src/components/AI/Chat/index.tsx
@@ -685,10 +685,14 @@ export const AIChat: Component<AIChatProps> = (props) => {
if (ctx.handoffResources && ctx.handoffResources.length > 0) {
sendOptions.handoffResources = ctx.handoffResources;
}
+ if (ctx.handoffActions && ctx.handoffActions.length > 0) {
+ sendOptions.handoffActions = ctx.handoffActions;
+ }
const hasSendOptions =
typeof sendOptions.autonomousMode === 'boolean' ||
Boolean(sendOptions.handoffContext) ||
- Boolean(sendOptions.handoffResources?.length);
+ Boolean(sendOptions.handoffResources?.length) ||
+ Boolean(sendOptions.handoffActions?.length);
const sendPromise = hasSendOptions
? chat.sendMessage(prompt, mentionsForAPI, findingId, sendOptions)
: chat.sendMessage(prompt, mentionsForAPI, findingId);
diff --git a/frontend-modern/src/components/AI/FindingsPanel.tsx b/frontend-modern/src/components/AI/FindingsPanel.tsx
index 6526e10fb0..6f48611325 100644
--- a/frontend-modern/src/components/AI/FindingsPanel.tsx
+++ b/frontend-modern/src/components/AI/FindingsPanel.tsx
@@ -20,6 +20,7 @@ import { aiChatStore } from '@/stores/aiChat';
import {
buildPatrolAssistantFindingBriefing,
buildPatrolAssistantFindingPrompt,
+ buildPatrolAssistantApprovalBriefingInput,
buildPatrolAssistantProposedFixBriefingInput,
buildPatrolRemediationPlanAssistantBriefing,
buildPatrolRemediationPlanAssistantPrompt,
@@ -480,16 +481,7 @@ export const FindingsPanel: Component<FindingsPanelProps> = (props) => {
const pendingApproval = aiIntelligenceStore.patrolPendingApprovals.find(
(approval) => approval.toolId === 'investigation_fix' && approval.targetId === finding.id,
);
- const pendingApprovalBriefing = pendingApproval
- ? {
- id: pendingApproval.id,
- status: pendingApproval.status,
- riskLevel: pendingApproval.riskLevel,
- requestedAt: pendingApproval.requestedAt,
- expiresAt: pendingApproval.expiresAt,
- targetName: pendingApproval.targetName,
- }
- : undefined;
+ const pendingApprovalBriefing = buildPatrolAssistantApprovalBriefingInput(pendingApproval);
const latestInvestigationProposedFix = await loadLatestInvestigationProposedFixBriefing(
finding,
pendingApprovalBriefing,
diff --git a/frontend-modern/src/components/AI/__tests__/FindingsPanel.test.ts b/frontend-modern/src/components/AI/__tests__/FindingsPanel.test.ts
index c1425baaa7..13da25d629 100644
--- a/frontend-modern/src/components/AI/__tests__/FindingsPanel.test.ts
+++ b/frontend-modern/src/components/AI/__tests__/FindingsPanel.test.ts
@@ -45,10 +45,11 @@ const patrolWorkspaceSource = readFileSync(
describe('FindingsPanel assistant handoff', () => {
it('routes Patrol investigation records into the Assistant briefing context', () => {
expect(findingsPanelSource).toContain('buildPatrolAssistantFindingBriefing');
+ expect(findingsPanelSource).toContain('buildPatrolAssistantApprovalBriefingInput');
expect(findingsPanelSource).toContain('buildPatrolAssistantProposedFixBriefingInput');
expect(findingsPanelSource).toContain('briefing,');
expect(findingsPanelSource).toContain('investigationRecord: finding.investigationRecord');
- expect(findingsPanelSource).toContain('pendingApproval: pendingApproval');
+ expect(findingsPanelSource).toContain('pendingApproval: pendingApprovalBriefing');
expect(findingsPanelSource).toContain('proposedFix,');
expect(findingsPanelSource).toContain('AIAPI.getInvestigation(finding.id)');
expect(findingsPanelSource).toContain('await aiIntelligenceStore.loadPendingApprovals()');
diff --git a/frontend-modern/src/components/patrol/ApprovalSection.tsx b/frontend-modern/src/components/patrol/ApprovalSection.tsx
index d6c49630e1..e77107511c 100644
--- a/frontend-modern/src/components/patrol/ApprovalSection.tsx
+++ b/frontend-modern/src/components/patrol/ApprovalSection.tsx
@@ -14,6 +14,7 @@ import { AIAPI, type ApprovalRequest, type ApprovalExecutionResult } from '@/api
import { getApprovalRiskPresentation } from '@/utils/approvalRiskPresentation';
import {
buildPatrolAssistantFindingBriefing,
+ buildPatrolAssistantApprovalBriefingInput,
buildPatrolAssistantProposedFixBriefingInput,
type PatrolAssistantProposedFixBriefingSource,
} from '@/features/patrol/patrolInvestigationContextModel';
@@ -53,16 +54,7 @@ export const ApprovalSection: Component<ApprovalSectionProps> = (props) => {
findingStatus: 'active',
investigationOutcome: props.investigationOutcome,
loopState: props.investigationOutcome || 'awaiting_approval',
- pendingApproval: approval
- ? {
- id: approval.id,
- status: approval.status,
- riskLevel: approval.riskLevel,
- requestedAt: approval.requestedAt,
- expiresAt: approval.expiresAt,
- targetName: approval.targetName,
- }
- : null,
+ pendingApproval: buildPatrolAssistantApprovalBriefingInput(approval),
proposedFix: buildPatrolAssistantProposedFixBriefingInput(
fix ||
(approval
diff --git a/frontend-modern/src/features/patrol/PatrolIntelligenceSummary.tsx b/frontend-modern/src/features/patrol/PatrolIntelligenceSummary.tsx
index decf0899f8..deb18c3664 100644
--- a/frontend-modern/src/features/patrol/PatrolIntelligenceSummary.tsx
+++ b/frontend-modern/src/features/patrol/PatrolIntelligenceSummary.tsx
@@ -26,6 +26,7 @@ import { aiIntelligenceStore } from '@/stores/aiIntelligence';
import type { ApprovalRequest } from '@/api/ai';
import {
buildPatrolAssessmentAssistantHandoff,
+ buildPatrolAssistantApprovalBriefingInput,
buildPatrolAssistantProposedFixBriefingInput,
type PatrolAssessmentAssistantFindingInput,
} from './patrolInvestigationContextModel';
@@ -518,14 +519,7 @@ export function PatrolIntelligenceSummary(props: { state: PatrolIntelligenceStat
}
function buildPatrolAssessmentApprovalBriefing(approval: ApprovalRequest) {
- return {
- id: approval.id,
- status: approval.status,
- riskLevel: approval.riskLevel,
- requestedAt: approval.requestedAt,
- expiresAt: approval.expiresAt,
- targetName: approval.targetName,
- };
+ return buildPatrolAssistantApprovalBriefingInput(approval);
}
function buildPatrolAssessmentApprovalProposedFixBriefing(approval: ApprovalRequest) {
diff --git a/frontend-modern/src/features/patrol/__tests__/PatrolIntelligenceSummary.test.tsx b/frontend-modern/src/features/patrol/__tests__/PatrolIntelligenceSummary.test.tsx
index 8fbd843532..6d2786315c 100644
--- a/frontend-modern/src/features/patrol/__tests__/PatrolIntelligenceSummary.test.tsx
+++ b/frontend-modern/src/features/patrol/__tests__/PatrolIntelligenceSummary.test.tsx
@@ -30,6 +30,18 @@ describe('PatrolIntelligenceSummary', () => {
status: 'pending',
requestedAt: '2026-05-06T12:00:00Z',
expiresAt: '2026-05-06T12:10:00Z',
+ plan: {
+ actionId: 'action-1',
+ requiresApproval: true,
+ approvalPolicy: 'admin',
+ message: 'Restart after the backup window clears.',
+ expiresAt: '2026-05-06T12:10:00Z',
+ },
+ preflight: {
+ intendedChange: 'Restart workload service',
+ dryRunAvailable: false,
+ dryRunSummary: 'No provider-supported dry run is available for this action.',
+ },
},
]);
@@ -60,6 +72,21 @@ describe('PatrolIntelligenceSummary', () => {
{ id: 'vm-100', name: 'web-server', type: 'vm', node: 'pve-1' },
{ id: 'backup-job', name: 'Nightly backup job', type: 'job', node: undefined },
]);
+ expect(context.handoffActions).toHaveLength(1);
+ expect((context.handoffActions as Array<Record<string, unknown>>)[0]).toMatchObject({
+ findingId: 'finding-1',
+ approvalId: 'approval-1',
+ approvalStatus: 'pending',
+ approvalRequestedAt: '2026-05-06T12:00:00Z',
+ approvalExpiresAt: '2026-05-06T12:10:00Z',
+ actionId: 'action-1',
+ actionApprovalPolicy: 'admin',
+ actionRequiresApproval: true,
+ actionPlanExpiresAt: '2026-05-06T12:10:00Z',
+ actionPlanMessage: 'Restart after the backup window clears.',
+ actionPreflight: 'Restart workload service',
+ actionDryRunSummary: 'No provider-supported dry run is available for this action.',
+ });
expect(context.briefing).toMatchObject({
suggestedPrompts: [
'Prioritize findings and safest next step',
diff --git a/frontend-modern/src/features/patrol/__tests__/patrolInvestigationContextModel.test.ts b/frontend-modern/src/features/patrol/__tests__/patrolInvestigationContextModel.test.ts
index eb6dd0c922..9af0625505 100644
--- a/frontend-modern/src/features/patrol/__tests__/patrolInvestigationContextModel.test.ts
+++ b/frontend-modern/src/features/patrol/__tests__/patrolInvestigationContextModel.test.ts
@@ -293,6 +293,12 @@ describe('patrolInvestigationContextModel', () => {
requestedAt: '2026-05-06T12:00:00Z',
expiresAt: '2026-05-06T12:10:00Z',
targetName: 'web-server',
+ actionId: 'action-1',
+ actionApprovalPolicy: 'admin',
+ actionPlanExpiresAt: '2026-05-06T12:10:00Z',
+ actionPlanMessage: 'Restart after the backup window clears.',
+ actionPreflight: 'Restart workload service',
+ actionDryRunSummary: 'No provider-supported dry run is available for this action.',
},
proposedFix: {
description: 'Restart the workload service',
@@ -314,6 +320,28 @@ describe('patrolInvestigationContextModel', () => {
expect(handoff.context.handoffContext).toContain('expires 2026-05-06T12:10:00Z');
expect(handoff.context.handoffContext).toContain('1 command recorded for approval context');
expect(handoff.context.handoffContext).toContain('destructive proposed fix');
+ expect(handoff.context.handoffActions).toHaveLength(1);
+ expect(handoff.context.handoffActions?.[0]).toMatchObject({
+ findingId: 'finding-1',
+ approvalId: 'approval-1',
+ approvalStatus: 'pending',
+ approvalRequestedAt: '2026-05-06T12:00:00Z',
+ approvalExpiresAt: '2026-05-06T12:10:00Z',
+ actionId: 'action-1',
+ actionApprovalPolicy: 'admin',
+ actionRequiresApproval: true,
+ actionPlanExpiresAt: '2026-05-06T12:10:00Z',
+ actionPlanMessage: 'Restart after the backup window clears.',
+ actionPreflight: 'Restart workload service',
+ actionDryRunSummary: 'No provider-supported dry run is available for this action.',
+ description: 'Restart the workload service',
+ riskLevel: 'high',
+ destructive: true,
+ targetHost: 'web-server',
+ targetResourceId: 'vm-100',
+ targetResourceName: 'web-server',
+ targetResourceType: 'vm',
+ });
expect(handoff.context.context).toMatchObject({
pendingApprovalCount: 1,
});
diff --git a/frontend-modern/src/features/patrol/patrolInvestigationContextModel.ts b/frontend-modern/src/features/patrol/patrolInvestigationContextModel.ts
index 7986579d1f..d725a2c93d 100644
--- a/frontend-modern/src/features/patrol/patrolInvestigationContextModel.ts
+++ b/frontend-modern/src/features/patrol/patrolInvestigationContextModel.ts
@@ -3,8 +3,13 @@ import type {
IntelligencePolicyPostureSummary,
ResourceCorrelation,
} from '@/types/aiIntelligence';
-import type { InvestigationRecord, RemediationPlan } from '@/api/ai';
-import type { AIChatContext, AIChatContextBriefing, AIChatHandoffResource } from '@/stores/aiChat';
+import type { ApprovalRequest, InvestigationRecord, RemediationPlan } from '@/api/ai';
+import type {
+ AIChatContext,
+ AIChatContextBriefing,
+ AIChatHandoffAction,
+ AIChatHandoffResource,
+} from '@/stores/aiChat';
import type { ResourceChange } from '@/types/resource';
import {
formatResourceChangeKind,
@@ -66,6 +71,12 @@ export interface PatrolAssistantApprovalBriefingInput {
requestedAt?: string | null;
expiresAt?: string | null;
targetName?: string | null;
+ actionId?: string | null;
+ actionApprovalPolicy?: string | null;
+ actionPlanExpiresAt?: string | null;
+ actionPlanMessage?: string | null;
+ actionPreflight?: string | null;
+ actionDryRunSummary?: string | null;
}
export interface PatrolAssistantProposedFixBriefingInput {
@@ -195,6 +206,7 @@ const MAX_ASSESSMENT_FINDINGS = 5;
const MAX_ASSESSMENT_RECENT_CHANGES = 3;
const MAX_ASSESSMENT_CORRELATIONS = 3;
const MAX_ASSESSMENT_RESOURCES = 8;
+const MAX_ASSESSMENT_HANDOFF_ACTIONS = 4;
const MAX_PATROL_BRIEFING_SUGGESTED_PROMPTS = 3;
export function buildPatrolInvestigationContextSummary(
@@ -304,6 +316,26 @@ export function buildPatrolAssistantProposedFixBriefingInput(
return briefing;
}
+export function buildPatrolAssistantApprovalBriefingInput(
+ approval?: ApprovalRequest | null,
+): PatrolAssistantApprovalBriefingInput | undefined {
+ if (!approval) return undefined;
+ return {
+ id: normalizeText(approval.id),
+ status: normalizeText(approval.status),
+ riskLevel: normalizeText(approval.riskLevel),
+ requestedAt: normalizeText(approval.requestedAt),
+ expiresAt: normalizeText(approval.expiresAt),
+ targetName: normalizeText(approval.targetName),
+ actionId: normalizeText(approval.plan?.actionId),
+ actionApprovalPolicy: normalizeText(approval.plan?.approvalPolicy),
+ actionPlanExpiresAt: normalizeText(approval.plan?.expiresAt),
+ actionPlanMessage: normalizeText(approval.plan?.message || approval.plan?.summary),
+ actionPreflight: normalizeText(approval.preflight?.intendedChange),
+ actionDryRunSummary: normalizeText(approval.preflight?.dryRunSummary),
+ };
+}
+
export function buildPatrolAssistantFindingPrompt(
input: PatrolAssistantFindingPromptInput,
): string {
@@ -331,6 +363,7 @@ export function buildPatrolAssessmentAssistantHandoff(
const handoffContext = buildPatrolAssessmentAssistantModelContext(input);
const recentChanges = normalizeAssessmentRecentChanges(input.supportingEvidence?.recentChanges);
const correlations = normalizeAssessmentCorrelations(input.supportingEvidence?.correlations);
+ const handoffActions = buildPatrolAssessmentHandoffActions(input);
return {
prompt: [
@@ -347,6 +380,7 @@ export function buildPatrolAssessmentAssistantHandoff(
autonomousMode: false,
handoffContext,
handoffResources: buildPatrolAssessmentHandoffResources(input),
+ handoffActions: handoffActions.length > 0 ? handoffActions : undefined,
briefing: buildPatrolAssessmentAssistantBriefing(input),
context: {
source: 'pulse-patrol-assessment',
@@ -590,6 +624,69 @@ function addAssessmentHandoffResource(
});
}
+function buildPatrolAssessmentHandoffActions(
+ input: PatrolAssessmentAssistantHandoffInput,
+): AIChatHandoffAction[] {
+ const actions: AIChatHandoffAction[] = [];
+
+ for (const finding of normalizeAssessmentFindings(input.activeFindings)) {
+ if (actions.length >= MAX_ASSESSMENT_HANDOFF_ACTIONS) break;
+
+ const pendingApproval = normalizeApprovalBriefing(finding.pendingApproval);
+ const proposedFix = normalizeProposedFixBriefing(finding.proposedFix);
+ const record = finding.investigationRecord;
+ const recordFix = record?.proposed_fix;
+ const approvalId = pendingApproval.id || normalizeText(record?.approval_id);
+ const fixId = normalizeText(recordFix?.id);
+ const description =
+ normalizeText(proposedFix?.description) || normalizeText(recordFix?.description);
+
+ if (!approvalId && !fixId && !description && !pendingApproval.actionId) {
+ continue;
+ }
+
+ actions.push({
+ findingId: normalizeText(finding.id) || normalizeText(record?.finding_id) || undefined,
+ recordId: normalizeText(record?.id) || undefined,
+ approvalId: approvalId || undefined,
+ approvalStatus: pendingApproval.status || undefined,
+ approvalRequestedAt: pendingApproval.requestedAt || undefined,
+ approvalExpiresAt: pendingApproval.expiresAt || undefined,
+ actionId: pendingApproval.actionId || undefined,
+ actionApprovalPolicy: pendingApproval.actionApprovalPolicy || undefined,
+ actionRequiresApproval: Boolean(approvalId),
+ actionPlanExpiresAt: pendingApproval.actionPlanExpiresAt || undefined,
+ actionPlanMessage: pendingApproval.actionPlanMessage || undefined,
+ actionPreflight: pendingApproval.actionPreflight || undefined,
+ actionDryRunSummary: pendingApproval.actionDryRunSummary || undefined,
+ fixId: fixId || undefined,
+ description: description || undefined,
+ riskLevel:
+ pendingApproval.riskLevel ||
+ normalizeText(finding.proposedFix?.riskLevel) ||
+ normalizeText(recordFix?.risk_level) ||
+ undefined,
+ destructive: Boolean(proposedFix?.destructive || recordFix?.destructive),
+ targetHost:
+ normalizeText(proposedFix?.targetHost) ||
+ normalizeText(recordFix?.target_host) ||
+ pendingApproval.targetName ||
+ undefined,
+ targetResourceId:
+ normalizeText(finding.resourceId || record?.subject?.resource_id) || undefined,
+ targetResourceName:
+ normalizeText(finding.resourceName || record?.subject?.resource_name) ||
+ pendingApproval.targetName ||
+ undefined,
+ targetResourceType:
+ normalizeText(finding.resourceType || record?.subject?.resource_type) || undefined,
+ targetNode: normalizeText(record?.subject?.node) || undefined,
+ });
+ }
+
+ return actions;
+}
+
function normalizeAssessmentFindings(
findings?: PatrolAssessmentAssistantFindingInput[] | null,
): PatrolAssessmentAssistantFindingInput[] {
@@ -1571,6 +1668,12 @@ function normalizeApprovalBriefing(
requestedAt: normalizeText(approval?.requestedAt),
expiresAt: normalizeText(approval?.expiresAt),
targetName: normalizeText(approval?.targetName),
+ actionId: normalizeText(approval?.actionId),
+ actionApprovalPolicy: normalizeText(approval?.actionApprovalPolicy),
+ actionPlanExpiresAt: normalizeText(approval?.actionPlanExpiresAt),
+ actionPlanMessage: normalizeText(approval?.actionPlanMessage),
+ actionPreflight: normalizeText(approval?.actionPreflight),
+ actionDryRunSummary: normalizeText(approval?.actionDryRunSummary),
};
}
diff --git a/frontend-modern/src/stores/__tests__/aiChat.test.ts b/frontend-modern/src/stores/__tests__/aiChat.test.ts
index 7759ab0cb1..75d3772ab9 100644
--- a/frontend-modern/src/stores/__tests__/aiChat.test.ts
+++ b/frontend-modern/src/stores/__tests__/aiChat.test.ts
@@ -144,6 +144,7 @@ describe('aiChatStore', () => {
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' }],
});
expect(aiChatStore.context.initialPrompt).toBe('discuss this incident');
@@ -151,6 +152,9 @@ describe('aiChatStore', () => {
expect(aiChatStore.context.handoffResources).toEqual([
{ id: 'storage-1', name: 'tank', type: 'storage', node: 'nas-1' },
]);
+ expect(aiChatStore.context.handoffActions).toEqual([
+ { findingId: 'finding-1', approvalId: 'approval-1' },
+ ]);
aiChatStore.clearInitialPrompt();
@@ -159,6 +163,9 @@ describe('aiChatStore', () => {
expect(aiChatStore.context.handoffResources).toEqual([
{ id: 'storage-1', name: 'tank', type: 'storage', node: 'nas-1' },
]);
+ expect(aiChatStore.context.handoffActions).toEqual([
+ { findingId: 'finding-1', approvalId: 'approval-1' },
+ ]);
});
it('focusInput returns false when closed and true when open with a registered element', () => {
diff --git a/frontend-modern/src/stores/aiChat.ts b/frontend-modern/src/stores/aiChat.ts
index 7e0ee3aed7..2b37d31ec0 100644
--- a/frontend-modern/src/stores/aiChat.ts
+++ b/frontend-modern/src/stores/aiChat.ts
@@ -24,6 +24,38 @@ export interface AIChatHandoffResource {
node?: string;
}
+export interface AIChatHandoffAction {
+ findingId?: string;
+ recordId?: string;
+ approvalId?: string;
+ approvalStatus?: string;
+ approvalRequestedAt?: string;
+ approvalExpiresAt?: string;
+ approvalDecidedAt?: string;
+ approvalConsumed?: boolean;
+ actionId?: string;
+ actionState?: string;
+ actionUpdatedAt?: string;
+ actionRequestedBy?: string;
+ actionCapability?: string;
+ actionApprovalPolicy?: string;
+ actionRequiresApproval?: boolean;
+ actionPlanExpiresAt?: string;
+ actionPlanMessage?: string;
+ actionPreflight?: string;
+ actionDryRunSummary?: string;
+ actionResult?: string;
+ fixId?: string;
+ description?: string;
+ riskLevel?: string;
+ destructive?: boolean;
+ targetHost?: string;
+ targetResourceId?: string;
+ targetResourceName?: string;
+ targetResourceType?: string;
+ targetNode?: string;
+}
+
export interface AIChatContext {
targetType?: string;
targetId?: string;
@@ -33,6 +65,7 @@ export interface AIChatContext {
briefing?: AIChatContextBriefing;
handoffContext?: string;
handoffResources?: AIChatHandoffResource[];
+ handoffActions?: AIChatHandoffAction[];
// Per-request execution mode override; false keeps scoped handoffs approval-required.
autonomousMode?: boolean;
}
diff --git a/internal/api/ai_handler.go b/internal/api/ai_handler.go
index c4a3d473de..898bfecb4d 100644
--- a/internal/api/ai_handler.go
+++ b/internal/api/ai_handler.go
@@ -782,12 +782,14 @@ type ChatRequest struct {
FindingID string `json:"finding_id,omitempty"`
HandoffContext string `json:"handoff_context,omitempty"`
HandoffResources []chat.HandoffResource `json:"handoff_resources,omitempty"`
+ HandoffActions []chat.HandoffAction `json:"handoff_actions,omitempty"`
AutonomousMode *bool `json:"autonomous_mode,omitempty"`
}
const (
chatRequestHandoffContextMaxBytes = 16 * 1024
chatRequestHandoffResourceLimit = 8
+ chatRequestHandoffActionLimit = 4
)
func chatAutonomousModeForScopedHandoff(requested *bool, handoffContext string, handoffResources []chat.HandoffResource, handoffActions []chat.HandoffAction) *bool {
@@ -833,6 +835,52 @@ func normalizeChatRequestHandoffResources(raw []chat.HandoffResource) []chat.Han
return resources
}
+func normalizeChatRequestHandoffActions(raw []chat.HandoffAction) []chat.HandoffAction {
+ actions := make([]chat.HandoffAction, 0, min(len(raw), chatRequestHandoffActionLimit))
+ for _, action := range raw {
+ if len(actions) >= chatRequestHandoffActionLimit {
+ break
+ }
+ normalized := chat.HandoffAction{
+ FindingID: trimChatHandoffField(action.FindingID, 256),
+ RecordID: trimChatHandoffField(action.RecordID, 256),
+ ApprovalID: trimChatHandoffField(action.ApprovalID, 256),
+ ApprovalStatus: trimChatHandoffField(action.ApprovalStatus, 64),
+ ApprovalRequestedAt: trimChatHandoffField(action.ApprovalRequestedAt, 64),
+ ApprovalExpiresAt: trimChatHandoffField(action.ApprovalExpiresAt, 64),
+ ApprovalDecidedAt: trimChatHandoffField(action.ApprovalDecidedAt, 64),
+ ApprovalConsumed: action.ApprovalConsumed,
+ ActionID: trimChatHandoffField(action.ActionID, 256),
+ ActionState: trimChatHandoffField(action.ActionState, 64),
+ ActionUpdatedAt: trimChatHandoffField(action.ActionUpdatedAt, 64),
+ ActionRequestedBy: trimChatHandoffField(action.ActionRequestedBy, 128),
+ ActionCapability: trimChatHandoffField(action.ActionCapability, 128),
+ ActionApprovalPolicy: trimChatHandoffField(action.ActionApprovalPolicy, 64),
+ ActionRequiresApproval: action.ActionRequiresApproval,
+ ActionPlanExpiresAt: trimChatHandoffField(action.ActionPlanExpiresAt, 64),
+ ActionPlanMessage: trimChatHandoffField(action.ActionPlanMessage, 512),
+ ActionPreflight: trimChatHandoffField(action.ActionPreflight, 512),
+ ActionDryRunSummary: trimChatHandoffField(action.ActionDryRunSummary, 512),
+ ActionResult: trimChatHandoffField(action.ActionResult, 64),
+ FixID: trimChatHandoffField(action.FixID, 256),
+ Description: trimChatHandoffField(action.Description, 512),
+ RiskLevel: trimChatHandoffField(action.RiskLevel, 64),
+ Destructive: action.Destructive,
+ TargetHost: trimChatHandoffField(action.TargetHost, 256),
+ TargetResourceID: trimChatHandoffField(action.TargetResourceID, 256),
+ TargetResourceName: trimChatHandoffField(action.TargetResourceName, 256),
+ TargetResourceType: canonicalizeChatMentionType(action.TargetResourceType),
+ TargetNode: trimChatHandoffField(action.TargetNode, 256),
+ }
+ if handoffActionHasBriefingValue(normalized) ||
+ strings.TrimSpace(normalized.FindingID) != "" ||
+ strings.TrimSpace(normalized.TargetResourceID) != "" {
+ actions = append(actions, normalized)
+ }
+ }
+ return actions
+}
+
func trimChatHandoffField(raw string, limit int) string {
value := strings.TrimSpace(raw)
if len(value) <= limit {
@@ -2202,7 +2250,7 @@ func (h *AIHandler) HandleChat(w http.ResponseWriter, r *http.Request) {
// as the user's authored prompt, so conversation history stays readable.
handoffContext := normalizeChatRequestHandoffContext(req.HandoffContext)
handoffResources := normalizeChatRequestHandoffResources(req.HandoffResources)
- var handoffActions []chat.HandoffAction
+ handoffActions := normalizeChatRequestHandoffActions(req.HandoffActions)
findingID := strings.TrimSpace(req.FindingID)
if findingID == "" && strings.TrimSpace(req.SessionID) != "" {
if storedFindingID, err := svc.GetModelHandoffFindingID(ctx, req.SessionID); err != nil {
diff --git a/internal/api/ai_handler_test.go b/internal/api/ai_handler_test.go
index be6c713f8b..38bc261e09 100644
--- a/internal/api/ai_handler_test.go
+++ b/internal/api/ai_handler_test.go
@@ -593,12 +593,32 @@ func TestHandleChat_PassesScopedHandoffContext(t *testing.T) {
Type: "storage",
Node: "nas-1",
}}, reqArg.HandoffResources)
+ assert.Equal(t, []chat.HandoffAction{{
+ FindingID: "finding-123",
+ ApprovalID: "approval-123",
+ ApprovalStatus: "pending",
+ ApprovalRequestedAt: "2026-05-06T12:00:00Z",
+ ApprovalExpiresAt: "2026-05-06T12:10:00Z",
+ ActionID: "action-123",
+ ActionApprovalPolicy: "admin",
+ ActionRequiresApproval: true,
+ ActionPlanExpiresAt: "2026-05-06T12:10:00Z",
+ ActionDryRunSummary: "No provider-supported dry run is available for this action.",
+ FixID: "fix-123",
+ Description: "Restart the workload service",
+ RiskLevel: "high",
+ Destructive: true,
+ TargetResourceID: "vm-100",
+ TargetResourceName: "web-server",
+ TargetResourceType: "vm",
+ }}, reqArg.HandoffActions)
+ assert.NotContains(t, fmt.Sprintf("%#v", reqArg.HandoffActions), "systemctl restart")
if assert.NotNil(t, reqArg.AutonomousMode) {
assert.False(t, *reqArg.AutonomousMode)
}
})
- body := `{"prompt":"discuss incident","autonomous_mode":true,"handoff_context":"[Alert Incident Context]\nIncident ID: incident-1\nTimeline Event 1: Command | Command event recorded","handoff_resources":[{"id":"storage-1","name":"tank","type":"storage","node":"nas-1"}]}`
+ body := `{"prompt":"discuss incident","autonomous_mode":true,"handoff_context":"[Alert Incident Context]\nIncident ID: incident-1\nTimeline Event 1: Command | Command event recorded","handoff_resources":[{"id":"storage-1","name":"tank","type":"storage","node":"nas-1"}],"handoff_actions":[{"finding_id":"finding-123","approval_id":"approval-123","approval_status":"pending","approval_requested_at":"2026-05-06T12:00:00Z","approval_expires_at":"2026-05-06T12:10:00Z","action_id":"action-123","action_approval_policy":"admin","action_requires_approval":true,"action_plan_expires_at":"2026-05-06T12:10:00Z","action_dry_run_summary":"No provider-supported dry run is available for this action.","fix_id":"fix-123","description":"Restart the workload service","risk_level":"high","destructive":true,"target_resource_id":"vm-100","target_resource_name":"web-server","target_resource_type":"vm"}]}`
req := httptest.NewRequest("POST", "/api/ai/chat", strings.NewReader(body))
w := httptest.NewRecorder()
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 3c5731ade1..9615322e3f 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -142,6 +142,9 @@ func TestContract_AssistantFindingContextUsesModelOnlyHandoff(t *testing.T) {
for _, required := range []string{
`svc.GetModelHandoffFindingID(ctx, req.SessionID)`,
`svc.ClearModelHandoffContext(ctx, sessionID)`,
+ `HandoffActions []chat.HandoffAction ` + "`json:\"handoff_actions,omitempty\"`",
+ "handoffActions := normalizeChatRequestHandoffActions(req.HandoffActions)",
+ "chatRequestHandoffActionLimit",
"handoffActions = buildUnifiedFindingHandoffActions(f, orgID)",
"handoffContext = buildUnifiedFindingChatContext(f, store, handoffActions)",
"handoffResources = buildUnifiedFindingHandoffResources(f, store)",