Applied snapshots
Some configuration cannot take effect the instant a replica reads it. A deployment declares the desired state in a configuration section. The fleet must agree on one version of it, install it in a controlled step, and keep serving the last version that worked while a new one is refused. An applied snapshot is the mechanism for that.
This page covers the stored versions, the code that turns a declaration into a version, the reconciler that serves the active version, and the owned unit that decides when a declared version becomes active. Shared rules of managed configuration are in constraints. The operator view is in configuration.
The pieces
Section in the deployment's configuration (the declaration)
| carry secret forms, strict bind once, canonical form, SHA-256
v
candidate: { feature, sha, schema version, document } held by each replica
| repository (one transaction, head row locked)
v
core.applied_snapshot_versions one immutable row per applied version
core.applied_snapshot_heads one row per feature: active pointer, pending, effects, release
change log entry applied_snapshot / <feature>
|
v
applied_snapshot reconciler on every replica
| decrypt inline secrets, resolve file and reference secrets
v
AppliedSnapshotState in the generation -> IFeatureConfig<TConfig>.TryGet()
A feature plugs in with IAppliedSnapshotFeature<TConfig> and AddAppliedSnapshotFeature<TConfig>, optionally with a
seeder that copies a snapshot back into the feature's rows. Its descriptor names the key, section, schema version, secret
fields and validation. Its behaviour judges whether a candidate may be applied now and runs the activation effects.
The declaration
A feature is managed when its section is present in the configuration, decided once at start. The declaration is bound
strictly. An unknown key, a wrong type or a failed Validate is a shape error. A shape error never stops the boot: the
replica keeps serving what is installed, reports the error and raises configuration.invalid for the feature. Only a
configured Managed:Directory that does not exist stops the boot.
The declared value becomes a canonical document with a fixed key order. Its SHA-256 identifies a version, so replicas
reading the same declaration agree. A section that disappears while the replica runs does
not remove the installed snapshot. The status shows "declaration missing" and configuration.invalid stays raised until
the section returns.
How a secret form crosses the binder
The Microsoft configuration binder renumbers lists, skips null, empty and scalar elements of object lists, appends to
collections that already have items and re-keys enum and integer keyed maps. A secret form (X_FILE, X_REF) has to
stay on its element through all of that. The codec rewrites each secret form at a declared secret site into a carrier
value with a prefix no operator writes, binds the copy once, and turns each carrier back into its form at the position
the binder gave it.
- A problem found after the bind (an unresolved reference, a carrier that could not be placed) names the bound
position. A problem found before it (unknown key, secret given in two forms, misplaced
_FILEor_REFsuffix) names the configuration key. The two differ only for sparse lists:Endpoints:2is positionEndpoints:1whenEndpoints:1is absent. - A carrier in a non-text setting, one the binder dropped, or a value that begins with the carrier prefix refuses the declaration and names the field.
- A value the binder cannot read is a shape error naming the setting by its configuration key.
Skipped elements are accepted silently and left out of the SHA, so a feature whose elements matter by count or identity
must check that in its own Validate. A skipped element holding a secret is never lost silently, because its
carrier is missing from the bound tree and the declaration is refused. Every TConfig collection must default to empty,
because the binder appends to defaults.
Secrets
A feature lists its secret fields (Token, Endpoints:*:Password). A secret can be given in three forms.
| Form | Stored as | Resolved |
|---|---|---|
| inline value | protected with the feature's data-protection purpose, per field | decrypted when the version is loaded |
X_FILE |
the path | read from each replica's file system when the version is loaded |
X_REF |
the reference | resolved through the secret resolver when the version is loaded |
The stored document never holds a plaintext secret or a resolved value. Resolved values are registered with the known-secret registry, so logs redact them. The SHA covers the declared forms, so rotating the value behind a file or reference does not change it and is picked up on the next load.
All references of a version resolve together under one deadline of half the reconcile timeout. A reference that does not
answer counts as unresolved. An unresolved reference leaves the feature without a record: TryGet() returns null, and
configuration.invalid and the status section name the field and reference, never the value.
A replica that left a version unserved because of an unresolved reference re-checks it every 30 seconds. When it
resolves, the replica appends an applied_snapshot change entry so every replica reconciles again. It does this at most
once every five minutes per feature, and only for a reference reason.
Storage
core.applied_snapshot_versions holds one row per applied version: feature, version number, SHA, document, creation time
and superseded time. Rows change only to set the superseded time. core.applied_snapshot_heads holds one row per
feature: the active version, the last version number ever issued and the states below. Version numbers only grow.
A feature is released by setting active_version to null, never by deleting its head row, because a deleted row would
let the next activation reuse version number 1.
The head row
| State | Columns | Meaning | Cleared by |
|---|---|---|---|
| active | active_version, effects_done_version |
the version the fleet serves, and the version whose effects completed | un-manage |
| pending | pending_sha, pending_code, pending_reason, pending_since_utc |
the fleet declares a SHA that is not active and is refused for a reason since a time | an activation, un-manage, or a pass finding nothing declared that is not active |
| effects | effects_error, effects_failing_since_utc |
the effects of the active version have not completed and the last attempt failed | the effects succeeding, an activation or un-manage |
| release | released_by, released_at_utc |
a replica released the head at a time | an activation |
Refusal codes:
| Code | Meaning |
|---|---|
fleet_not_agreed |
the replicas do not all declare the same SHA |
effects_not_done |
the fleet agrees, but the effects of the active version have not completed |
executor_lacks_feature |
the owner's build does not know the feature |
references_unresolved |
a reference of the owner's declaration does not resolve on the owner |
declaration_changed |
the owner's declaration was replaced after its SHA was compared |
A feature's judge may add codes. The refusal time is keyed on the SHA alone, so a blocker that flips between two codes does not restart it.
The repository
The repository is the only writer. Each operation runs in one transaction that first locks the feature's head row
(SELECT ... FOR UPDATE), so writers of one feature are serialised and different features do not wait for each other.
This relies on read committed isolation. A caller that must be fenced passes a factory that opens the fenced
transaction on the same context.
- Activate. The caller passes the head state it evaluated against (active version and release time). A different head
answers
HeadChangedand writes nothing, and so does a candidate with the active SHA. Otherwise the transaction supersedes the active version, appends the new one, moves the pointer, clears the other states and appends theapplied_snapshotchange entry itself, because the tables are not mapped to change capture. - Record and clear refusal. Record stores code, reason and first-refused time and appends nothing. Recording the active SHA as pending throws.
- Record effects failure, mark effects done. A failure of a no-longer-active version writes nothing.
The reconciler
applied_snapshot is a change-log aggregate keyed by feature. On every replica the reconciler loads the active version
of each registered feature, unprotects its inline secrets, resolves files and references, registers the values for
redaction and builds the feature's record into one AppliedSnapshotState in the generation. A version written under a
schema newer than the build can read is not served, and the feature reports it.
After each published generation a replica calls the feature's change hook once per installed version it has not yet announced. A throwing hook is logged and called again on the next publication. The hook does local work such as closing a client or rebuilding a cache and never decides whether the version applies.
IFeatureConfig<TConfig> answers from the state. With no applied version, or an unmanaged feature, it answers version 0,
a value the feature supplies. Unmanaged, EnsureWritable stays open so the feature's own editing path works.
What each replica reports
The status section carries declaredSnapshots: per declared feature, the SHA, or the shape error, or "declaration
missing", plus the unresolved references.
Collecting status does no secret-store I/O. A per-replica checker verifies each declaration's references at start, on
change and every 30 seconds, in its own loop with a 15 second budget. A check that ignores its deadline is abandoned five
seconds later and the status says the references have not been checked. A check publishes an immutable
(sha, unresolved, checkedAt) record. The status reports a SHA only when the record's SHA equals the current
declaration's, so after a reload it reports none until the next check. Only the newest check publishes.
The executor
applied-snapshots is an owned unit: one owner in the fleet, eligible only where the capability applied-snapshots/1 is
advertised, never in safe mode. Every replica advertises it next to safe-mode, so a build that does not know it never
owns the unit.
The owner runs a pass every 15 seconds and whenever its reconciler sees an applied_snapshot change entry. A pass covers
the features in the heads, those the running replicas declare and those the build registers, so a feature added by a
rolling upgrade is evaluated even by an owner that does not know it. Each feature is handled on its own view (see
Consistency of the activation decision), and one failing feature does not stop
the others.
Fleet evaluation
The evaluation is a pure function of one view: the feature's head and the roster read after it, with each replica's declared SHA and member-lease validity. It uses nothing from the owner's process, so any owner gives the same answer.
Release. A head released by un-manage records the releasing replica. While that replica's member lease is valid and it
is not yet in the roster, it blocks, because it no longer declares the feature and has not yet said so. The block lifts
when the lease is gone. Once the replica is in the roster it blocks like any replica that does not declare, or agrees
when it returns with the section. A fenced row never holds this clause, and for 5 minutes after the fence it blocks
through agreement. After that it no longer counts, so the fleet may reactivate the old declaration until the next
replica that boots without the section releases the head again.
Un-manage runs only after the replica's own join, so every release has a live member lease behind it. A replica that
became Exited never releases.
Agreement. Every replica that counts must have a report, declare the feature, carry no error or unresolved
reference, and report the same SHA. The blocker lists the first failing condition of each replica, with differing SHAs
grouped. A running replica counts, except a fenced one whose lease ended more than 5 minutes before the roster read
(database clock). A fenced replica can only block, never agree, because its status writes are refused after the lease
TTL. A replica that returns under the same id gets a new epoch.
The declaration that waits. The most declared SHA among counted replicas that is not active, ties broken by ordinal SHA order. The system status headline uses the same rule.
Activation
The owner reads its own declaration once, and the judge and the activation use that candidate. Steps run in this order.
- Owed effects. When the head's active version differs from the version whose effects are recorded as done, the
owner (still owning the unit) loads the version, decrypts and resolves it, runs the effects and records them done. A
failure is recorded in the effects state and retried every pass. It never blocks evaluation of a split fleet. Effects
never read
IFeatureConfig<T>, resolve only fleet-resolvable references, and must be idempotent and harmless for a version that is no longer active, because they are external actions that cannot be fenced. A new owner finishes what the previous one did not. - Nothing waits. No running replica declares anything not active: a stale pending state is cleared, and the pass ends for the feature.
- Not agreed. Recorded as pending
fleet_not_agreedon the SHA that waits. - Effects not done. The fleet agrees but the active version's effects are incomplete:
effects_not_done, and nothing new is activated. - Executor lacks the feature. The owner's build does not register it:
executor_lacks_feature. - Judgement. The owner proceeds only when its own declaration has the agreed SHA. A lagging report waits for the next
pass. The feature's behaviour judges the candidate here and a refusal is recorded with its own code and reason. A
declaration replaced after the comparison is recorded as
declaration_changed. - Activation. The version, the moved head and the change entry commit in one transaction opened through the owner's fence, so a stale owner writes nothing. The effects then run and are recorded in a second transaction. A crash between the two leaves the effects owed, and the next owner repeats them.
Consistency of the activation decision
Activation is a guarded write whose guard joins a fact of the head (the release stamp, written by un-manage on any
replica) with facts of the cluster roster (running, member lease, reports). The head can be locked and compared. The
roster is a lock-free read as of its ReadAt. The code therefore fixes the order of the reads and compares only the
head.
For each feature the pass reads the head, then the whole roster in one call. The fleet evaluation uses only that view.
The owner judges and activates in the fenced transaction, where the head row is locked and active_version and
released_at_utc are compared with the view's head. If either differs, nothing is written and the pass ends for the
feature.
This is enough because a release is the un-manage of a replica after its own join, and it always changes
active_version from a version to none.
- A release committed before the head read is seen by the head, and its releaser's join committed earlier, so the roster holds its member row. A releaser that runs without a report of its own epoch blocks agreement, and one that drains holds a valid lease until it ends. One fenced for over 5 minutes, or whose lease ended, is the accepted reactivation.
- A release committed after the head read changes
active_version, so the compare-and-set fails. - A change after the roster read that does not touch the head (a join, a lease ending, a report) cannot make a committed activation unsafe. A join is followed by a release that the cases above catch.
A writer of the head that does not change active_version would need its own field in the token.
This rests on six guarantees of the cluster library, which each library upgrade must keep:
- One live tenure per replica id. A join under an existing id takes the row over only when it is
fencedordrainingor its lease has expired, and gets a new epoch. - The join commits before the replica phase leaves
Starting. - A report is bound to the epoch of its member, so a rejoin can drop an old report but never attribute it to the new process.
- A member lease is judged on the database clock in the statement that reads it, and a draining row is not renewed.
- The library connects to the primary only, so a status read after a commit sees that commit.
- A fenced transaction holds the owned row
FOR SHARE, so it cannot commit after the unit changed owner.
The pending record, its clearing and the judge's refusals are written without a compare-and-set, and a stale one lasts until the next pass rewrites it. Facts the judge reads from the replica's live state (for example a provider in use) are not compared at commit, so a feature must tolerate their changing or check them again where it acts.
Retention
The owned job applied-snapshot-retention runs every 6 hours and deletes versions superseded more than 30 days ago. It
never deletes the active version or a head row, so the version counter keeps growing.
Un-managing a feature
A serving replica that boots without the section of a feature it knows reads that feature's head. If a version is active, the replica runs the feature's seeder with the active snapshot and releases the head, in one transaction. The migrate-only job never does this, because it mounts no managed directory and every feature would look un-managed.
An inline secret is carried over. A file or reference secret is resolved and written when it still resolves, and left
not set when the answer is definitive (gone, destroyed, forbidden, malformed). A source that does not answer within the
resolution budget (Unavailable, a timeout, an I/O error other than a missing file) refuses the release of that
feature, because writing "not set" for a secret that still exists would lose it for good. A seeder failure rolls back
the transaction. In both cases the head stays active, the boot continues, configuration.invalid is reported through the
Unmanage issue source naming fields and no values, and the next restart tries again.
On release the active version becomes none, the pending and effects states are cleared, the head records released_by
and released_at_utc, and an applied_snapshot change entry makes every replica fall back to the rows. Only the first
replica finds an active head.
A replica without the section keeps serving the snapshot while the head is active, and a release marker in the view makes it read the rows after the seed. While a feature is still served from a snapshot, its panel edits are refused, because the release would overwrite them with the seed. The release takes no membership fence: while a process holds a valid lease no other process can join under that id, and a lapsed lease means the process is gone.
Alerts and status
configuration.pending is raised for a feature when its pending state or failing effects have stood for 15 minutes, and
on nothing else. The text names the reason of each old condition. The owner raises and clears it at the end of each
pass, touching only rows keyed by feature alone.
The system status lists per feature the declaration most running replicas report, the active version (number, SHA,
activation time), the states pending, effects and released (each null when it does not hold) and each replica's
declaration error or unresolved references. The section is omitted when no feature is declared as a snapshot.
Rules
- The active version is only replaced by a successful activation. A failed or refused one leaves it serving.
- Secret resolution never runs on the status path. Each resolving path has its own budget: reconcile half of
ReconcileTimeout, the checker 15 seconds per declaration, the pass 15 seconds per feature.