Skip to main content
An agent should never apply blind. Every apply path in Levelrail has a read only form that returns what would change, and every refusal carries a stable code you can match on instead of parsing text.

The flow

  1. Plan. Send the same files you would apply to a plan call. Nothing is written.
  2. Read the plan. Check summary, each change action, warnings, and whether the stack needs approval.
  3. Apply with the plan hash. Pass the hash from the plan as expected_plan_hash. If live state moved, the apply is refused with plan_stale and you plan again.
  4. On a refusal, branch on code, not on the message.

Where each plan lives

--dry-run with --exit-code exits 2 when changes are pending, so a script can gate on it. The dashboard shows the same plans in the resource import preview and in the stack sync revision view.

Plan shape

A resource or stack plan is one JSON object:
  • action is one of create, update, delete, noop, error. An error change has a code from the table below and a reason.
  • Created, changed and removed resources are the changes with create, update and delete.
  • Secret values and env values are never in a plan. Sensitive fields show (hidden).
  • A stack plan response adds issues (validation problems with file and line) and, when the stack needs approval, the apply answers 202 with pending_approval instead of changing anything.
  • An env dry run returns dry_run: true, changed, env_version and plan (key names and the kind of change, no values). Pass env_version back as expected_version when you apply.

Error codes

Match on the code field. Released codes are never renamed or reused. Stack and resource apply codes are listed in full, with what to do for each, in IaC error codes. The ones an agent meets most: Env apply codes: Other plain refusals carry a status based code (validation_failed, forbidden, not_found, conflict, unavailable).

Example

Over MCP, call plan_apply (or plan_stack) first, show the summary to the person, then call apply_resources (or apply_stack with confirm: true) with expected_plan_hash set to the plan hash. If it answers plan_stale, plan again.
Last modified on November 28, 2026