diff --git a/docs/AI_AUTONOMY.md b/docs/AI_AUTONOMY.md index 8e1a99a1d4..2d6518ee27 100644 --- a/docs/AI_AUTONOMY.md +++ b/docs/AI_AUTONOMY.md @@ -74,6 +74,8 @@ pulse_api PUT /api/ai/patrol/autonomy <<'JSON' JSON ``` +Activating **Autopilot** (`"autonomy_level": "full"`) via `PUT /api/ai/patrol/autonomy` also requires an active `acknowledgement_id` created in the same authenticated human session via `POST /api/ai/patrol/autonomy/acknowledgements` (and revocable via `DELETE /api/ai/patrol/autonomy/acknowledgements/{id}`). Both acknowledgement endpoints require administrator access, `settings:write`, and a human browser session rather than an API token. + The helper's loopback origin is for requests made on the Pulse host. For remote use, change the origin and protocol restriction **in the helper** as the API guide describes, using your Pulse **HTTPS** URL with certificate verification @@ -162,7 +164,7 @@ When Patrol mode is `approval`, `assisted`, or `full`, Patrol investigates findi | `patrol_investigation_budget` | `investigation_budget` | 10 | 5-30 | Maximum evidence-tool calls per investigation. Patrol derives a separate model-response safety ceiling. | | `patrol_investigation_timeout_sec` | `investigation_timeout_sec` | 600 (1500 for subscription CLIs) | 60-1800 | Maximum seconds per investigation. Subscription agent CLIs (`codex-subscription`, `claude-subscription`) default to 1500 seconds (25 minutes) when unset. | -The following limits are fixed in the runtime and cannot be changed: up to 3 investigations run in parallel (up to 64 additional findings can wait in memory for a free slot, prioritised critical-first), up to 3 attempts per finding, a 1 hour default cooldown between investigation attempts, a 20 minute cooldown after a failed fix or failed fix verification, and a 10 minute cooldown after a timed-out outcome. Runs that fail before producing a conclusion, are interrupted by a restart, or end with unknown fix verification carry no extra cooldown and wait for the next scheduled Patrol cycle. +The following limits are fixed in the runtime and cannot be changed: up to 3 investigations run in parallel on metered API providers, local subscription agent CLIs (`codex-subscription`, `claude-subscription`) run 1 investigation at a time because each CLI serves one call at a time (`GetPatrolInvestigationConcurrency()`), and up to 64 additional findings can wait in memory for a free slot, prioritised critical-first then longest waiting (`maxDeferredInvestigations`, cleared on restart). Patrol also enforces up to 3 attempts per finding, a 1 hour default cooldown between investigation attempts, a 20 minute cooldown after a failed fix or failed fix verification, and a 10 minute cooldown after a timed-out outcome. Runs that fail before producing a conclusion, are interrupted by a restart, or end with unknown fix verification carry no extra cooldown and wait for the next scheduled Patrol cycle. Background Patrol action plans, including refreshed Patrol plans, stay open for approval for 24 hours before expiring, matching investigation retention. Direct API and interactive action plans keep the 5-minute default expiry. Live freshness, policy, and emergency-stop checks still run when an approved plan executes. diff --git a/docs/OPERATIONAL_TRUST.md b/docs/OPERATIONAL_TRUST.md index 4186cfed68..b05f95bb60 100644 --- a/docs/OPERATIONAL_TRUST.md +++ b/docs/OPERATIONAL_TRUST.md @@ -159,18 +159,31 @@ segments. ## Metrics -The `/metrics` listener exposes Operational Trust counters and histograms under -`pulse_operational_trust_*`. Labels use closed, low-cardinality vocabularies; -resource IDs, evidence IDs, provider-instance names, actors, and destination -IDs never appear as labels. +The `/metrics` listener exposes ten Operational Trust counters and histograms +under `pulse_operational_trust_*` (`internal/operationaltrust/metrics.go`). +Labels use closed, low-cardinality vocabularies. Resource IDs, evidence IDs, +provider-instance names, actors, and destination IDs never appear as labels: + +| Metric | Type | Labels / bounded values | +| :--- | :--- | :--- | +| `pulse_operational_trust_observation_to_open_seconds` | Histogram | None (elapsed seconds from first observation to open record) | +| `pulse_operational_trust_open_to_notification_enqueue_seconds` | Histogram | None (elapsed seconds from open transition to notification enqueue) | +| `pulse_operational_trust_evidence_observations_total` | Counter | `source` (bounded provider or `other`), `state` (`current`, `stale`, `unknown`, `partial`, `unavailable`, `partial_permission`, `denied`) | +| `pulse_operational_trust_identity_correlations_total` | Counter | `outcome` (`attached`, `standalone`, `ambiguous`, `unresolved`, `other`) | +| `pulse_operational_trust_protection_posture_evaluations_total` | Counter | `state` (`protected`, `attention`, `unprotected`, `unknown`, `other`) | +| `pulse_operational_trust_protection_posture_evaluation_failures_total` | Counter | `reason` (`invalid_policy`, `invalid_posture`, `store`, `provider`, `other`) | +| `pulse_operational_trust_notification_delivery_total` | Counter | `outcome` (`queued`, `retry`, `sent`, `failed`, `dead_letter`, `cancelled`, `other`) | +| `pulse_operational_trust_active_count_mismatch_total` | Counter | None (canonical active count vs attention projection mismatches) | +| `pulse_operational_trust_action_offers_total` | Counter | `eligibility` (`eligible`, `ineligible`, `unknown`, `other`) | +| `pulse_operational_trust_action_verification_total` | Counter | `outcome` (`pending`, `confirmed`, `contradicted`, `inconclusive`, `timed_out`, `not_attempted`, `other`) | Useful alerts include: -- sustained growth in `active_count_mismatch_total`; -- notification `failed` or `dead_letter` outcomes; -- growing stale, unavailable, denied, or partial evidence observations; -- identity `ambiguous` or `unresolved` outcomes; -- action verification `contradicted`, `inconclusive`, or `timed_out` outcomes. +- sustained growth in `pulse_operational_trust_active_count_mismatch_total` +- `pulse_operational_trust_notification_delivery_total` with `outcome` `failed` or `dead_letter` +- growing `stale`, `unavailable`, `denied`, `partial_permission`, or `partial` counts in `pulse_operational_trust_evidence_observations_total` +- `ambiguous` or `unresolved` outcomes in `pulse_operational_trust_identity_correlations_total` +- `contradicted`, `inconclusive`, or `timed_out` outcomes in `pulse_operational_trust_action_verification_total` ## Upgrade and compatibility diff --git a/docs/PATROL_ARCHITECTURE.md b/docs/PATROL_ARCHITECTURE.md index bc900a022d..1ee1838ad0 100644 --- a/docs/PATROL_ARCHITECTURE.md +++ b/docs/PATROL_ARCHITECTURE.md @@ -147,6 +147,17 @@ Patrol also recovers investigations that were left running and retries ones that timed out. See `recoverStuckInvestigations` and `retryTimedOutInvestigations` in `internal/ai/patrol_findings.go`. +**Concurrency and deferred queue:** `GetPatrolInvestigationConcurrency()` in +`internal/config/ai.go` admits up to `3` parallel investigations on metered API +providers (`MaxConcurrentInvestigations`) and `1` at a time on local +`codex-subscription` and `claude-subscription` CLIs. When every slot is busy, +`FindingsStore.DeferInvestigation` in `internal/ai/patrol_investigation_queue.go` +holds up to `64` additional findings in memory (`maxDeferredInvestigations`), +dequeuing critical findings before warnings and then longest waiting +(`TakeNextDeferredInvestigation`), and re-checking `Finding.ShouldInvestigate` +before starting each queued run. Because the deferred list lives in memory, +waiting findings are picked up again on a later Patrol run after a restart. + ### Turn budgets and stuck-run recovery Investigation turns use caller-owned stall and deadline budgets in diff --git a/docs/UNIFIED_RESOURCES.md b/docs/UNIFIED_RESOURCES.md index cf3a7416de..dcd832373d 100644 --- a/docs/UNIFIED_RESOURCES.md +++ b/docs/UNIFIED_RESOURCES.md @@ -152,6 +152,6 @@ The hook hydrates from the WebSocket state when available and falls back to the ## See Also - [Architecture](../ARCHITECTURE.md) — system architecture overview -- [Migration Guide](MIGRATION_UNIFIED_NAV.md) — upgrading from platform-specific navigation +- [Retired unified-navigation migration](MIGRATION_UNIFIED_NAV.md): historical context and platform-shaped equivalents for retired `/workloads`, `/storage`, and `/recovery` routes - [API Reference](API.md) — full API documentation - [TrueNAS Integration](TRUENAS.md) — TrueNAS-specific details diff --git a/frontend-modern/public/docs/AI_AUTONOMY.md b/frontend-modern/public/docs/AI_AUTONOMY.md index 8e1a99a1d4..2d6518ee27 100644 --- a/frontend-modern/public/docs/AI_AUTONOMY.md +++ b/frontend-modern/public/docs/AI_AUTONOMY.md @@ -74,6 +74,8 @@ pulse_api PUT /api/ai/patrol/autonomy <<'JSON' JSON ``` +Activating **Autopilot** (`"autonomy_level": "full"`) via `PUT /api/ai/patrol/autonomy` also requires an active `acknowledgement_id` created in the same authenticated human session via `POST /api/ai/patrol/autonomy/acknowledgements` (and revocable via `DELETE /api/ai/patrol/autonomy/acknowledgements/{id}`). Both acknowledgement endpoints require administrator access, `settings:write`, and a human browser session rather than an API token. + The helper's loopback origin is for requests made on the Pulse host. For remote use, change the origin and protocol restriction **in the helper** as the API guide describes, using your Pulse **HTTPS** URL with certificate verification @@ -162,7 +164,7 @@ When Patrol mode is `approval`, `assisted`, or `full`, Patrol investigates findi | `patrol_investigation_budget` | `investigation_budget` | 10 | 5-30 | Maximum evidence-tool calls per investigation. Patrol derives a separate model-response safety ceiling. | | `patrol_investigation_timeout_sec` | `investigation_timeout_sec` | 600 (1500 for subscription CLIs) | 60-1800 | Maximum seconds per investigation. Subscription agent CLIs (`codex-subscription`, `claude-subscription`) default to 1500 seconds (25 minutes) when unset. | -The following limits are fixed in the runtime and cannot be changed: up to 3 investigations run in parallel (up to 64 additional findings can wait in memory for a free slot, prioritised critical-first), up to 3 attempts per finding, a 1 hour default cooldown between investigation attempts, a 20 minute cooldown after a failed fix or failed fix verification, and a 10 minute cooldown after a timed-out outcome. Runs that fail before producing a conclusion, are interrupted by a restart, or end with unknown fix verification carry no extra cooldown and wait for the next scheduled Patrol cycle. +The following limits are fixed in the runtime and cannot be changed: up to 3 investigations run in parallel on metered API providers, local subscription agent CLIs (`codex-subscription`, `claude-subscription`) run 1 investigation at a time because each CLI serves one call at a time (`GetPatrolInvestigationConcurrency()`), and up to 64 additional findings can wait in memory for a free slot, prioritised critical-first then longest waiting (`maxDeferredInvestigations`, cleared on restart). Patrol also enforces up to 3 attempts per finding, a 1 hour default cooldown between investigation attempts, a 20 minute cooldown after a failed fix or failed fix verification, and a 10 minute cooldown after a timed-out outcome. Runs that fail before producing a conclusion, are interrupted by a restart, or end with unknown fix verification carry no extra cooldown and wait for the next scheduled Patrol cycle. Background Patrol action plans, including refreshed Patrol plans, stay open for approval for 24 hours before expiring, matching investigation retention. Direct API and interactive action plans keep the 5-minute default expiry. Live freshness, policy, and emergency-stop checks still run when an approved plan executes. diff --git a/frontend-modern/public/docs/OPERATIONAL_TRUST.md b/frontend-modern/public/docs/OPERATIONAL_TRUST.md index 4186cfed68..b05f95bb60 100644 --- a/frontend-modern/public/docs/OPERATIONAL_TRUST.md +++ b/frontend-modern/public/docs/OPERATIONAL_TRUST.md @@ -159,18 +159,31 @@ segments. ## Metrics -The `/metrics` listener exposes Operational Trust counters and histograms under -`pulse_operational_trust_*`. Labels use closed, low-cardinality vocabularies; -resource IDs, evidence IDs, provider-instance names, actors, and destination -IDs never appear as labels. +The `/metrics` listener exposes ten Operational Trust counters and histograms +under `pulse_operational_trust_*` (`internal/operationaltrust/metrics.go`). +Labels use closed, low-cardinality vocabularies. Resource IDs, evidence IDs, +provider-instance names, actors, and destination IDs never appear as labels: + +| Metric | Type | Labels / bounded values | +| :--- | :--- | :--- | +| `pulse_operational_trust_observation_to_open_seconds` | Histogram | None (elapsed seconds from first observation to open record) | +| `pulse_operational_trust_open_to_notification_enqueue_seconds` | Histogram | None (elapsed seconds from open transition to notification enqueue) | +| `pulse_operational_trust_evidence_observations_total` | Counter | `source` (bounded provider or `other`), `state` (`current`, `stale`, `unknown`, `partial`, `unavailable`, `partial_permission`, `denied`) | +| `pulse_operational_trust_identity_correlations_total` | Counter | `outcome` (`attached`, `standalone`, `ambiguous`, `unresolved`, `other`) | +| `pulse_operational_trust_protection_posture_evaluations_total` | Counter | `state` (`protected`, `attention`, `unprotected`, `unknown`, `other`) | +| `pulse_operational_trust_protection_posture_evaluation_failures_total` | Counter | `reason` (`invalid_policy`, `invalid_posture`, `store`, `provider`, `other`) | +| `pulse_operational_trust_notification_delivery_total` | Counter | `outcome` (`queued`, `retry`, `sent`, `failed`, `dead_letter`, `cancelled`, `other`) | +| `pulse_operational_trust_active_count_mismatch_total` | Counter | None (canonical active count vs attention projection mismatches) | +| `pulse_operational_trust_action_offers_total` | Counter | `eligibility` (`eligible`, `ineligible`, `unknown`, `other`) | +| `pulse_operational_trust_action_verification_total` | Counter | `outcome` (`pending`, `confirmed`, `contradicted`, `inconclusive`, `timed_out`, `not_attempted`, `other`) | Useful alerts include: -- sustained growth in `active_count_mismatch_total`; -- notification `failed` or `dead_letter` outcomes; -- growing stale, unavailable, denied, or partial evidence observations; -- identity `ambiguous` or `unresolved` outcomes; -- action verification `contradicted`, `inconclusive`, or `timed_out` outcomes. +- sustained growth in `pulse_operational_trust_active_count_mismatch_total` +- `pulse_operational_trust_notification_delivery_total` with `outcome` `failed` or `dead_letter` +- growing `stale`, `unavailable`, `denied`, `partial_permission`, or `partial` counts in `pulse_operational_trust_evidence_observations_total` +- `ambiguous` or `unresolved` outcomes in `pulse_operational_trust_identity_correlations_total` +- `contradicted`, `inconclusive`, or `timed_out` outcomes in `pulse_operational_trust_action_verification_total` ## Upgrade and compatibility diff --git a/frontend-modern/public/docs/PATROL_ARCHITECTURE.md b/frontend-modern/public/docs/PATROL_ARCHITECTURE.md index bc900a022d..1ee1838ad0 100644 --- a/frontend-modern/public/docs/PATROL_ARCHITECTURE.md +++ b/frontend-modern/public/docs/PATROL_ARCHITECTURE.md @@ -147,6 +147,17 @@ Patrol also recovers investigations that were left running and retries ones that timed out. See `recoverStuckInvestigations` and `retryTimedOutInvestigations` in `internal/ai/patrol_findings.go`. +**Concurrency and deferred queue:** `GetPatrolInvestigationConcurrency()` in +`internal/config/ai.go` admits up to `3` parallel investigations on metered API +providers (`MaxConcurrentInvestigations`) and `1` at a time on local +`codex-subscription` and `claude-subscription` CLIs. When every slot is busy, +`FindingsStore.DeferInvestigation` in `internal/ai/patrol_investigation_queue.go` +holds up to `64` additional findings in memory (`maxDeferredInvestigations`), +dequeuing critical findings before warnings and then longest waiting +(`TakeNextDeferredInvestigation`), and re-checking `Finding.ShouldInvestigate` +before starting each queued run. Because the deferred list lives in memory, +waiting findings are picked up again on a later Patrol run after a restart. + ### Turn budgets and stuck-run recovery Investigation turns use caller-owned stall and deadline budgets in diff --git a/frontend-modern/public/docs/UNIFIED_RESOURCES.md b/frontend-modern/public/docs/UNIFIED_RESOURCES.md index cf3a7416de..dcd832373d 100644 --- a/frontend-modern/public/docs/UNIFIED_RESOURCES.md +++ b/frontend-modern/public/docs/UNIFIED_RESOURCES.md @@ -152,6 +152,6 @@ The hook hydrates from the WebSocket state when available and falls back to the ## See Also - [Architecture](../ARCHITECTURE.md) — system architecture overview -- [Migration Guide](MIGRATION_UNIFIED_NAV.md) — upgrading from platform-specific navigation +- [Retired unified-navigation migration](MIGRATION_UNIFIED_NAV.md): historical context and platform-shaped equivalents for retired `/workloads`, `/storage`, and `/recovery` routes - [API Reference](API.md) — full API documentation - [TrueNAS Integration](TRUENAS.md) — TrueNAS-specific details diff --git a/scripts/tests/test_authentication_diagnostic_docs.py b/scripts/tests/test_authentication_diagnostic_docs.py index e2144d5273..5f38634421 100644 --- a/scripts/tests/test_authentication_diagnostic_docs.py +++ b/scripts/tests/test_authentication_diagnostic_docs.py @@ -163,13 +163,27 @@ class AuthenticationDiagnosticDocsTest(unittest.TestCase): def test_ai_autonomy_verification_timeout_and_autopilot_gate_match_runtime(self): source = DOCUMENTS["AI_AUTONOMY"].read_text() + shipped = (ROOT / "frontend-modern/public/docs/AI_AUTONOMY.md").read_text(encoding="utf-8") + self.assertEqual(source, shipped) guide = " ".join(source.split()) self.assertIn("human-session acknowledgement", guide) + self.assertIn("POST /api/ai/patrol/autonomy/acknowledgements", source) + self.assertIn("DELETE /api/ai/patrol/autonomy/acknowledgements/{id}", source) self.assertIn("1500 for subscription CLIs", guide) self.assertIn("codex-subscription", source) self.assertIn("claude-subscription", source) - self.assertIn("const DefaultPatrolSubscriptionInvestigationTimeoutSec = 1500", - (ROOT / "internal/config/ai.go").read_text()) + self.assertIn("up to 3 investigations run in parallel on metered API providers", guide) + self.assertIn("run 1 investigation at a time", guide) + self.assertIn("GetPatrolInvestigationConcurrency()", source) + self.assertIn("maxDeferredInvestigations", source) + ai_cfg = (ROOT / "internal/config/ai.go").read_text(encoding="utf-8") + self.assertIn("const DefaultPatrolSubscriptionInvestigationTimeoutSec = 1500", ai_cfg) + self.assertIn("func (c *AIConfig) GetPatrolInvestigationConcurrency() int", ai_cfg) + queue_go = (ROOT / "internal/ai/patrol_investigation_queue.go").read_text(encoding="utf-8") + self.assertIn("const maxDeferredInvestigations = 64", queue_go) + routes_go = (ROOT / "internal/api/router_routes_ai_relay.go").read_text(encoding="utf-8") + self.assertIn('"/api/ai/patrol/autonomy/acknowledgements"', routes_go) + self.assertIn('"/api/ai/patrol/autonomy/acknowledgements/"', routes_go) self.assertNotIn("cannot return to idle state without verification", guide) self.assertIn("ActionResultV2", source) self.assertIn("ASSISTANT_SAFETY.md#evidence-and-outcomes", source) @@ -237,6 +251,12 @@ class AuthenticationDiagnosticDocsTest(unittest.TestCase): "`5`-minute grace window (`investigationRunGrace`)", "`stuckInvestigationResult` and `abandonedInvestigationSession`", '"Patrol stopped waiting for this investigation after it ran past its time limit."', + "`GetPatrolInvestigationConcurrency()`", + "`MaxConcurrentInvestigations`", + "`1` at a time on local `codex-subscription` and `claude-subscription` CLIs", + "`FindingsStore.DeferInvestigation`", + "`64` additional findings in memory (`maxDeferredInvestigations`)", + "`TakeNextDeferredInvestigation`", ): with self.subTest(phrase=phrase): self.assertIn(phrase, guide) diff --git a/scripts/tests/test_navigation_help_docs.py b/scripts/tests/test_navigation_help_docs.py index 8d708deb5c..0c833b7ed3 100644 --- a/scripts/tests/test_navigation_help_docs.py +++ b/scripts/tests/test_navigation_help_docs.py @@ -588,6 +588,11 @@ class NavigationHelpDocsTest(unittest.TestCase): with self.subTest(source="UpdateReadinessChecksPanel.tsx", marker=marker): self.assertIn(marker, panel_tsx) + self.assertEqual(doc_text("UNIFIED_RESOURCES.md"), + (ROOT / "frontend-modern/public/docs/UNIFIED_RESOURCES.md").read_text(encoding="utf-8")) + self.assertNotIn("upgrading from platform-specific navigation", doc_text("UNIFIED_RESOURCES.md")) + self.assertIn("Retired unified-navigation migration", doc_text("UNIFIED_RESOURCES.md")) + def test_all_changed_guides_match_their_shipped_copies(self): for name in ( "README.md", diff --git a/scripts/tests/test_production_rollout_docs.py b/scripts/tests/test_production_rollout_docs.py index 08f25a020b..4c98715545 100644 --- a/scripts/tests/test_production_rollout_docs.py +++ b/scripts/tests/test_production_rollout_docs.py @@ -307,6 +307,24 @@ class ProductionRolloutDocsTest(unittest.TestCase): attention = (ROOT / "internal/api/attention_handlers.go").read_text(encoding="utf-8") self.assertIn('case path == "/receipts":', attention) + metrics_go = (ROOT / "internal/operationaltrust/metrics.go").read_text(encoding="utf-8") + for metric_suffix in ( + "observation_to_open_seconds", + "open_to_notification_enqueue_seconds", + "evidence_observations_total", + "identity_correlations_total", + "protection_posture_evaluations_total", + "protection_posture_evaluation_failures_total", + "notification_delivery_total", + "active_count_mismatch_total", + "action_offers_total", + "action_verification_total", + ): + with self.subTest(metric=metric_suffix): + self.assertIn(f'Name: "{metric_suffix}"', metrics_go) + self.assertIn(f"`pulse_operational_trust_{metric_suffix}`", trust) + self.assertIn("`partial_permission`", trust) + if __name__ == "__main__": unittest.main()