Files
Pulse/docs/PATROL_ARCHITECTURE.md
pulse-triage[bot] d160c6d886 Align Patrol, Operational Trust, and Unified Resources Help docs
Fix runtime drift across four shipped Help guides and their mirrored copies under
frontend-modern/public/docs/:

- docs/AI_AUTONOMY.md: document that local subscription agent CLIs
  (codex-subscription, claude-subscription) run 1 investigation at a time
  rather than 3 in parallel (GetPatrolInvestigationConcurrency() in
  internal/config/ai.go), document the 64-finding critical-first in-memory
  deferred queue (maxDeferredInvestigations), and document the human-session
  Autopilot acknowledgement API endpoints
  (POST /api/ai/patrol/autonomy/acknowledgements and
  DELETE /api/ai/patrol/autonomy/acknowledgements/{id}).
- docs/PATROL_ARCHITECTURE.md: document investigation concurrency limits and
  the in-memory critical-first deferred queue
  (internal/ai/patrol_investigation_queue.go).
- docs/OPERATIONAL_TRUST.md: list all ten registered pulse_operational_trust_*
  Prometheus metrics and their bounded label vocabularies from
  internal/operationaltrust/metrics.go, including partial_permission on
  evidence observations, and reference full metric names in alert examples.
- docs/UNIFIED_RESOURCES.md: replace the contradictory "upgrading from
  platform-specific navigation" description for MIGRATION_UNIFIED_NAV.md with
  its retired historical context matching docs/README.md.

Extend source-bound regression tests in
scripts/tests/test_authentication_diagnostic_docs.py,
scripts/tests/test_production_rollout_docs.py, and
scripts/tests/test_navigation_help_docs.py.

Contract-Neutral: Shipped Help documentation alignment and source-bound docs unit tests only; no runtime UI, backend API, schema, auth, or subsystem contract delta.
Change-source: pulse-maintainer
2026-11-28 22:35:37 +00:00

10 KiB

Pulse Patrol deep dive

How a Patrol run actually works, for readers who want more than the overview in AI features.

The short version is that Patrol pairs deterministic triage and verification with a single model-owned agentic analysis loop. The model owns diagnosis and finding decisions during the run, while deterministic checks bound triage, stale-finding reconciliation, and fix verification.

A run, end to end

A Patrol analysis cycle moves through the following stages. Each is described in more detail below.

  1. A pre-flight budget check (CheckBudget("patrol")), which fails fast before any context is built.
  2. Guest intelligence gathering (gatherGuestIntelligence, bounded to five seconds), covering discovery and reachability probing.
  3. Deterministic triage (runDeterministicTriageState), which computes flags, capacity forecasts, and quiet-state context for the run.
  4. Focused seed context assembly (buildTriageSeedSectionsState and assembleSeedWithinBudget), with automatic tighter-budget retries if the provider reports a context-window error.
  5. Core active-finding snapshotting (establishCoreFindingSnapshot) and the agentic tool loop (ExecutePatrolStream), where the model calls tools, files findings, and records explicit assessments.
  6. Post-run reconciliation in internal/ai/patrol_run.go: flagging omitted active-finding assessments, stamping deterministic capacity forecasts, folding alert mirrors, auto-reconciling stale findings, cleaning up old resolved findings, recovering stuck or timed-out investigations, and reviewing active alerts.

Budget check first

The budget check runs before context assembly and before a chat service is acquired. A run that cannot afford to complete is stopped at the cheapest possible point rather than after the expensive work.

Guest intelligence

Discovery and reachability probing run before the seed context is built, with a five-second timeout, so the context the model receives already reflects which guests are reachable.

Deterministic triage and seed context

Triage narrows the surface first, and the seed context is then built from what triage returned rather than from everything Pulse knows. This keeps the model's starting context focused on what looks interesting.

Quiet infrastructure still goes through the configured model. Patrol does not skip the model when nothing looks wrong, because "nothing is wrong" is itself a judgement worth making explicitly.

The turn budget for the agentic loop is a fixed execution limit, independent of heuristic flags or inventory size: patrolDetectionMaxTurns in internal/ai/patrol_ai.go grants 4 turns for an explicit quick run (PatrolDepthQuick) and 40 turns otherwise.

The agentic loop and explicit assessments

The model runs an agentic loop with tool access. Findings and assessments are recorded through tool calls during the loop rather than parsed out of prose afterwards, so a finding exists because the model deliberately filed it.

The original conversation owns diagnosis and finding decisions. Patrol does not launch a separate follow-up model session to infer missing verdicts from old finding excerpts or signal counts. When an active seeded finding finishes a run without an accepted verdict, patrolMissingAssessmentIDs leaves that omission explicit and records an incomplete-assessment error on the run.

Deterministic signal detection and verification

Deterministic signal detection lives in DetectSignals and SignalThresholdsFromPatrol in internal/ai/patrol_signals.go. It scans completed tool call output for known problem signals without depending on model judgement.

The signal types are:

Signal Meaning
smart_failure A disk reporting SMART failure
high_cpu Sustained CPU above the threshold
high_memory Sustained memory above the threshold
high_disk Disk or pool usage above the threshold
backup_failed A backup job that failed
backup_stale No backup inside the staleness window
guest_unreachable A guest that failed reachability probing

Thresholds come from your own alert configuration rather than from a separate set of numbers, so detection agrees with what Pulse would alert on. SignalThresholdsFromPatrol maps your configured alert thresholds onto the signal thresholds, falling back per field to these defaults when a value is not configured.

Threshold Default
Storage warning 75%
Storage critical 95%
High CPU 70%
High memory 80%
Backup staleness 48 hours

Backup staleness has no user-facing setting and always uses the default.

In the live Patrol runtime, DetectSignals powers deterministic fix verification (verifyBySignals in internal/ai/patrol_findings.go for smart-failure and backup-failed), alongside direct runtime-state verifiers declared in hasDeterministicVerifierForKey (backup-stale, cpu-high, memory-high, disk-high, and guest-unreachable). Both the resolve gate and stale-finding reconciliation consult hasDeterministicVerifierForKey before accepting a finding as resolved. Offline Patrol quality evaluations in internal/ai/eval/patrol_quality.go also use DetectSignals.

Investigation

A finding may be investigated after it is filed. Investigation is a separate loop from the run that produced the finding, coordinated through the InvestigationOrchestrator contract in pkg/aicontracts/interfaces.go.

Whether a finding is investigated at all depends on your autonomy level and on the finding's own state. Finding.ShouldInvestigate in internal/ai/findings.go is the gate, and it refuses in every one of these cases.

  • Autonomy is unset or monitor. Investigation only runs at approval, assisted, or full.
  • The finding is resolved, dismissed, suppressed, or snoozed.
  • The severity is not warning or critical. Info and watch findings are not investigated.
  • A fix is already queued for approval, so the next move belongs to you.
  • The finding reached a terminal outcome, such as fix verified, resolved, fix rejected, cannot fix, or needs attention.
  • An investigation is already running, or the finding has already been investigated three times (maxInvestigationAttempts).
  • The last investigation is still inside its cooldown (investigationCooldown is one hour by default, investigationFixRetryCooldown is twenty minutes after a failed fix or failed verification, and investigationTimeoutCooldown is ten minutes for timeout outcomes). Failed runs that produced no conclusion (empty outcome, timed out, or interrupted) and fix_verification_unknown carry no additional cooldown so the scheduled Patrol cadence owns the next assessment while keeping the three-attempt cap.

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 internal/ai/chat/agentic_investigation_budget.go and internal/ai/chat/agentic_final.go:

  • Stream-idle timeout: Streaming investigations enforce PatrolProviderStreamIdleTimeout (60 seconds) between provider chunks. Buffered local Codex and Claude subscription CLIs widen that turn budget to 4 minutes (patrolSubscriptionInvestigationTurnTimeout). Both budgets carry over to the final narrative summary call (ensureFinalTextResponse) so slow or local providers do not drop to a short chunk default.
  • Summary deadline, conclusion reserve, and output-limit recovery: Unlike interactive chat's 20-second summary cap, an investigation summary may use the remaining run deadline (investigationSummaryTimeout). Before starting another evidence turn, investigationConclusionReserve reserves 3 * max(slowestTurn, 20s) + 15s (capped at half the run budget) so the conclusion and final summary can finish before the deadline. If a final response exhausts the model's output budget, Patrol runs one tool-free low-reasoning synthesis pass capped at 4,096 tokens (investigationOutputLimitRecoveryAllowance).
  • Stuck-run sweep: recoverStuckInvestigations (stuckInvestigationResult and abandonedInvestigationSession in internal/ai/patrol_findings.go) gives a live run its original deadline plus a 5-minute grace window (investigationRunGrace). Runs lost to a restart or shutdown close as interrupted while still spending an attempt toward the three-attempt cap so a crash loop cannot retry forever. Overdue live runs close as timed_out with "Patrol stopped waiting for this investigation after it ran past its time limit." so finding and session telemetry agree.

Why it is built this way

Model judgement is good at explaining and correlating across mixed infrastructure, while deterministic checks are reliable for triage context, stale-finding cleanup, and post-fix verification. Keeping diagnosis inside the original conversation avoids hidden second-pass guesses when a model omits an assessment, while deterministic verifiers keep resolution claims grounded in actual runtime state.