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.

Allow monitor Patrol autonomy saves without Pro

rcourtman8e17f1660570
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 3a63857923..37839906db 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -214,6 +214,10 @@ profile and assignment columns, but embedded table framing must route through
handlers and connection ledgers, but they must remain settings/API
availability resources and must not create install commands, agent tokens, or
host uninstall/stop-monitoring lifecycle actions.
+ Patrol autonomy API changes are likewise adjacent when they touch shared
+ `internal/api/` route wiring: monitor-mode configuration and remediation
+ entitlement payloads remain AI runtime/API-contract owned and must not create
+ agent lifecycle authority, install-token scope, or fleet command semantics.
Hosted handoff subjects consumed through the shared API auth boundary must
already be stable, non-email principals; lifecycle-adjacent routes must not
recover authority from a blank handoff subject by falling back to contact
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 16823544bb..174dd029c9 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -1246,3 +1246,8 @@ runtime services may reuse one canonical executor configuration, but each chat
or Patrol run must clone that executor before attaching resolved-context,
approval-routing, or patrol-finding state so concurrent sessions cannot
overwrite one another's mutable runtime context.
+That same Patrol runtime boundary owns Community monitor-mode autonomy saves.
+The open-source/free `PUT /api/ai/patrol/autonomy` adapter may persist
+findings-only `monitor` configuration and the governed investigation budget /
+timeout clamps, but it must continue to reject `approval`, `assisted`, and
+`full` autonomy with the canonical safe-remediation license response.
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 9b8402210a..f7f8f84bff 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -827,6 +827,10 @@ the canonical monitored-system blocked payload.
generic hosted AI quota, anonymous Community entitlement, trial CTA,
account-backed activation support, or full-chat entitlement in normal
self-hosted v6 GA UI
+ and the Patrol autonomy save contract, so Community/free runtime payloads
+ may persist only `monitor` autonomy settings through
+ `/api/ai/patrol/autonomy`, while `approval`, `assisted`, and `full` return
+ the canonical license-required response instead of a generic save failure
and the structured investigation-record contract, so unified findings may
expose `investigation_record` only through the shared
`aicontracts.InvestigationRecord` payload shape, with frontend API types
@@ -3727,3 +3731,9 @@ re-introduce a per-tab gate on this boundary. The discovery subnet settings
write path through `SettingsAPI.updateSystemSettings` remains governed by the
shared `internal/api/` settings boundary and is unaffected by the polling
scope change.
+The shared Patrol autonomy API contract now separates findings-only monitor
+configuration from paid remediation autonomy. `GET /api/ai/patrol/autonomy`
+continues to clamp effective Community autonomy to `monitor`, and
+`PUT /api/ai/patrol/autonomy` in the open-source/free adapter must accept and
+persist only `monitor` settings while returning the canonical license-required
+payload for investigation or remediation autonomy levels.
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
index 75818e5ae0..ace4150a1f 100644
--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md
+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md
@@ -701,7 +701,10 @@ frontend primitive boundary.
commercial-facing Patrol capability language: Pro-locked helper copy,
autonomy segmented controls, and run-history/result labels must use
`Remediate`, `remediated`, or safe remediation wording while legacy API
- names remain hidden from operators.
+ names remain hidden from operators. The Patrol configuration popover is part
+ of that shared feature-presentation boundary: it must stay viewport-bounded,
+ expose an accessible dialog label, and pass backend save rejection reasons
+ through to the toast surface instead of replacing them with generic copy.
19. Keep the shared `system-ai` settings shell product-first.
`frontend-modern/src/components/Settings/AISettings.tsx`,
`frontend-modern/src/components/Settings/settingsHeaderMeta.ts`,
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
index d6e954613f..db011e0dc4 100644
--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
@@ -317,6 +317,11 @@ suppress stale healthy summary headlines such as `Health A · 100/100` even if
the last summary payload still looks healthy. Legacy `/ai` entry points must
redirect into that same Patrol-owned shell rather than preserving a second
canonical route.
+That same browser proof now covers the Patrol configuration save contract.
+The advanced Patrol panel must stay within the desktop viewport, scroll its
+own contents to the Apply control, and surface the backend's concrete
+license/validation reason when a save is rejected instead of replacing it with
+a generic `Failed to save advanced settings` toast.
That same Patrol-owned presentation rule also applies to the findings empty
state: `frontend-modern/src/components/AI/FindingsPanel.tsx` must not treat
`0 active findings` as equivalent to "your infrastructure looks healthy" when
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 460c66540e..2ae8f51489 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -221,6 +221,10 @@ bypass the API fail-closed execution gate.
those notes. Recovery-adjacent diagnostics consumers must preserve the
source-specific Docker / Podman wording and recovery destinations governed
by the shared diagnostics API contract.
+ Shared Patrol autonomy routes may also touch broad `internal/api/` wiring,
+ but monitor-mode AI configuration and remediation entitlement responses stay
+ AI runtime/API-contract owned and must not become recovery-local policy,
+ storage remediation authority, or storage-specific license semantics.
Adjacent Docker / Podman management routes may also share `internal/api/`
transport with storage/recovery. Storage and recovery consumers must
preserve the API-owned Docker / Podman agent or host wording for management
diff --git a/frontend-modern/src/features/patrol/PatrolIntelligenceHeader.tsx b/frontend-modern/src/features/patrol/PatrolIntelligenceHeader.tsx
index f8c1f00ceb..ee682e80b0 100644
--- a/frontend-modern/src/features/patrol/PatrolIntelligenceHeader.tsx
+++ b/frontend-modern/src/features/patrol/PatrolIntelligenceHeader.tsx
@@ -172,7 +172,11 @@ export function PatrolIntelligenceHeader(props: { state: PatrolIntelligenceState
</button>
<Show when={state.showAdvancedSettings()}>
- <div class="fixed right-4 top-32 z-[9999] isolate max-h-[calc(100vh-10rem)] w-[calc(100vw-2rem)] overflow-y-auto rounded-md border border-border bg-surface p-5 shadow-sm animate-slide-up transform origin-top-right sm:right-8 sm:top-[13rem] sm:max-h-[36rem] sm:w-[340px]">
+ <div
+ role="dialog"
+ aria-label="Patrol Configuration"
+ class="fixed right-4 top-32 z-[9999] isolate max-h-[calc(100vh-10rem)] w-[calc(100vw-2rem)] overflow-y-auto rounded-md border border-border bg-surface p-5 shadow-sm animate-slide-up transform origin-top-right sm:right-8 sm:top-[13rem] sm:max-h-[calc(100vh-14rem)] sm:w-[340px]"
+ >
<div class="flex items-center justify-between mb-5 pb-3 border-b border-border-subtle">
<h4 class="text-base font-semibold tracking-tight text-base-content">
Patrol Configuration
diff --git a/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts b/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts
index 0cd084eccb..9149679cbd 100644
--- a/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts
+++ b/frontend-modern/src/features/patrol/usePatrolIntelligenceState.ts
@@ -509,7 +509,7 @@ export function usePatrolIntelligenceState() {
setShowAdvancedSettings(false);
} catch (err) {
console.error('Failed to save advanced settings:', err);
- notificationStore.error('Failed to save advanced settings');
+ notificationStore.error((err as Error).message || 'Failed to save advanced settings');
} finally {
setIsSavingAdvanced(false);
}
diff --git a/internal/api/ai_handlers.go b/internal/api/ai_handlers.go
index 2c18120d11..c30877597c 100644
--- a/internal/api/ai_handlers.go
+++ b/internal/api/ai_handlers.go
@@ -6723,8 +6723,92 @@ func (h *AISettingsHandler) HandleGetPatrolAutonomy(w http.ResponseWriter, r *ht
json.NewEncoder(w).Encode(settings)
}
-// HandleUpdatePatrolAutonomy has been moved to enterprise.
-// The route now delegates to aiAutoFixEndpoints.HandleUpdatePatrolAutonomy.
+// HandleUpdatePatrolAutonomyMonitorOnly persists findings-only Patrol autonomy
+// settings for builds without the safe remediation extension.
+func (h *AISettingsHandler) HandleUpdatePatrolAutonomyMonitorOnly(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodPut {
+ http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
+ return
+ }
+
+ aiService := h.GetAIService(r.Context())
+ if aiService == nil {
+ writeErrorResponse(w, http.StatusServiceUnavailable, "service_unavailable", "Pulse Patrol service not available", nil)
+ return
+ }
+ cfg := aiService.GetConfig()
+ if cfg == nil {
+ writeErrorResponse(w, http.StatusServiceUnavailable, "not_configured", "Pulse Patrol not configured", nil)
+ return
+ }
+
+ var req PatrolAutonomySettings
+ if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
+ writeErrorResponse(w, http.StatusBadRequest, "invalid_request", "Invalid request body", nil)
+ return
+ }
+ if !config.IsValidPatrolAutonomyLevel(req.AutonomyLevel) {
+ writeErrorResponse(w, http.StatusBadRequest, "invalid_autonomy_level",
+ fmt.Sprintf("Invalid autonomy level: %s. Must be 'monitor', 'approval', 'assisted', or 'full'", req.AutonomyLevel), nil)
+ return
+ }
+ if req.AutonomyLevel != config.PatrolAutonomyMonitor {
+ WriteLicenseRequired(w, featureAIAutoFixKey, "Investigation and auto-fix require Pulse Pro. Community tier is limited to Monitor (findings-only) autonomy.")
+ return
+ }
+
+ if req.InvestigationBudget < 5 {
+ req.InvestigationBudget = 5
+ }
+ if req.InvestigationBudget > 30 {
+ req.InvestigationBudget = 30
+ }
+ if req.InvestigationTimeoutSec < 60 {
+ req.InvestigationTimeoutSec = 60
+ }
+ if req.InvestigationTimeoutSec > 1800 {
+ req.InvestigationTimeoutSec = 1800
+ }
+
+ effectiveUnlocked := cfg.PatrolFullModeUnlocked
+ if req.FullModeUnlocked != nil {
+ effectiveUnlocked = *req.FullModeUnlocked
+ }
+
+ cfg.PatrolAutonomyLevel = config.PatrolAutonomyMonitor
+ cfg.PatrolFullModeUnlocked = effectiveUnlocked
+ cfg.PatrolInvestigationBudget = req.InvestigationBudget
+ cfg.PatrolInvestigationTimeoutSec = req.InvestigationTimeoutSec
+
+ persistence := h.getPersistence(r.Context())
+ if persistence == nil {
+ writeErrorResponse(w, http.StatusServiceUnavailable, "not_configured", "Pulse Patrol not configured", nil)
+ return
+ }
+ if err := persistence.SaveAIConfig(*cfg); err != nil {
+ writeErrorResponse(w, http.StatusInternalServerError, "save_failed", "Failed to save Pulse Assistant config", nil)
+ return
+ }
+ if err := aiService.LoadConfig(); err != nil {
+ log.Warn().Err(err).Msg("Patrol autonomy settings saved but config reload failed")
+ }
+
+ settings := PatrolAutonomyResponse{
+ AutonomyLevel: config.PatrolAutonomyMonitor,
+ FullModeUnlocked: effectiveUnlocked,
+ InvestigationBudget: req.InvestigationBudget,
+ InvestigationTimeoutSec: req.InvestigationTimeoutSec,
+ }
+ if err := utils.WriteJSONResponse(w, map[string]interface{}{
+ "success": true,
+ "settings": settings,
+ }); err != nil {
+ log.Error().Err(err).Msg("Failed to write patrol autonomy update response")
+ }
+}
+
+// Premium Patrol autonomy updates have been moved to enterprise.
+// The route delegates to aiAutoFixEndpoints.HandleUpdatePatrolAutonomy.
// maxFindingIDLength is the maximum allowed length for finding IDs in URL paths.
// Real finding IDs are 16 hex chars (SHA256[:8]), but we accept up to 256 for
diff --git a/internal/api/ai_handlers_test.go b/internal/api/ai_handlers_test.go
index 0cf8633b9d..574b827238 100644
--- a/internal/api/ai_handlers_test.go
+++ b/internal/api/ai_handlers_test.go
@@ -64,6 +64,43 @@ func TestAIHandlersUseSafeRemediationCommercialCopy(t *testing.T) {
}
}
+func TestAISettingsHandler_PatrolAutonomyMonitorOnlyAllowsMonitor(t *testing.T) {
+ tmp := t.TempDir()
+ cfg := &config.Config{DataPath: tmp}
+ persistence := config.NewConfigPersistence(tmp)
+ handler := newTestAISettingsHandler(cfg, persistence, nil)
+
+ body := `{"autonomy_level":"monitor","investigation_budget":2,"investigation_timeout_sec":30}`
+ req := newLoopbackRequest(http.MethodPut, "/api/ai/patrol/autonomy", strings.NewReader(body))
+ rec := httptest.NewRecorder()
+ handler.HandleUpdatePatrolAutonomyMonitorOnly(rec, req)
+
+ require.Equal(t, http.StatusOK, rec.Code, rec.Body.String())
+ var resp struct {
+ Success bool `json:"success"`
+ Settings PatrolAutonomyResponse `json:"settings"`
+ }
+ require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &resp))
+ require.True(t, resp.Success)
+ require.Equal(t, config.PatrolAutonomyMonitor, resp.Settings.AutonomyLevel)
+ require.Equal(t, 5, resp.Settings.InvestigationBudget)
+ require.Equal(t, 60, resp.Settings.InvestigationTimeoutSec)
+
+ saved, err := persistence.LoadAIConfig()
+ require.NoError(t, err)
+ require.Equal(t, config.PatrolAutonomyMonitor, saved.PatrolAutonomyLevel)
+ require.Equal(t, 5, saved.PatrolInvestigationBudget)
+ require.Equal(t, 60, saved.PatrolInvestigationTimeoutSec)
+
+ premiumBody := `{"autonomy_level":"approval","investigation_budget":10,"investigation_timeout_sec":120}`
+ premiumReq := newLoopbackRequest(http.MethodPut, "/api/ai/patrol/autonomy", strings.NewReader(premiumBody))
+ premiumRec := httptest.NewRecorder()
+ handler.HandleUpdatePatrolAutonomyMonitorOnly(premiumRec, premiumReq)
+
+ require.Equal(t, http.StatusPaymentRequired, premiumRec.Code, premiumRec.Body.String())
+ require.Contains(t, premiumRec.Body.String(), "limited to Monitor")
+}
+
func TestAISettingsHandler_GetAndUpdateSettings_RoundTrip(t *testing.T) {
t.Parallel()
diff --git a/internal/api/ai_patrol_community_limits_test.go b/internal/api/ai_patrol_community_limits_test.go
index d5f0fa6528..fa6876f06e 100644
--- a/internal/api/ai_patrol_community_limits_test.go
+++ b/internal/api/ai_patrol_community_limits_test.go
@@ -77,13 +77,54 @@ func TestPatrolCommunityAutonomyLockedToMonitor(t *testing.T) {
t.Fatalf("expected autonomy %q for Community, got %q", config.PatrolAutonomyMonitor, getResp.AutonomyLevel)
}
- // PUT via free adapter should return 402 for Community.
- freeAdapter := aiAutoFixFreeAdapter{}
- body := `{"autonomy_level":"approval","investigation_budget":10,"investigation_timeout_sec":120}`
+ // PUT via free adapter should allow findings-only monitor settings and
+ // persist the same clamped runtime limits used by the enterprise handler.
+ freeAdapter := aiAutoFixFreeAdapter{handler: handler}
+ body := `{"autonomy_level":"monitor","investigation_budget":2,"investigation_timeout_sec":30}`
putReq := httptest.NewRequest(http.MethodPut, "/api/ai/patrol/autonomy", strings.NewReader(body))
putRec := httptest.NewRecorder()
freeAdapter.HandleUpdatePatrolAutonomy(putRec, putReq)
- if putRec.Code != http.StatusPaymentRequired {
- t.Fatalf("expected 402 for Community autonomy update, got %d: %s", putRec.Code, putRec.Body.String())
+ if putRec.Code != http.StatusOK {
+ t.Fatalf("expected monitor update to be allowed for Community, got %d: %s", putRec.Code, putRec.Body.String())
+ }
+ var putResp struct {
+ Success bool `json:"success"`
+ Settings PatrolAutonomyResponse `json:"settings"`
+ }
+ if err := json.Unmarshal(putRec.Body.Bytes(), &putResp); err != nil {
+ t.Fatalf("failed to decode update response: %v", err)
+ }
+ if !putResp.Success {
+ t.Fatalf("expected successful update response, got %+v", putResp)
+ }
+ if putResp.Settings.AutonomyLevel != config.PatrolAutonomyMonitor {
+ t.Fatalf("expected saved autonomy %q, got %q", config.PatrolAutonomyMonitor, putResp.Settings.AutonomyLevel)
+ }
+ if putResp.Settings.InvestigationBudget != 5 || putResp.Settings.InvestigationTimeoutSec != 60 {
+ t.Fatalf("expected clamped budget/timeout 5/60, got %d/%d",
+ putResp.Settings.InvestigationBudget, putResp.Settings.InvestigationTimeoutSec)
+ }
+ saved, err := persistence.LoadAIConfig()
+ if err != nil {
+ t.Fatalf("LoadAIConfig: %v", err)
+ }
+ if saved.PatrolAutonomyLevel != config.PatrolAutonomyMonitor {
+ t.Fatalf("expected persisted autonomy %q, got %q", config.PatrolAutonomyMonitor, saved.PatrolAutonomyLevel)
+ }
+ if saved.PatrolInvestigationBudget != 5 || saved.PatrolInvestigationTimeoutSec != 60 {
+ t.Fatalf("expected persisted budget/timeout 5/60, got %d/%d",
+ saved.PatrolInvestigationBudget, saved.PatrolInvestigationTimeoutSec)
+ }
+
+ // Investigation/remediation autonomy remains Pro-gated.
+ approvalBody := `{"autonomy_level":"approval","investigation_budget":10,"investigation_timeout_sec":120}`
+ approvalReq := httptest.NewRequest(http.MethodPut, "/api/ai/patrol/autonomy", strings.NewReader(approvalBody))
+ approvalRec := httptest.NewRecorder()
+ freeAdapter.HandleUpdatePatrolAutonomy(approvalRec, approvalReq)
+ if approvalRec.Code != http.StatusPaymentRequired {
+ t.Fatalf("expected 402 for Community premium autonomy update, got %d: %s", approvalRec.Code, approvalRec.Body.String())
+ }
+ if !strings.Contains(approvalRec.Body.String(), "limited to Monitor") {
+ t.Fatalf("expected Pro gate response to explain monitor limit, got %s", approvalRec.Body.String())
}
}
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 94f1f6352e..e84dded01a 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -116,6 +116,51 @@ func TestPatrolRemediationCommercialCopyUsesSafeRemediationWording(t *testing.T)
}
}
+func TestContract_PatrolAutonomyCommunityMonitorUpdatePayload(t *testing.T) {
+ rawToken := "patrol-autonomy-contract-token-123.12345678"
+ record := newTokenRecord(t, rawToken, []string{config.ScopeSettingsWrite}, nil)
+ cfg := newTestConfigWithTokens(t, record)
+ router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")
+
+ body := `{"autonomy_level":"monitor","investigation_budget":2,"investigation_timeout_sec":30}`
+ req := httptest.NewRequest(http.MethodPut, "/api/ai/patrol/autonomy", strings.NewReader(body))
+ req.Header.Set("X-API-Token", rawToken)
+ rec := httptest.NewRecorder()
+ router.Handler().ServeHTTP(rec, req)
+
+ if rec.Code != http.StatusOK {
+ t.Fatalf("expected monitor autonomy update to be allowed, got %d: %s", rec.Code, rec.Body.String())
+ }
+ var resp struct {
+ Success bool `json:"success"`
+ Settings PatrolAutonomyResponse `json:"settings"`
+ }
+ if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
+ t.Fatalf("decode monitor update response: %v", err)
+ }
+ if !resp.Success {
+ t.Fatalf("expected success response, got %+v", resp)
+ }
+ if resp.Settings.AutonomyLevel != config.PatrolAutonomyMonitor ||
+ resp.Settings.InvestigationBudget != 5 ||
+ resp.Settings.InvestigationTimeoutSec != 60 {
+ t.Fatalf("unexpected monitor update settings: %+v", resp.Settings)
+ }
+
+ premiumBody := `{"autonomy_level":"approval","investigation_budget":10,"investigation_timeout_sec":120}`
+ premiumReq := httptest.NewRequest(http.MethodPut, "/api/ai/patrol/autonomy", strings.NewReader(premiumBody))
+ premiumReq.Header.Set("X-API-Token", rawToken)
+ premiumRec := httptest.NewRecorder()
+ router.Handler().ServeHTTP(premiumRec, premiumReq)
+
+ if premiumRec.Code != http.StatusPaymentRequired {
+ t.Fatalf("expected premium autonomy to require license, got %d: %s", premiumRec.Code, premiumRec.Body.String())
+ }
+ if !strings.Contains(premiumRec.Body.String(), "limited to Monitor") {
+ t.Fatalf("expected premium autonomy payload to explain Community monitor limit, got %s", premiumRec.Body.String())
+ }
+}
+
func TestContract_AssistantFindingContextUsesModelOnlyHandoff(t *testing.T) {
handlerSource, err := os.ReadFile(filepath.Clean("ai_handler.go"))
if err != nil {
diff --git a/internal/api/router_routes_ai_relay.go b/internal/api/router_routes_ai_relay.go
index 447dac6ddb..8409f0ba41 100644
--- a/internal/api/router_routes_ai_relay.go
+++ b/internal/api/router_routes_ai_relay.go
@@ -137,7 +137,8 @@ func (r *Router) registerAIRelayRoutesGroup() {
r.mux.HandleFunc("/api/ai/patrol/suppressions/", RequireAuth(r.config, RequireScope(config.ScopeAIExecute, r.aiSettingsHandler.HandleDeleteSuppressionRule)))
r.mux.HandleFunc("/api/ai/patrol/dismissed", RequireAuth(r.config, RequireScope(config.ScopeAIExecute, r.aiSettingsHandler.HandleGetDismissedFindings)))
- // Patrol Autonomy - GET stays in core (always returns current level); PUT is gated via extension
+ // Patrol Autonomy - GET stays in core; PUT is extension-gated for premium
+ // modes while the free adapter persists findings-only monitor settings.
r.mux.HandleFunc("/api/ai/patrol/autonomy", RequireAdmin(r.config, RequireScope(config.ScopeSettingsWrite, func(w http.ResponseWriter, req *http.Request) {
switch req.Method {
case http.MethodGet:
@@ -232,8 +233,12 @@ func (aiAutoFixFreeAdapter) HandleReapproveInvestigationFix(w http.ResponseWrite
WriteLicenseRequired(w, featureAIAutoFixKey, "Fix execution requires Pulse Pro")
}
-func (aiAutoFixFreeAdapter) HandleUpdatePatrolAutonomy(w http.ResponseWriter, _ *http.Request) {
- WriteLicenseRequired(w, featureAIAutoFixKey, "Patrol autonomy settings require Pulse Pro")
+func (a aiAutoFixFreeAdapter) HandleUpdatePatrolAutonomy(w http.ResponseWriter, r *http.Request) {
+ if a.handler != nil {
+ a.handler.HandleUpdatePatrolAutonomyMonitorOnly(w, r)
+ return
+ }
+ WriteLicenseRequired(w, featureAIAutoFixKey, "Investigation and auto-fix require Pulse Pro. Community tier is limited to Monitor (findings-only) autonomy.")
}
func (aiAutoFixFreeAdapter) HandleGetRemediationPlans(w http.ResponseWriter, _ *http.Request) {
diff --git a/tests/integration/tests/18-patrol-runtime-state.spec.ts b/tests/integration/tests/18-patrol-runtime-state.spec.ts
index 7f178d2147..c4929b81cb 100644
--- a/tests/integration/tests/18-patrol-runtime-state.spec.ts
+++ b/tests/integration/tests/18-patrol-runtime-state.spec.ts
@@ -1,9 +1,11 @@
-import { expect, test, type Page } from "@playwright/test";
+import { expect, test, type Page, type Route } from "@playwright/test";
import { ensureAuthenticated, trackBrowserRequests } from "./helpers";
const PATROL_BLOCK_REASON =
"Connect a provider to power Pulse Assistant and Patrol.";
+const PATROL_AUTONOMY_PRO_REQUIRED =
+ "Investigation and auto-fix require Pulse Pro. Community tier is limited to Monitor (findings-only) autonomy.";
function todayAt(hours: number, minutes: number): string {
const value = new Date();
@@ -221,7 +223,10 @@ const scopedTriggerPatrolStatus = {
},
};
-async function mockBlockedPatrolRuntimeState(page: Page): Promise<void> {
+async function mockBlockedPatrolRuntimeState(
+ page: Page,
+ options: { autonomyRoute?: (route: Route) => Promise<void> } = {},
+): Promise<void> {
await page.route("**/api/ai/patrol/status", async (route) => {
await route.fulfill({
status: 200,
@@ -239,6 +244,10 @@ async function mockBlockedPatrolRuntimeState(page: Page): Promise<void> {
});
await page.route("**/api/ai/patrol/autonomy", async (route) => {
+ if (options.autonomyRoute) {
+ await options.autonomyRoute(route);
+ return;
+ }
await route.fulfill({
status: 200,
contentType: "application/json",
@@ -325,6 +334,29 @@ async function mockBlockedPatrolRuntimeState(page: Page): Promise<void> {
});
}
+async function mockRuntimeCapabilities(
+ page: Page,
+ capabilities: string[],
+): Promise<void> {
+ await page.route("**/api/license/runtime-capabilities", async (route) => {
+ await route.fulfill({
+ status: 200,
+ contentType: "application/json",
+ body: JSON.stringify({
+ capabilities,
+ limits: [],
+ hosted_mode: false,
+ max_history_days: 7,
+ runtime: {
+ build: "community",
+ label: "Pulse Community runtime",
+ },
+ blocked_capabilities: [],
+ }),
+ });
+ });
+}
+
async function mockScopedTriggerPatrolRuntimeState(page: Page): Promise<void> {
await page.route("**/api/ai/patrol/status", async (route) => {
await route.fulfill({
@@ -492,7 +524,7 @@ test.describe("Patrol runtime-state browser contract", () => {
await mockBlockedPatrolRuntimeState(page);
await page.getByRole("tab", { name: "Patrol" }).click();
- await expect(page).toHaveURL(/\/ai/);
+ await expect(page).toHaveURL(/\/patrol/);
await expect(page.getByText("Patrol Paused").first()).toBeVisible();
await expect(page.getByText("Patrol paused").first()).toBeVisible();
@@ -508,6 +540,101 @@ test.describe("Patrol runtime-state browser contract", () => {
entitlementsRequests.stop();
});
+ test("shows the server reason when Patrol configuration save is rejected", async ({
+ page,
+ }, testInfo) => {
+ test.skip(
+ testInfo.project.name.startsWith("mobile-"),
+ "Desktop-only Patrol configuration coverage",
+ );
+
+ let autonomyUpdateCount = 0;
+
+ await mockRuntimeCapabilities(page, [
+ "ai_patrol",
+ "ai_autofix",
+ "ai_alerts",
+ ]);
+ await ensureAuthenticated(page);
+ await mockBlockedPatrolRuntimeState(page, {
+ autonomyRoute: async (route) => {
+ if (route.request().method() !== "PUT") {
+ await route.fulfill({
+ status: 200,
+ contentType: "application/json",
+ body: JSON.stringify({
+ autonomy_level: "monitor",
+ full_mode_unlocked: false,
+ investigation_budget: 15,
+ investigation_timeout_sec: 300,
+ }),
+ });
+ return;
+ }
+
+ autonomyUpdateCount += 1;
+ if (autonomyUpdateCount === 1) {
+ const payload = route.request().postDataJSON() as Record<
+ string,
+ unknown
+ >;
+ await route.fulfill({
+ status: 200,
+ contentType: "application/json",
+ body: JSON.stringify({
+ success: true,
+ settings: {
+ autonomy_level: payload.autonomy_level ?? "assisted",
+ full_mode_unlocked: payload.full_mode_unlocked ?? false,
+ investigation_budget: payload.investigation_budget ?? 15,
+ investigation_timeout_sec:
+ payload.investigation_timeout_sec ?? 300,
+ },
+ }),
+ });
+ return;
+ }
+
+ await route.fulfill({
+ status: 402,
+ contentType: "application/json",
+ body: JSON.stringify({
+ error: "license_required",
+ message: PATROL_AUTONOMY_PRO_REQUIRED,
+ feature: "ai_autofix",
+ upgrade_url: "https://www.pulseproxmox.com/pricing",
+ }),
+ });
+ },
+ });
+
+ await page.goto("/patrol", { waitUntil: "domcontentloaded" });
+ await page.getByRole("button", { name: "Configure Patrol" }).click();
+ const configPanel = page.getByRole("dialog", {
+ name: "Patrol Configuration",
+ });
+
+ const remediateButton = configPanel.getByRole("button", {
+ name: "Remediate",
+ });
+ await expect(remediateButton).toBeEnabled();
+ await remediateButton.click();
+ await expect.poll(() => autonomyUpdateCount).toBe(1);
+
+ await configPanel.evaluate((element) => {
+ element.scrollTop = element.scrollHeight;
+ });
+ const applyButton = configPanel.getByRole("button", {
+ name: "Apply Configuration",
+ });
+ await applyButton.click();
+
+ await expect(page.getByText(PATROL_AUTONOMY_PRO_REQUIRED)).toBeVisible();
+ await expect(page.getByText("Failed to save advanced settings")).toHaveCount(
+ 0,
+ );
+ });
+
test("surfaces scoped trigger context inside the summary and split trigger controls on the Patrol page", async ({
page,
}, testInfo) => {