Implementing Apply
An applier writes declared source to a provider. This page is the write-side peer of Implementing Observation, and it exists for the same reason: a caller can trust a result only when it says what it did not do.
The tri-state
Section titled “The tri-state”Per resource in the plan, an applier returns exactly one verdict:
| verdict | means |
|---|---|
| APPLIED | the provider was called and the resource converged — created, updated or unchanged |
| PRUNED | owned, no longer declared, deleted |
| NOT-ATTEMPTED | no provider call was made, carrying a total reason |
The three are disjoint and total. Every resource handed to the applier appears in exactly one of them. A resource in none of them was silently dropped, and this contract prevents that.
Each bucket is an array of one shape, all three extending ApplyRef so a resource is named the same way everywhere. packages/core/src/apply.ts is the contract.
interface ApplyRef { kind: string; name: string; } // the provider's own type name, verbatim
interface AppliedResource extends ApplyRef { action: "created" | "updated" | "unchanged"; physicalId?: string;}interface PrunedResource extends ApplyRef { deleted: boolean; // false when the delete was a no-op; still PRUNED}interface NotAttemptedResource extends ApplyRef { reason: NotAttemptedReason; detail?: string; // the status and body, the missing binding, the unsupported kind}applyRefKey(ref) produces the kind/name string the conformance suite and the diagnostics use.
Why NOT-ATTEMPTED
Section titled “Why NOT-ATTEMPTED”The read path had two ways to return nothing for a declared entity and no way to tell them apart (the provider said it is absent, or the lexicon never looked), and the second was classifying as create. That is what observation.ts fixed.
The write path had the identical hole:
const mapper = MAPPERS[r.kind];if (!mapper) { console.log(`skip: no mapper for kind ${r.kind}`); continue; // never appears in `applied`, or anywhere}A caller receiving { applied: [...] } could not distinguish a complete apply from one that dropped half the manifest, and ApplyOp had nothing to gate on. A console.log on stdout is not a signal in a result, the same way a warn on stderr was not a signal in a change set.
The reasons are total
Section titled “The reasons are total”type NotAttemptedReason = | "unsupported-kind" // no mapper/writer for this type | "no-credentials" // no usable authorization for the target | "no-binding" // no concrete target resolved | "dependency-failed" // an upstream in the same run failed | "filtered" // withheld by a caller-requested scope | "not-prunable"; // an owned orphan of a kind that cannot be enumeratedPick one. Consumers switch exhaustively over these values, so a reason is never a free-form string. A free-form string is what a console.log already was.
not-prunable is the prune-side reason. It separates “there was nothing to prune” from “I could not look for anything to prune here.” An applier that cannot enumerate a kind cannot know whether an owned orphan of it exists.
The envelope
Section titled “The envelope”import { applyResult } from "@intentius/chant";
return applyResult(applied, pruned, notAttempted);Versioned and self-discriminating (apply: "v1"), so an un-migrated applier may keep returning its own shape. That shape normalizes to “everything I was handed, I attempted”, which is the claim it already makes implicitly.
Reporting NOT-ATTEMPTED requires the envelope, since only the envelope can express it.
Two helpers come with it, both from @intentius/chant:
| Helper | Use |
|---|---|
notAttemptedAll(refs, reason, detail?) | The whole-apply refusal. Turns every resource in the plan into a NOT-ATTEMPTED entry with one reason, for a bind that failed outright. The write-side peer of unobservedAll. |
normalizeApply(value) | Turns either accepted shape (or undefined) into three always-present arrays. What every consumer, and every conformance assertion, works with. |
To say “I applied nothing because I could not”, return notAttemptedAll. Returning nothing normalizes to three empty arrays, which reads as an empty plan.
Ownership
Section titled “Ownership”Prune deletes only what chant owns. The marker channel differs per provider (tags on Azure, machine metadata on Fly), and the rule does not. Read the marker before issuing a delete, and never delete a resource that does not carry it. Which channel your lexicon reads on which path is declared as ownershipChannel on the plugin.
Assertion 4 is what holds you to it. A comment saying prune is owned-only is not enforcement, and every applier that got this wrong had the comment.
See also
Section titled “See also”- Apply Conformance Suite — the suite that proves an applier honors this contract
- Observation Contract — the read-side tri-state this one mirrors
- Implementing Observation — the reader that decides what an apply has left to do