Native command catalog and pack lifecycle
Native command catalogs and command packs turn reviewed command sources into authenticated policy data that the runtime can admit. The lifecycle keeps catalog meaning, executable policy, release authority, local cache state, and active controls separate so that a downloaded or prepared pack cannot enforce policy until native checks and an atomic activation commit succeed.
Lifecycle boundary
Catalog and pack roles
The command catalog is the read-only description of extensions, rules, permissions, relationships, and command metadata. A command pack is the compiled policy data for an extension. The catalog explains what a command capability means; the pack supplies the native matcher data used to evaluate it.
The source compiler produces deterministic catalog and program projections from validated source metadata. Native catalog preparation can also produce a metadata-only discovery view from authenticated release objects. Neither catalog metadata nor a pack selection grants a permission by itself. native_command_source_catalog.rs and catalog_prepare.rs define this separation.
References: rust/…/native_command_source_catalog.rs• L26-36 rust/…/catalog_prepare.rs• L1-3
Admission authority
The runtime admits a prepared set only after the source, release, native engine, policy graph, and local security state agree. Preparation is a candidate-building step. Activation is the later step that makes the candidate the current policy snapshot.
This boundary lets the system keep an existing active policy when discovery or transfer fails. It also prevents a transport response, a stale cache object, or a catalog read from acting as runtime authority. preparation.py and activation_store.py hold the two stages apart.
The lifecycle moves from an authenticated source to verified objects, then to a native preparation result and an atomic active snapshot:
flowchart LR
A[Installed bundle or cloud release] --> B[Authenticated root]
B --> C[Native preparation]
C --> D[Verified cache objects]
D --> E[Prepared catalog and pack set]
E --> F[Authenticated activation record]
F --> G[Active runtime policy]
References: src/…/preparation.py• L77-155 src/…/activation_store.py• L91-134
Catalog and pack preparation
Source compilation
The preparation flow starts with command source programs and trust metadata. A native compiler converts them into a catalog, a native command program, and per-extension policy packs. The release root then names the complete inventory and the engine that can interpret it.
The compiler validates trust classes, activation defaults, matcher coverage, and compatibility fallbacks as it lowers source metadata. It admits a complete catalog or pack only after the resulting native program and required inventory pass native validation. A failed or partial build cannot replace the previous complete release root. This makes a source change produce a new content identity instead of mutating policy data already in use. native_command_source_catalog.rs defines the source-to-artifact boundary.
References: rust/…/native_command_source_catalog.rs• L43-79 rust/…/native_command_source_catalog.rs• L168-241 rust/…/native_command_source_catalog.rs• L367-424
Catalog validation
Catalog loading treats the packaged catalog and native command program as one contract. It checks the schema and size limits first. It then checks canonical digests, relationship references, permission ownership, rule ownership, matcher contracts, and authoring provenance.
The result is an immutable catalog with indexes for extensions, aliases, rules, permissions, action classes, capabilities, and candidate executables. Any missing, duplicated, mismatched, or oversized part fails closed instead of producing a partial catalog. generated_command_catalog_loader.py is the release-artifact validation boundary.
References: src/…/generated_command_catalog_loader.py• L333-438 src/…/generated_command_catalog.py• L275-337
Pack preparation
Native preparation is a metadata-only discovery step behind an authenticated installed or remote factory. It validates the authority root, release schema, engine identity, object index, transport description, and extension count before it creates a private discovery area. It does not read or admit a pack as active policy.
The adapter follows native fetch requests in bounded rounds. It may request individual objects or batches, and it validates each returned length and digest before using it. It walks the transport and index proofs, validates record ownership and locations, and writes compact discovery pages only after it has one valid metadata row for every expected extension. A result becomes a discovery handle only after native preparation reports a complete object graph.
The handle is bound to the authenticated authority, guard home, profile, and validity window. A catalog read through an invalid, expired, or unknown handle returns unavailable. This keeps discovery useful for selection and explanation without allowing a transport result to become runtime authority.
References: rust/…/catalog_prepare.rs• L83-161 rust/…/catalog_prepare.rs• L184-276 rust/…/catalog_prepare_proof.rs• L108-166 rust/…/catalog_prepare.rs• L316-330
Authority sources
Installed source
The installed source is the command-pack bundle shipped with the trusted release. Native manifests bind the bundle and source compiler to the same installed executable identity. This source has no remote freshness claim, so it can provide local policy data but cannot claim cloud publication authority.
The installed factory also supplies bounded reads for local objects and packs. If an optional installed asset is absent, the system can use the release-bound asset path when native checks allow it. The factory rejects caller-controlled roots and unbound package data. installed_bundle.py defines this local authority profile.
References: src/…/installed_bundle.py• L1-5 src/…/installed_bundle.py• L245-275
Cloud source
The cloud source starts with a small advisory selector. The selector identifies a source commit, publication, and root digest. The client fetches the matching root and provenance, then verifies the release against the fixed repository, workflow, signer, source commit, and artifact digest.
The verified root carries an authority epoch, validity interval, engine identity, object indexes, defaults, and revocations. A valid cloud root is suitable for preparation only. Native admission and the activation transaction still decide whether it can replace the current policy.
References: src/…/transport.py• L126-172 src/…/authority.py• L48-136 src/…/authority.py• L209-312
Source synchronization
Synchronization compares installed and cloud authority through a protected lifecycle floor. New cloud publications must advance the retained source lineage and version. An installed upgrade may change the native engine while preserving the highest accepted cloud identity.
The system performs synchronization on update and observation paths, not during command decisions. A transient cloud outage leaves a complete active policy in place. A required proof for a newer authenticated observation can instead move the system into a conservative pending state until the proof is available.
References: src/…/transport.py• L130-153 src/…/active_security.py• L167-215 src/…/lifecycle.py• L57-113
Cache and transfer state
Content-addressed cache
The cache stores pack objects by their SHA-256 identity. Writers use temporary files and publish complete objects atomically. Readers check object type, length, digest, nesting depth, and expansion limits before using the bytes.
The cache is reusable across preparation attempts, but it is not authority. Native preparation proves that the object belongs to the authenticated release and to the current engine. A cache hit can reduce transfer work; it cannot substitute for release verification. catalog_prepare_proof.rs reuses native object verification for preparation reads.
References: src/…/pack_store.py• L17-31 src/…/pack_store.py• L44-65 rust/…/catalog_prepare_proof.rs• L108-140
Archive transfer
Large object sets can move as deterministic ZIP archives. The producer includes only objects reachable from the requested pack. The consumer verifies the archive digest, directory bounds, member names, regular-file type, stored format, and each member digest before publishing objects into the cache.
Archive ingestion may leave unused immutable objects after a later failure. That is safe because only a complete native preparation can produce an activation draft. pack_archives.py implements transfer as data movement rather than authority.
References: src/…/pack_archives.py• L22-32 src/…/pack_archives.py• L78-129
Preparation sessions
Preparation and activation share a private command-pack directory under the native runtime state area. A bounded native session protects its discovery work while it reads and expands the object graph. The session closes on success or failure so that another lifecycle operation can retry without using an incomplete preparation.
The session supports individual and batched fetches, limits live sessions and handles, and reclaims an older session when the budget is full. It publishes compact pages only after all expected rows are present. A damaged cached object is fetched again; returned data must match the requested reference before it can repair the cache. catalog_prepare.rs defines this preparation boundary.
References: rust/…/catalog_prepare.rs• L36-63 rust/…/catalog_prepare.rs• L134-161 rust/…/catalog_prepare.rs• L188-276 rust/…/catalog_prepare.rs• L349-471
Selection and activation
Pack selection
Selection is an intent to prepare a set of extensions. Native planning resolves dependencies and rejects unavailable or revoked entries. A selected extension can be active only when the surrounding control authority enables it; a presentation pack or selection plan does not grant an enable state.
The selection result includes both the selected execution set and the wider registry needed to explain retained controls. Permission suggestions are constrained by each permission's baseline floor, so a pack cannot weaken an existing safety baseline. pack.py illustrates the presentation rule, while native preparation owns runtime selection.
References: src/…/pack.py• L163-209 src/…/preparation.py• L110-120
Activation record
Activation seals the prepared candidate into a bounded record. The record binds the selected IDs, registry metadata, executable names, program and catalog digests, source and publication identity, engine, revocation epoch, validity interval, and the previous record digest.
The record is authenticated with the local verifier key and stored with its digest and MAC. Its referenced pages remain in the immutable object cache. This gives startup and recovery a small authenticated header while preserving access to the catalog closure.
References: src/…/activation_record.py• L69-125 src/…/activation_record.py• L153-244
Atomic activation
Activation validates the protected lifecycle floor and the predecessor before it enters the control mutation lease. The final transaction checks the draft header, revision, scope identity, and current record again. It then commits the lifecycle state and activation record together.
This ordering prevents a prepared candidate from becoming active after another writer has changed the controls. It also avoids network lookup and large metadata reconstruction inside the final transaction. activation_transition.py stages the candidate; activation_store.py commits it.
References: src/…/activation_transition.py• L14-64 src/…/activation_store.py• L91-134
Migration and recovery
Installed migration
Startup migration moves an older control store to the installed command-pack authority without rewriting existing user controls or permissions. It first requires authenticated legacy anchor and snapshot evidence plus a verified installed release. It records a lifecycle floor so later operations cannot rebuild authority from stale legacy rows.
The migration is idempotent. An install with no legacy controls can derive its initial floor from the verified installed release. If the protected floor or retained legacy evidence is missing, corrupt, rolled back, or inconsistent, migration fails closed rather than re-enrolling from the legacy database. migration.rs owns the native migration boundary.
References: rust/…/migration.rs• L133-170 rust/…/migration.rs• L295-344
Engine migration
When the installed native engine changes, the active selection can be prepared again from the authenticated source. The old compiled policy objects are not reused across engines, even when the source and publication identity are known. The lifecycle floor preserves accepted version and source history while the new engine produces fresh policy data.
This distinction lets an installed release upgrade safely without accepting old executable policy IR as if it were valid for the new matcher engine. pack_lifecycle.rs keeps engine compatibility in lifecycle planning.
References: rust/…/pack_lifecycle.rs• L264-307 rust/…/native_command_source_catalog.rs• L367-424
Offline subset
An offline subset reuses only a previously committed authenticated publication and its cache. Native checks require the exact committed predecessor and reject a caller that tries to introduce a new cloud identity while offline.
The subset can reduce or retain the committed selection without contacting the network. It cannot lower the lifecycle floor or turn an uncommitted cache into authority. activation_transition.py and offline.py define this recovery path.
References: src/…/activation_transition.py• L25-55 src/…/offline.py• L94-105
Active synchronization
Background observation compares the active authenticated record with installed and cloud sources. It refreshes proofs and metadata outside hook and decision paths, then uses compare-and-swap checks before publishing a changed protected observation.
If SQL state is replaced or the process restarts, reconciliation starts from the protected native observation. It can restore the same active marker offline. It cannot revive an older policy when the authenticated record says that newer proofs are pending or required.
References: src/…/active_security.py• L95-165 src/…/active_security.py• L233-265
Related authority pages
The broader runtime authority model is described in native-runtime-authority. Use native-runtime-residency-and-recovery for resident state and recovery behavior, native-command-evaluation-and-classification for command evaluation after admission, and native-command-source-programs for source-program ownership and generation.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the catalog digest, native program digest, source provenance digest, and engine identity aligned across packaged artifacts and prepared-pack metadata.
- Keep release-root object indexes, archive locations, object names, and cache verification rules compatible. A valid root with an unreachable or substituted object must remain unavailable.
- Keep discovery handle binding aligned with the guard home, authority digest, profile, and expiry. A metadata handle must not become activation authority.
- Keep activation record page counts and registry contents aligned with the selected set. Retained inactive metadata is part of control continuity.
- Keep installed and remote lifecycle transitions monotonic. A new engine must reprepare policy objects instead of reusing old-engine IR.
- Keep migration dependent on authenticated legacy evidence and the protected integrity anchor. Do not restore authority from legacy rows after protected-floor loss.
- Keep refresh and synchronization outside command-decision paths. A proof outage must not silently replace the last known active policy.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Catalog and native program digests differ | Catalog admission fails closed | Cross-artifact digest and ownership checks |
| A cached object has changed bytes | Preparation rejects the object or fetches it again | Content-addressed digest and length verification |
| An authority root is expired or has the wrong schema | Preparation or catalog reads become unavailable | Profile-specific authority and expiry checks |
| A release root has an invalid location or incomplete index | Preparation cannot produce a complete discovery result | Located-reference, ownership, count, and graph checks |
| A release root is expired or not attested | New preparation or activation is refused | Validity checks and fixed Sigstore provenance policy |
| A pack is revoked | Preparation stops for that extension or pack | Authenticated revocation lookup before use |
| Another writer changes the active record | The staged activation is rejected | Predecessor, revision, floor, and scope checks |
| The native engine changes | Old compiled policy cannot be admitted | Engine-bound pack verification and re-preparation |
| Protected lifecycle state or legacy evidence is missing or corrupt | Migration and lifecycle reads fail closed | MAC-protected floor and authenticated legacy evidence |
Key files
| File | Why to read it |
|---|---|
| rust/…/native_command_source_catalog.rs | Source lowering, trust projection, matcher compilation, and artifact admission |
| rust/…/catalog_prepare.rs | Authenticated metadata discovery, bounded sessions, and discovery handles |
| rust/…/catalog_prepare_proof.rs | Located object proofs, bounded graph walking, and transport integrity |
| src/…/generated_command_catalog_loader.py | Catalog and native-program validation boundary |
| src/…/authority.py | Cloud release identity and provenance checks |
| src/…/pack_store.py | Immutable object cache and compiled-pack integrity |
| src/…/pack_archives.py | Archive creation and safe object ingestion |
| src/…/activation_record.py | Authenticated active snapshot shape |
| src/…/activation_transition.py | Lifecycle validation before activation |
| src/…/activation_store.py | Atomic activation commit |
| rust/…/pack_lifecycle.rs | Native lifecycle authority, source transitions, and operation dispatch |
| rust/…/selection.rs | Control-layer composition and selected-versus-retained extension sets |
| rust/…/migration.rs | Authenticated legacy migration and recovery evidence |
| rust/…/floor.rs | Protected monotonic lifecycle floor |