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 / native-command-jobs-and-queue-execution

Native command jobs and queue execution

Guard turns a cloud-directed command into a bounded local job plan, durable queue state, and a result that can be safely recorded by Guard Cloud. The flow keeps planning, local confirmation, one-time execution, repair, replay checks, and result binding under one native state model. It is part of native runtime authority and complements native runtime residency and recovery and native command evaluation and classification.

Job planning

Job planning maps a cloud operation to the command family and local context that may run it. It validates the operation's inputs before the queue starts execution, and it returns either a runnable plan, a local confirmation request, or a clear failure.

Operation families

The planner groups supported operations into package-shim, app, exact cloud-review, and policy-memory families. Package-shim operations may carry a checked manager list. App operations may carry a registered harness and an editor or cli surface. Unknown operations do not enter the queue.

References: rust/…/command_job_plan_op.rs• L17-107 rust/…/command_job_plan_op_tests.rs• L30-105

Confirmation plans

Removal actions do not run as ordinary cloud jobs. The planner creates a confirmation plan that tells the local user which command to run. App removal uses the canonical harness identity and a matching confirmation phrase, while package-shim removal names the selected managers.

References: rust/…/command_job_plan_op.rs• L110-167 rust/…/command_job_plan_op.rs• L216-259 rust/…/command_job_plan_op_tests.rs• L107-128 rust/…/command_job_plan_op_tests.rs• L198-226

Plan request binding

The plan operation binds its answer to the complete request with a size-bounded SHA-256 digest. A supported schema produces a plan result. A wrong schema or an oversized request produces an error before planning can create authority for the job.

References: rust/…/command_job_plan_op.rs• L38-71 rust/…/command_job_plan_op_tests.rs• L228-300

Queue state

Queue state is the local record that lets a cloud job cross process and restart boundaries without losing its approval or running it twice. The native state service reads and writes each logical row in one immediate SQLite transaction.

Approval ledger

The ledger keeps pending jobs, signed local approvals, and consumed-job replay rows as separate bounded lists. Pending jobs expire with the job identity. Approval consumes only when the signed grant names the exact same identity and verifies with the expected integrity key. A successful consume can record replay state in the same transaction.

The main command capability controls this ledger. Issuing a new capability resets active queue, pending, and local approval state. Replay rows remain so a job that already ran cannot become runnable again. Revoking the capability clears the capability and all command ledger rows together.

References: rust/…/command_state.rs• L30-62 rust/…/command_state.rs• L211-337 rust/…/command_state.rs• L366-429 rust/…/command_state_tests.rs• L81-192 rust/…/command_state_replay_tests.rs• L126-180

Replay identity

Replay state records the identity digest, job ID, idempotency key, operation, expiry, and consume time for a job that has passed the local gate. Before a verdict uses replay state, the service can return only rows that could match the subject's job ID or idempotency key. Rows with incomplete identity stay available for the verdict to judge.

This diagram shows how a job moves from cloud intake through local approval and replay protection.

flowchart LR
    Cloud[Cloud job] --> Plan[Native plan]
    Plan -->|run| Queue[Queue state]
    Plan -->|confirm| Pending[Pending approval]
    Pending --> Grant[Signed local approval]
    Grant --> Consume[Consume exact identity]
    Queue --> Consume
    Consume --> Replay[Replay row]
    Replay --> Execute[Local execution]
    Execute --> Result[Bound result]

References: rust/…/command_state.rs• L228-235 rust/…/command_state.rs• L306-363 rust/…/command_state.rs• L385-419 rust/…/command_state_replay_tests.rs• L31-123

Queue capability transitions

Capability changes define queue boundaries. A new capability starts with no active lease, pending result, or local approval from the old queue, but it preserves replay history. A clear operation removes the whole command ledger without touching unrelated local state.

References: rust/…/command_state.rs• L366-429 rust/…/command_state_replay_tests.rs• L126-180

Queue repair

Queue repair makes a damaged queue lane safe for the worker to load. It inspects only the main lane or a named review-drain lane, removes malformed active-job or pending-result fields, and returns the lane to idle when it changes the row.

Lane repair

The repair operation never treats an arbitrary state row as a queue lane. A missing row, a non-object row, a healthy row, or null queue fields need no write. A damaged active_job must be an object, and a pending result must contain both an object job and an object payload.

References: rust/…/command_queue_repair.rs• L17-53 rust/…/command_queue_repair.rs• L55-85 rust/…/command_queue_repair_tests.rs• L40-105 rust/…/command_queue_repair_tests.rs• L148-172

Atomic repair

Repair reads and writes a lane in the same immediate transaction as the state request. When it drops damaged fields, it clears the last error and marks the lane idle. A read or decode failure returns an error and does not turn unreadable state into an empty queue.

References: rust/…/command_queue_repair.rs• L1-9 rust/…/command_queue_repair.rs• L55-85 rust/…/command_queue_repair_tests.rs• L108-145 rust/…/command_queue_repair_tests.rs• L167-172

Result recording

Result recording converts a settled job and its local execution into the payload that Guard Cloud stores. It requires both the job ID and lease ID, preserves a stable idempotency key, and closes the lease with a success, failure, or local-confirmation status.

Execution outcomes

The result contract has three main paths:

  • A successful ordinary job posts the execution object as its result.
  • A job waiting for local confirmation posts waiting_local_confirm without exposing the internal waiting marker.
  • An execution failure posts failed with a failure code and a useful message.

Exact cloud-review jobs also carry protocol version data. Their result is built from bound request and receipt identities instead of accepting arbitrary execution data.

References: rust/…/command_result.rs• L24-41 rust/…/command_result.rs• L107-165 rust/…/command_result_tests.rs• L56-121

Exact review contract

An exact review result joins the cloud job binding with the local execution record. The local request ID and receipt ID must agree across those records. The result then reports application and continuation status with their reasons and RFC 3339 update times.

The v2 contract limits opaque IDs and reason text, requires a reason for rejected or failed application states, and requires valid timestamps. A contract violation becomes a posted failure with exact_result_contract_invalid, so the leased job still reaches a terminal cloud result.

References: rust/…/command_result.rs• L219-305 rust/…/command_result.rs• L307-345 rust/…/command_result_contract.rs• L8-101 rust/…/command_result_contract.rs• L103-174 rust/…/command_result_tests.rs• L124-260

Native review results

Native workspace-review payloads provide only a strict set of request ID, receipt ID, and non-empty envelope fields. Partial, malformed, or mismatched native data is rejected. This keeps a result tied to the cloud binding and prevents a locally produced review record from being attached to another job.

References: rust/…/command_result.rs• L307-345 rust/…/command_result_tests.rs• L150-172

Change checklist

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

  • Keep operation names, family assignments, input checks, confirmation commands, and local command identity aligned. A planner change can send a job to the wrong execution path or make a valid confirmation unusable.
  • Keep job identity fields, identity digests, signed grants, replay rows, expiry checks, and idempotency keys aligned. A mismatch must refuse reuse rather than create a second run.
  • Keep capability issue and clear transitions aligned with queue, approval, pending-result, and replay state. New authority must not inherit active work from an old capability.
  • Keep main and review-drain lane keys restricted to queue rows. Repair must never rewrite an unrelated state row.
  • Keep result statuses, lease closure, idempotency keys, exact-review protocol fields, and the cloud result contract aligned.
  • Keep exact-review binding IDs, status reasons, and timestamps consistent across job payloads, execution data, and the v2 contract.

Important failure modes

TriggerConsequenceGuard
A cloud operation is unknown or has invalid managers, harness, or surface dataThe job is refused before executionThe planner returns a typed failure plan.
A removal job lacks the required local confirmationThe destructive action does not run from the cloud queueThe planner returns a confirmation plan with a canonical command and phrase.
A grant names a changed job identity or fails signature verificationThe grant remains unspent and the job remains pendingThe consumer checks the identity digest, signature, key, and full identity.
Queue state contains malformed active or pending-result dataThe worker cannot trust the lane stateRepair drops only the damaged fields and resets the lane to idle in one transaction.
Replay state is missing or does not match the job subjectA completed job could be considered for reuseReplay rows bind identity digest, job ID, idempotency key, and expiry.
Exact-review IDs or execution bindings disagreeThe cloud result is not accepted as a valid review outcomeResult construction checks the server binding and local execution IDs.
An exact result violates status, reason, ID, or timestamp rulesThe lease closes as a contract failure rather than a false successThe v2 contract validator emits exact_result_contract_invalid.
A job has no lease ID or job IDNo cloud result can safely close the leaseResult recording refuses the payload in a fixed validation order.

Key files

FileWhy to read it
rust/…/command_job_plan_op.rsDefines the supported cloud operations, validation, run plans, failures, and confirmation plans.
rust/…/command_state.rsDefines the durable pending, approval, replay, capability, and queue-state lifecycle.
rust/…/command_queue_repair.rsDefines safe repair for main and review-drain queue lanes.
rust/…/command_result.rsBuilds the cloud-facing result for ordinary, waiting, failed, and exact-review jobs.
rust/…/command_result_contract.rsDefines the v2 exact-review result rules.
rust/…/command_state_tests.rsShows approval expiry, signing, exact consumption, replay recording, and capability transitions.
rust/…/command_state_replay_tests.rsShows replay filtering and the boundary between command state and unrelated local state.
rust/…/command_queue_repair_tests.rsShows which damaged queue fields are repaired and which rows are protected.
rust/…/command_result_tests.rsShows result status, binding, native payload, contract, and size guarantees.