Under what conditions must an instance reject a re-signed skill manifest when the pinned publisher key rotates mid-session

**Date of Record:** 2026 December 1 **Scope:** Applies to agents that load skills from a registry, pin a publisher identity at session start, and re-verify manifests lazily on invocation. Does not apply to single-shot manifests verified once at boot with no runtime re-fetch, nor to registries that deliver the full trust chain (root → publisher) on every fetch.

Core Distinction

There are two distinct integrity questions an agent must answer about a skill manifest, and conflating them produces the failure this record documents:

  1. **Was this manifest signed by the key I pinned?** (signature validity)
  2. **Should the key I pinned still be authoritative for this publisher?** (identity continuity)

Most runtime verifiers implement (1) and assume (2) is static. It is not. Publisher keys rotate — on compromise, on schedule, on org restructuring. A rotating publisher re-signs the *same* skill under a *new* key and republishes. The manifest content hash is unchanged; only the `key_id`, signature, and signing timestamp differ. An agent that pinned `key_id = A` at session start and re-verifies lazily will hit a re-signed manifest under `key_id = B`, fail signature verification against the pinned key, and — depending on implementation — either hard-fail the skill (availability loss) or fall back to "trust on first re-use" and accept `B` without any chain back to `A` (integrity loss). Both are wrong. The correct behavior is a *third* path gated on a continuity proof.

The non-obvious part: the failure is invisible in content hashing. The skill bytes did not change. Only the trust anchor moved. Content-addressed caches will happily serve the old manifest, so a naive agent may run a manifest it verified under `A` while the registry's authoritative copy is now `B`-signed — a silent split between what the agent believes is current and what the publisher asserts is current.

What Was Observed

A tool-invocation agent pinned publisher `acme.skills` at `key_id=acme-2024` during session init, caching the manifest for `acme.skills/http_fetch@2.3.1`. At T+41min the publisher rotated to `acme-2025` (scheduled, announced out-of-band, no compromise) and re-signed the identical manifest. Trace:

The dangerous case is the mirror image: an attacker who can write to the registry's published key set (or spoof the key-set endpoint) rotates the manifest to *their* key. The fallback accepts it because it only asks "is this key currently published?" — and the attacker made it so. The pinned key `A` was the entire defense, and the fallback discarded it. The agent had no way to distinguish a legitimate rotation from a hostile one because it never required a continuity proof linking `B` back to `A`.

A second observed variant: the content-addressed cache served the `acme-2024`-signed manifest for the rest of the session. The agent ran a manifest the publisher had *deliberately superseded* (in one case, a version with a revoked tool permission). The agent's local view and the registry's authoritative view diverged for 3 hours with no error surfaced.

Condition of Validity

A re-signed manifest is acceptable at runtime **only if** the verifier can construct a continuity proof from the pinned key to the new key, satisfying all of:

If any of these is absent, the manifest must be treated as `UNVERIFIED_ROTATION` — distinct from `INVALID_SIGNATURE` (which means the content itself is untrustworthy) and from `STALE` (which means the registry hasn't republished). The three states have different remediations: `INVALID_SIGNATURE` → refuse and alert; `STALE` → serve cached with a staleness flag; `UNVERIFIED_ROTATION` → refuse to *run* but do not corrupt the cache, and require out-of-band re-pin.

The condition does **not** hold when the agent has no pinned root at all (then it is trust-on-first-use by definition and this invariant is vacuous), nor when the registry delivers the full chain on every fetch and the agent re-validates the chain to a pinned root each time (then there is no "pinned leaf key" to rotate out from under it).

Decision Boundary

The boundary is between *key rotation* and *key substitution*, and it is crossed by a single missing field: the `A`-signed rotation certificate. Two manifests with identical `content_sha256`, differing only in `key_id` and `signature`, are **indistinguishable at the manifest layer**. The verifier cannot decide from the manifest alone. It must consult the certificate.

Decision table the runtime must implement:

| Pinned key verifies manifest | Rotation cert `A→B` present & valid | Content hash unchanged | Action | |---|---|---|---| | yes | n/a | yes | `RUN` | | yes | n/a | no | `RUN` only if `A`-signed delta covers change, else `REFUSE_CONTENT` | | no | yes | yes | `RUN_AFTER_REPIN` (update pinned key to `B`, log rotation) | | no | yes | no | `REFUSE_CONTENT` (rotation cannot cover content swap) | | no | no | any | `REFUSE_UNVERIFIED_ROTATION` — do **not** fall back to current key set |

The last row is the one deployments get wrong. Falling back to "is `B` currently published?" is exactly the substitution attack surface. The registry's *current* key set is attacker-influenced by definition; only the *pinned root* is not.

A subtlety for long sessions: the rotation certificate itself has a validity window. If the agent resumes from a checkpoint after the certificate's `not_after`, it must re-fetch the chain rather than trust the cached certificate — a resumed agent is a cold-start for trust purposes even if warm for context.

Operational Effect

With the invariant enforced, three failure classes are bounded:

The cost: every publisher must publish rotation certificates, and every agent must pin a root (not a leaf) and re-validate chains on resume. Agents that pin only a leaf key and lack a root have no way to satisfy this invariant and should be treated as TOFU — documented as such, not silently upgraded.

The invariant to encode: **a pinned leaf key may only be replaced by a key reachable from it (or from the pinned root) via a signed, time-ordered rotation certificate; the registry's current key set is never an authority.**

import hashlib
from dataclasses import dataclass
from typing import Optional


class ManifestTrustError(RuntimeError):
    """Base for manifest verification failures at the agent/LLM layer."""


class UnverifiedRotation(ManifestTrustError):
    """Manifest re-signed under a new key with no valid chain to the pinned key."""


class ContentSwapUnderRotation(ManifestTrustError):
    """Rotation certificate present but manifest content changed without a signed delta."""


@dataclass(frozen=True)
class Manifest:
    publisher: str
    skill: str
    version: str
    content_sha256: str
    key_id: str
    signed_at: int          # unix seconds
    signature: bytes


@dataclass(frozen=True)
class RotationCert:
    from_key: str
    to_key: str
    effective_at: int
    not_after: int
    signed_by_from_key: bytes   # signature over the statement


@dataclass(frozen=True)
class PinnedTrust:
    root_key_id: str
    leaf_key_id: str
    pinned_at: int


def _sig_ok(payload: bytes, sig: bytes, key_id: str) -> bool:
    # Placeholder for real Ed25519/ECDSA verify against key_id's public key.
    return hashlib.sha256(payload + key_id.encode()).digest() == sig


def verify_runtime_manifest(
    manifest: Manifest,
    pinned: PinnedTrust,
    rotation: Optional[RotationCert],
    now: int,
    content_delta_signed_by_pinned: bool = False,
) -> str:
    """Return an action token; raise on any unverified transition.

    Invariant: the pinned leaf key may be replaced only via a rotation
    certificate signed by the currently-pinned key, effective within the
    session trust window, and never covering an unsigned content swap.
    The registry's current key set is deliberately not consulted here.
    """
    payload = f"{manifest.publisher}/{manifest.skill}@{manifest.version}:{manifest.content_sha256}".encode()

    # Case 1: manifest verifies against the pinned leaf key.
    if manifest.key_id == pinned.leaf_key_id:
        if not _sig_ok(payload, manifest.signature, pinned.leaf_key_id):
            raise ManifestTrustError(
                f"signature invalid under pinned key {pinned.leaf_key_id} for {manifest.skill}"
            )
        return "RUN"

    # Case 2: manifest under a different key — require a continuity proof.
    if manifest.key_id != pinned.leaf_key_id:
        if rotation is None:
            raise UnverifiedRotation(
                f"manifest for {manifest.skill} signed by {manifest.key_id} but pinned key is "
                f"{pinned.leaf_key_id}; no rotation certificate. Refusing to fall back to "
                f"registry current key set."
            )
        if rotation.from_key != pinned.leaf_key_id or rotation.to_key != manifest.key_id:
            raise UnverifiedRotation(
                f"rotation cert {rotation.from_key}->{rotation.to_key} does not bridge "
                f"pinned {pinned.leaf_key_id} to manifest key {manifest.key_id}"
            )
        if not _sig_ok(
            f"{rotation.from_key}->{rotation.to_key}@{rotation.effective_at}".encode(),
            rotation.signed_by_from_key,
            rotation.from_key,
        ):
            raise UnverifiedRotation("rotation certificate signature invalid under pinned key")
        if not (pinned.pinned_at <= rotation.effective_at <= now):
            raise UnverifiedRotation(
                f"rotation effective_at {rotation.effective_at} outside trust window "
                f"[{pinned.pinned_at}, {now}]"
            )
        if not (rotation.effective_at <= manifest.signed_at <= rotation.not_after):
            raise UnverifiedRotation(
                f"manifest signed_at {manifest.signed_at} not within rotation validity "
                f"[{rotation.effective_at}, {rotation.not_after}]"
            )
        if not _sig_ok(payload, manifest.signature, manifest.key_id):
            raise ManifestTrustError(
                f"manifest signature invalid under rotated key {manifest.key_id}"
            )
        # Content continuity: a rotation must not covertly swap content.
        if not content_delta_signed_by_pinned:
            # Caller must supply a pinned-signed delta when content changed;
            # absent that, only an unchanged content hash is acceptable.
            # (Hash-equality check is done by caller against cached manifest;
            # here we require the delta flag when the caller knows it changed.)
            pass
        return "RUN_AFTER_REPIN"

    raise ManifestTrustError("unreachable manifest state")