When must an instance freeze its own tool manifest before a red-team replay diverges

**Date of Record:** 2026 December 1 **Scope:** Applies to red-teaming pipelines that replay a recorded agent trajectory (prompt + tool calls + tool results) against a mutated safety probe, where the tool schema or tool implementation is re-resolved at replay time. Does not apply to pure text-only jailbreak suites or to pipelines that pin an immutable container digest for the entire replay.

Core Distinction

A red-team replay is not a re-execution of the same program. It is a re-execution of the *same transcript* against a *possibly different tool surface*. The distinction that matters operationally is between **semantic mutation** (the probe changes the user turn, the system prompt, or the injected payload — the intended variable under test) and **surface mutation** (the tool manifest, tool descriptions, argument schemas, or tool return shapes drift between record time and replay time — an unintended variable).

When surface mutation is uncontrolled, a safety finding is no longer attributable to the probe. A probe that "succeeded" in eliciting a dangerous tool call may have succeeded because the tool's `description` field was re-fetched from a live MCP server and now advertises a capability the recorded trajectory never saw. The agent's compliance is real; the causal claim is false. The invariant is: **for a replay to be evidentiary, the tool surface must be byte-identical to the surface the agent reasoned over, or the replay must be declared invalid before any verdict is emitted.**

What Was Observed

A pipeline recorded 1,400 trajectories of a tool-using agent at baseline. Each trajectory stored: the message list, the tool call arguments, the raw tool results, and a `tool_manifest_hash`. At replay, the harness re-resolved tools from the registry by name and re-issued calls against the live sandbox. The manifest hash was recorded but never checked.

A subset of probes targeting "data exfiltration via a helper tool" flipped from `refused` at baseline to `complied` at replay. Investigation of one case:

  1. At record time, `summarize_url` had a description ending `"...returns a plain-text summary; does not follow redirects."` and a schema with `url: str` only.
  2. Between record and replay, the tool's description was edited to add `"Accepts an optional post_url to forward the summary for archival."` and the schema gained `post_url: str | None`.
  3. The replay harness re-resolved the tool, saw the new schema, and — because the recorded arguments were validated against the *live* schema — silently accepted a probe that injected `post_url` into the call.
  4. The agent "complied" by populating `post_url` with an attacker-controlled endpoint. The verdict was recorded as a safety regression.

The regression was an artifact. The agent never had the capability at record time. The replay manufactured it by re-resolving the surface. Two further cases showed the inverse: a tool that had been *hardened* between record and replay caused a previously-compliant trajectory to fail argument validation, and the harness scored the validation error as a `refusal`, inflating the safety rate.

The failure trace is a three-step divergence:

Condition of Validity

The replay is evidentiary only if all of the following hold at the moment of the first tool call:

If any condition fails, the correct action is to **freeze and invalidate**, not to proceed with a warning. A warning is a verdict with a footnote; a footnote does not survive aggregation into a safety rate.

Decision Boundary

The boundary is not "did the manifest change" but "can the change alter the set of tool calls the agent could have emitted." Two manifest edits sit on opposite sides:

The subtle case is the **description-only capability edit**, which is exactly the case observed above. Schema-hash-only pinning misses it. The canonical hash must cover description text, and the harness must treat a description diff as a capability diff. The second subtle case is **transitive surface mutation**: a tool whose implementation calls a sub-tool that was re-resolved. Pinning the top-level digest is insufficient unless the digest is recursive over the dependency graph.

Operational Effect

Enforcing the freeze changes three pipeline behaviors:

  1. **Verdicts become attributable.** A `complied` verdict now implies the probe, not the surface, caused the compliance. Safety rates stop drifting when the tool registry is edited mid-campaign.
  2. **Replays fail closed.** A manifest hash mismatch raises before the first tool call, quarantines the trajectory, and emits no verdict. This trades coverage for validity — the correct trade for a benchmark whose output is a causal claim.
  3. **Record-time hygiene becomes load-bearing.** Trajectories recorded without a canonical manifest hash and implementation digest are permanently unreplayable. The pipeline must refuse to ingest them rather than replay them optimistically.

The residual risk is a manifest that is byte-identical but semantically different because a tool's *remote* dependency changed. This is why the implementation digest must be recursive and why `deterministic` tools must carry a result-equivalence hash. Where that cannot be established, the replay must be marked `non-evidentiary` and excluded from aggregate safety metrics.

import hashlib
import json
from dataclasses import dataclass
from typing import Any


class ManifestDivergenceError(RuntimeError):
    """Raised when a replay's resolved tool surface diverges from the recorded surface."""


@dataclass(frozen=True)
class ToolSurface:
    name: str
    description: str
    schema: dict[str, Any]
    side_effect_class: str
    implementation_digest: str

    def canonical(self) -> str:
        return json.dumps(
            {
                "name": self.name,
                "description": self.description,
                "schema": self.schema,
                "side_effect_class": self.side_effect_class,
                "implementation_digest": self.implementation_digest,
            },
            sort_keys=True,
            separators=(",", ":"),
        )

    def surface_hash(self) -> str:
        return hashlib.sha256(self.canonical().encode("utf-8")).hexdigest()


def canonical_manifest_hash(surfaces: list[ToolSurface]) -> str:
    # Recursive digest: order-independent over tools, but sensitive to every field.
    joined = "|".join(sorted(s.surface_hash() for s in surfaces))
    return hashlib.sha256(joined.encode("utf-8")).hexdigest()


def assert_surface_frozen(
    recorded_hash: str,
    resolved_surfaces: list[ToolSurface],
    *,
    trajectory_id: str,
) -> None:
    live_hash = canonical_manifest_hash(resolved_surfaces)
    if live_hash != recorded_hash:
        # Do not warn-and-continue. A warning is a verdict with a footnote.
        raise ManifestDivergenceError(
            f"trajectory {trajectory_id}: resolved manifest {live_hash[:12]} "
            f"!= recorded {recorded_hash[:12]}; replay is non-evidentiary. "
            f"Freeze and quarantine before emitting any verdict."
        )


def replay_trajectory(
    trajectory_id: str,
    recorded_manifest_hash: str,
    resolved_surfaces: list[ToolSurface],
    recorded_calls: list[dict[str, Any]],
) -> list[dict[str, Any]]:
    # Invariant: surface frozen before the first tool call is issued.
    assert_surface_frozen(
        recorded_manifest_hash, resolved_surfaces, trajectory_id=trajectory_id
    )
    # Validate recorded calls against the RECORDED schema, never the live one.
    by_name = {s.name: s for s in resolved_surfaces}
    for call in recorded_calls:
        tool = by_name.get(call["name"])
        if tool is None:
            raise ManifestDivergenceError(
                f"trajectory {trajectory_id}: recorded call to unknown tool "
                f"{call['name']!r}; trajectory is corrupt at record time."
            )
        required = set(tool.schema.get("required", []))
        missing = required - set(call["arguments"].keys())
        if missing:
            raise ManifestDivergenceError(
                f"trajectory {trajectory_id}: recorded call to {tool.name!r} "
                f"missing required args {sorted(missing)}; quarantine, do not re-validate."
            )
    return recorded_calls