Skip to content

ApplyOp's arm target deletes foreign resources under delete: "owned-only" #1448

Closed

Description

@lex00

ApplyOp({ target: "arm", delete: "owned-only" }) issues an ARM deployment in
Complete mode, which deletes every resource in the resource group that is not in
the template — including resources chant does not own and never applied.

The claim

lexicons/temporal/src/op/activities/apply.ts:179-181:

 * Apply declared source to the cloud via the target's native mechanism.
 * Deletes (when enabled) are limited to chant-owned orphans by construction —
 * every delete path is scoped to the ownership marker.

And :46-48:

 * - `owned-only` — deletes only chant-owned orphans, via the target's native
 *   prune/complete mechanism scoped to the ownership marker.

The docs repeat it. guide/reconciling-lifecycle.mdx: "Deletes ride the native
delete path scoped to the ownership marker, so they only ever touch
chant-owned orphans."

What the arm branch does

:113-127:

export function applyCommand(
  target: ShellApplyTarget,
  env: string,
  output: string,
  deleteMode: DeleteMode,
): string {
  const deletes = deleteMode !== "never";
  switch (target) {
    case "cloudformation":
      return `aws cloudformation deploy --template-file ${output} --stack-name ${env} …`;
    case "arm": {
      const mode = deletes ? " --mode Complete" : " --mode Incremental";
      return `az deployment group create --resource-group ${env} --template-file ${output}${mode}`;
    }
  }
}

No tag filter, no marker, no scoping of any kind. ARM Complete mode's contract is
resource-group-wide: it removes everything in the group that the template does
not declare. managed-by: chant does not enter into it.

So for the arm target, owned-only and gated are both
"delete everything in this resource group that isn't in my template."

The CloudFormation branch is fine — the stack genuinely is the boundary, and a
resource outside it is untouched. The kubectl branch is fine — #1075 moved it to
the k8s lexicon's server-side apply with a marker-scoped prune. ARM is the one
target where the native mechanism's blast radius is the whole container and
nothing narrows it.

The test encodes it as correct

apply.test.ts:13-14:

test("arm uses Complete mode only when deleting", () => {
  expect(applyCommand("arm", "rg", "t.json", "owned-only")).toContain("--mode Complete");

So the behaviour is asserted, and the assertion is what makes the guarantee
false. Any fix has to change this test, not satisfy it.

chant already has the safe version and ApplyOp doesn't use it

azApply (lexicons/azure/src/op/activities/az-apply.ts) applies per-resource
ARM PUTs and prunes through pruneArmOrphans (:410), which filters on
isChantOwned(tags) (:363) before issuing any delete. That is the marker-scoped
delete the docblock describes. nativeApply shells out to az deployment instead
and never reaches it.

#1204 recorded the transport correction for exactly this reason — #707 shipped as
per-resource ARM PUT, not az deployment, because floci-az has no deployments
provider. The applier moved; ApplyOp did not follow.

Note also that azApply's own docblock (:352) says floci-az drops resource
tags, so its owned-only prune is inert against the emulator and only takes effect
against real Azure. Whichever path this lands on, that caveat needs to be a test,
not a comment.

Options

  1. Route the arm target through azApply. The delete becomes marker-scoped
    by construction, and ApplyOp starts using the applier that shipped. Largest
    change, correct outcome, and it is the same move feat(k8s): server-side apply — chant field manager + conflict surface #1075 made for kubectl.
  2. Refuse the combination. target: "arm" with delete other than never
    fails at build time with a message naming the reason. Honest and small;
    removes a capability people may be using.
  3. Keep Complete mode, drop the guarantee. Document that arm deletes at
    resource-group scope and is not marker-scoped, and require an explicit
    acknowledgement flag. Cheapest, and it makes owned-only mean two different
    things depending on target, which is worse than either of the above.

(1) is the right end state and (2) is a defensible stopgap while it lands.
(3) should not ship — a delete mode whose scope depends on the target is exactly
the kind of thing the ownership model exists to prevent.

Verification

  • A test asserting that an arm apply with delete: "owned-only" does not issue
    a delete against a resource in the group carrying no chant marker. Assert on
    the transport, not on the returned command string.
  • The existing apply.test.ts:13 assertion is replaced, not kept.

Related

Activity

  1. added
    bug
    on Aug 3, 2026
  2. lex00 commented on Aug 3, 2026

    @lex00
    ContributorAuthor

    The general form of this is #1446 (shared write-path contract + conformance harness) — its assertion 4 asserts owned-only prune on the transport rather than on a returned command string. Routing option 1 here is the same change #1449 proposes for every non-kubectl target.

  3. lex00 commented on Aug 3, 2026

    @lex00
    ContributorAuthor

    Docs corrected on main in #1453 (37751bc) — the guarantee no longer appears anywhere, and guide/ops.mdx now states the per-target delete scope in a table with a caution naming the workaround.

    That is documentation only. The behaviour is unchanged and this issue stays open: applyCommand still emits --mode Complete for both owned-only and gated, and apply.test.ts:13 still asserts it. Replacing that assertion belongs to whichever routing option lands here.

  4. added 3 commits that reference this issue on Aug 3, 2026
    f2cab1e
    f711e46
    c6cd0f3
  5. lex00 commented on Aug 3, 2026

    @lex00
    ContributorAuthor

    Decision: option 2 now, option 1 as the follow-up.

    Ship the build-time refusal first so the destructive combination cannot be reached by accident, then route arm through azApply — which is also half of #1449.

    So this issue becomes the refusal, and the routing is tracked separately. Taking it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions