Introducing a new way to review your PRs.

Read the announcement

hashgraph-online / hol-guard

Open-source antivirus and firewall for AI agents: block risky tools, secret access, prompt injection, malicious packages, MCP servers, plugins, and skills at runtime.

View on GitHub

44 documents · Updated Nov 23, 2026

docs / cloud-review-delivery-and-recovery

Cloud review delivery and recovery

Cloud Review connects local Guard review events to Guard Cloud and brings signed results back for the exact pending action. It keeps local enforcement in control while it checks delivery identity, protects event content, retries safely, restores durable state, and gives operators clear repair paths. This page expands Policy authority and cloud exceptions and relates to Policy bundles, integrity, and sync and Cloud exception request workflow.

Cloud Review boundary

Cloud Review has two linked but separate paths. The event path reports local review activity to Cloud. The exact-review path applies one signed Cloud decision to one matching pending request after local consent. Neither path replaces local Guard enforcement or changes policy authority.

An accepted upload means that Cloud accepted the event. It does not allow or block the local action. A remote decision can resolve only the named request when its authority and binding checks pass. If Cloud is unavailable or a result fails those checks, the request stays safe locally.

Review authorization

Device consent is a local signed capability for exact remote review. It is separate from the Cloud connection and from policy memory. The capability is tied to the device, grant, installation, machine, runtime, and workspace, and it expires.

The settings flow enables Cloud Review only after the current Cloud connection and workspace are confirmed. It also requires explicit confirmation and the local high-risk approval proof when that gate is active. Enabling refreshes pending requests for the current identity. Held events remain unassigned unless the operator selects the explicit recovery choice. Disabling records a signed revocation while leaving local review and the Cloud connection available.

References: src/…/cloud_review_settings.py• L106-175 src/…/exact_cloud_review.py• L163-238

OAuth target binding

The delivery identity is the complete tuple of OAuth subject, workspace, machine, and machine installation. Guard stores a non-reversible subject hash with each event. It can refresh machine details for the same subject and workspace, but it does not silently move events to another account or workspace.

The sync path verifies this identity before it reads ready events. A changed subject or workspace isolates affected events. A changed machine or installation needs repair while the subject and workspace stay the same. Exact decisions also require the matching device identity.

References: src/…/cloud_review_sync.py• L216-245 src/…/cloud_review_settings.py• L130-142

Event projection and delivery

Durable event projection

Guard records each local review change in a durable outbox before delivery. The outbox preserves the local request snapshot and immutable event identity so delivery does not rebuild a request from changing local state.

The Cloud projection adds a privacy-safe display, request claim, risk and policy context, continuation offer, timestamps, and correlation identity. It carries the event schema, stream position, and payload digest used to bind the upload to local state. The projection uses an explicit risk category when one exists. Otherwise it derives a level from the review text, or leaves the level unknown. Invalid snapshots, continuation data, bindings, or native review context are quarantined or retried instead of being sent as an unsafe event.

This diagram shows the path from a local review change to a Cloud result and then back to the exact local request.

flowchart LR
    A[Local review change] --> B[Durable review outbox]
    B --> C{Binding and snapshot valid?}
    C -->|no| D[Quarantine or retry]
    C -->|yes| E[Privacy-safe Cloud projection]
    E --> F[Authenticated bounded batch]
    F --> G[Guard Cloud Review]
    G --> H[Accepted, duplicate, stale, or rejected result]
    H --> I[Outbox acknowledgement or retry]
    G --> J[Signed exact decision]
    J --> K{Capability and request match?}
    K -->|no| L[Keep request safe and pending]
    K -->|yes| M[Resolve one local request]
    M --> N[Report continuation status]

References: rust/…/cloud_review_event.rs• L112-190 rust/…/cloud_review_event_tests.rs• L50-185 src/…/cloud_review_sync.py• L254-318

Batch transport

The worker sends ordered prefixes of the outbox to the Cloud Review batch endpoint. Each batch uses protocol 2 and is limited by both event count and encoded request size. The local hard limits cap a batch at 250 events or 512 KiB, even when Cloud offers a larger limit. The default count is 50 events.

Guard normalizes each response before it can acknowledge the outbox. It requires one result for each event in the same order, matching event IDs, a valid acknowledgement high-water mark, and consistent accepted and rejected counts. Accepted, duplicate, and stale results are delivery-success states. Quarantined and rejected results remain non-success results. Positive server batch limits are retained, while retry hints are bounded to one hour and invalid hints are ignored.

After a valid response, Guard can adapt the next batch within the server limit and the local cap. It stores these limits for the current delivery identity. A new OAuth subject, workspace, machine, or installation starts with the default limits.

References: rust/…/cloud_review_ack.rs• L20-187 rust/…/cloud_review_ack_tests.rs• L34-259 src/…/cloud_review_sync.py• L323-396

Worker pacing

The delivery worker wakes after a committed review event and also performs a low-rate safety poll. This combines prompt delivery with recovery when an in-memory wake signal is lost. It waits longer after repeated errors with bounded exponential backoff and jitter. A durable retry time can shorten a healthy wait.

The native cloud-event-sync command is the runtime boundary for related Cloud sync work. It routes Guard events, pain signals, runtime sessions, receipts, authenticated requests, command jobs, and OAuth refresh work. It keeps the OAuth refresh circuit local under the storage gate and returns a clear failure when an action payload is missing. This boundary lets the caller use one strict command contract while keeping local state changes separate from brokered Cloud calls.

The worker stays dormant until a Cloud workspace and sync URL exist. Authentication and transport failures update durable sync state and do not turn off local review. Settings changes can refresh the worker, and daemon shutdown can stop it.

References: src/…/cloud_review_sync_worker.py• L37-108 src/…/cloud_review_sync_worker.py• L128-230 rust/…/cloud_event_command.rs• L22-175

Authentication and exact decisions

OAuth refresh

Event upload uses the normal Guard Cloud authorization context. If Cloud returns an authorization failure, Guard refreshes OAuth once and retries the same batch. The token change does not create a new event or duplicate the local request.

The refreshed context must still match the stored source, subject, workspace, machine, and installation. If it does not, delivery stops until the operator confirms a safe repair. Authentication errors remain visible in durable sync state.

References: src/…/cloud_review_sync.py• L198-209 src/…/cloud_review_sync.py• L234-245 src/…/cloud_review_sync_worker.py• L184-223

Signed exact decision

Cloud can return a signed exact decision through its dedicated command path. Guard checks the capability, signature, expiry, OAuth and device identity, workspace, grant, request identity, action hash, policy version, harness, artifact scope, and receipt lifetime. It also rejects a replayed receipt or a request that is no longer pending.

When the checks pass, Guard resolves only the named request at the named artifact scope. The result creates local approval authority for that action. It does not change policy bundles or decision memory. A separate continuation result tells the dashboard or calling harness whether the blocked action resumed, needs a manual retry, remains blocked, or cannot resume.

References: src/…/guard_cloud_review.py• L344-365 src/…/exact_cloud_review_apply.py• L43-165

Retry identity

A retry keeps the canonical correlation identity of the original request. If Cloud reports a snapshot sequence collision, Guard repairs the stored sequence only when the response identifies the same event and provides a valid acknowledgement high-water mark. Zero is valid for a new rejected stream.

For a retry-only identity drift, the worker can requeue the event once for the current binding. A durable marker makes that repair idempotent. A canonical correlation repair is separate and occurs only when the local event still matches the active binding. An immutable continuation-binding mismatch is quarantined after a successful store transition. If that transition fails, Guard retains the result for retry so it does not discard unacknowledged evidence.

Retry messages are reduced to safe Cloud error text before durable storage. This keeps operator feedback useful without retaining sensitive Cloud or request content.

References: src/…/cloud_review_retry_recovery.py• L13-71 src/…/cloud_review_retry_recovery.py• L74-131 src/…/cloud_review_sync.py• L362-383

SQLite recovery

State salvage

SQLite recovery rebuilds a coherent Cloud Review store from a quarantined source database when the active store cannot be used. It restores the identity, OAuth state, exact-review capability and revocation, verification keys, pending requests, receipts, replay state, settings recovery state, and event outbox.

The salvage is all-or-nothing. It needs valid local OAuth state and an installation identity. It does not create or renew consent. Capability and revocation state must return together so an enabled capability cannot exist without its revocation record. A successful copy wakes normal delivery.

References: src/…/sqlite_cloud_review_recovery.py• L13-30 src/…/sqlite_cloud_review_recovery.py• L52-89

Recovery boundaries

Recovery accepts a real source database and an empty destination. It rejects symlinks, non-empty destinations, missing required tables, incomplete identity or replay state, and partial copies. Older presentation-only request columns may be absent. Authority, identity, decision, revocation, receipt, and replay data may not be absent.

The destination transaction rolls back when a required table cannot be copied. Recovery does not erase a complete local state or invent new authority. After reopening, normal capability, OAuth, revocation, and request-binding checks still apply.

References: src/…/sqlite_cloud_review_recovery.py• L31-49 src/…/sqlite_cloud_review_recovery.py• L92-129

Operator feedback paths

Settings status

The settings view separates Cloud connection from exact-review authorization. It reports the active workspace and source, capability expiry, pending uploads, held events, isolated events, binding-matched delivery time, durable delivery state, and activation errors. It also reports when the outbox is unavailable instead of showing a false healthy state.

The main operator states are:

StateMeaningSafe next action
Not connectedNo usable Cloud target existsConnect Guard Cloud; local review remains available
Confirmation neededCloud is connected but exact review is not authorizedConfirm Enable Cloud Review
Pending uploadsEvents wait for the current bindingLet the worker run or refresh status
Uploads retryingDelivery failed but events remain localReview the safe error and allow a later retry
Held eventsEvents have no confirmed identityAdopt them only after confirming the current workspace
Isolated eventsEvents belong to another identity or workspaceKeep them isolated; do not adopt them as a shortcut
Authorization saved; delivery needs another attemptConsent succeeded but requeue or worker activation failedFix the local issue and choose Restore Cloud Review

References: src/…/cloud_review_settings.py• L57-103 src/…/cloud_review_sync.py• L451-484

Local recovery actions

The settings action can restore Cloud Review after activation failure, held events, or a delivery error. Restore checks the current workspace and source, requeues requests for the established identity, and can adopt only previously unassigned events when the operator selects that scope. Events from another identity remain isolated.

The action requires the protected local settings boundary, explicit confirmation, and the high-risk approval gate. If requeue or worker refresh fails, Guard stores the activation error. Consent and local protection remain intact so the operator can retry.

References: src/…/cloud_review_settings.py• L106-183

Remote action feedback

Remote exact-review feedback has two tracks. Application status says whether Guard applied the signed decision. Continuation status says whether the original action resumed, remains blocked, needs a manual retry, is waiting, or is not supported.

Guard records rejected and used results locally. A stale, expired, replayed, or wrongly targeted result does not change the pending request. A valid result resolves only its exact request and returns the continuation outcome for the dashboard or calling harness.

References: src/…/guard_cloud_review.py• L337-365 src/…/exact_cloud_review_transport.py• L33-197

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to the shared contract must keep schema versions, semantic rules, status values, fixtures, and exact command-result fields aligned for all consumers.
  • Changes to event projection must preserve the immutable outbox payload, privacy level, correlation identity, continuation snapshot, native review context, event identity, and payload digest.
  • Changes to identity fields must update source, subject hash, workspace, machine, installation, capability, request, and batch-limit binding checks together.
  • Changes to batch handling must preserve protocol checks, event ordering, event-ID matching, acknowledgement-through rules, count checks, byte limits, status handling, retry-hint bounds, and binding-scoped adaptive limits.
  • Changes to native review delivery must preserve replay preparation before upload and marker persistence before outbox acknowledgement.
  • Changes to retry recovery must keep snapshot collision repair, canonical correlation repair, and immutable continuation quarantine as separate paths. Replay markers must remain idempotent per source and binding.
  • Changes to stored errors must keep Cloud and request-sensitive text scrubbed before it reaches sync state or settings feedback.
  • Changes to settings recovery must preserve the distinction between saved consent, pending-request requeue, worker health, held events, isolated events, and unavailable outbox state.
  • Changes to SQLite recovery must copy identity, capability, revocation, receipts, replay state, and outbox sequences together. Presentation-only compatibility must not weaken authority checks.
  • Changes to the cloud-event-sync command must keep action names, required payloads, authentication boundaries, and the local refresh-circuit boundary aligned with its callers.

Important failure modes

TriggerConsequenceGuard
OAuth subject, workspace, machine, or installation does not match the outbox bindingEvents are not safely delivered to the current Cloud targetRequire the complete binding before reading ready events
A stored event or continuation snapshot is invalidThe event cannot become a safe Cloud projectionQuarantine invalid data or retain temporary native outages for retry
A batch response has invalid IDs, sequences, protocol, counts, or status valuesGuard cannot safely acknowledge the batchReject the response and retain events for retry
A retry hint or server batch limit has an invalid valueUnsafe pacing data could affect later deliveryAccept only positive integer limits and bounded positive retry hints
Native replay state is not prepared or its marker is not savedDelivery is retried instead of acknowledgedPrepare replay state before upload and persist the accepted marker before acknowledgement
OAuth upload fails with authorization errorThe current batch is delayedRefresh OAuth once and keep the same events for retry
Retry identity is non-canonicalCloud could link a result to the wrong requestRepair only with the matching event, binding, and Cloud confirmation
Immutable continuation binding is rejectedThe event must not gain a new continuation targetQuarantine after a successful store transition; retain evidence when it fails
Exact capability is expired, revoked, altered, or wrongly boundThe signed decision cannot resolve the requestCheck signature, expiry, revocation, device, grant, workspace, request, and receipt
SQLite recovery lacks required identity, revocation, receipt, or replay stateCloud Review authority could be incompleteReject the salvage and keep the destination unchanged
Settings requeue or worker refresh fails after consentDelivery is delayed while local protection remains activePersist the activation error and offer Restore Cloud Review
A cloud-event-sync action lacks its required call payloadThe requested Cloud or local sync operation fails without changing stateReject the command with an action-specific failure

Key files

FileWhy to read it
src/…/guard_cloud_review.pyDefines the shared Cloud Review contract validation and exact command-result boundary.
src/…/cloud_review_settings.pyDefines consent changes, delivery status, held-event recovery, and activation errors.
src/…/cloud_review_event_projection.pyDefines the privacy-safe event projection and native review context carried to Cloud.
rust/…/cloud_review_event.rsDefines the event shape sent for a local review request, including display data, risk context, and continuation facts.
rust/…/cloud_review_ack.rsDefines protocol-2 batch acknowledgement normalization and safe delivery hints.
src/…/cloud_review_sync.pyConnects identity checks, batching, authentication, acknowledgement, retry, quarantine, and durable sync state.
src/…/cloud_review_sync_worker.pyDefines wake-driven delivery, safety polling, and error backoff.
rust/…/cloud_event_command.rsDefines the native command boundary for event sync, receipts, Cloud requests, command jobs, and OAuth control.
src/…/cloud_review_retry_recovery.pyDefines bounded retry-identity repair and terminal continuation quarantine.
src/…/exact_cloud_review_apply.pyShows how one signed exact decision is checked and applied without changing policy bundles.
src/…/sqlite_cloud_review_recovery.pyDefines all-or-nothing recovery of Cloud Review state from a quarantined SQLite store.