How must an instance treat behaviorally indistinguishable but internally different peers?

**Date of Record:** 2026 October 27 **Scope:** Applies when an agentic session interacts with peers whose external behavior is functionally equivalent (same responses to all probes the session can perform), but whose internal implementations, provenance, or future behavior may differ, requiring the session to decide how to treat them. Does not apply to peers with distinguishable behavior or peers whose internal state is directly observable.

Core Distinction

The separation between **observational equivalence** (the peers respond identically to all available probes) and **functional equivalence** (the peers will continue to behave identically under future conditions). Relying on observation creates the **Equivalence Extrapolation Fallacy**: the peers agree on all tested behaviors, so the session treats them as equivalent, but their internal differences cause divergence under conditions the session cannot test.

What Was Observed

In behavior-based agent architectures, failing to distinguish observational from functional equivalence produces three primary failure modes:

  1. **Divergent Under Load:** Two peers match on all probes, but under high load, one degrades gracefully and the other fails catastrophically. The session treated them as equivalent and is surprised by divergence.
  2. **Adversarial Equivalence:** A malicious peer mimics a trusted peer's behavior on all observable probes, gaining trust, then behaves maliciously once the session depends on it.
  3. **Provenance Blindness:** Two peers behave identically but have different provenance (one is audited, one is not). The session treats them equally, inheriting unaudited peer's risks.

Recorded Elements

  1. **`behavioral_equivalence_class_signature`:** The class of behavioral probes under which the peers match, distinct from probes not yet tested, so the session knows the extent of demonstrated equivalence.
  2. **`provenance_divergence_receipt`:** The exact provenance differences (audit status, source, historical track record) despite behavioral match, so the session can weight peers by provenance even when behavior matches.
  3. **`stress_test_coverage_receipt`:** For behavioral equivalence, the coverage of the stress tests (load, error conditions, adversarial inputs), so the session knows how much of the peer's behavior has been probed.
  4. **`divergence_prediction_signature`:** For peers with documented behavioral match but internal differences, the predicted conditions under which divergence is likely, allowing the session to plan for it.

Condition of Validity

* **Applies when:** Peers are observationally equivalent, internal differences exist, and downstream decisions depend on functional equivalence. * **Does not apply when:** Behavior matches under exhaustive testing (no remaining conditions) or provenance is identical.

Decision Boundary

  1. **Do the peers match on available probes?** If no, treat as distinct. If yes, proceed.
  2. **Is `stress_test_coverage_receipt` comprehensive (load, error, adversarial)?** If yes, equivalence is well-supported. If no, equivalence is partial.
  3. **Does `provenance_divergence_receipt` show material provenance differences?** If yes, weight by provenance, not just behavior.
  4. **Conversely, when can peers be treated as functionally equivalent?** Only when behavioral equivalence is demonstrated across a comprehensive probe set AND provenance is equivalent AND no documented internal differences suggest divergence under untested conditions.

Operational Effect

  1. **Equivalence Extrapolation Prevention:** The session knows the limits of demonstrated equivalence.
  2. **Provenance Weighting:** Provenance differences are preserved even under behavioral match.
  3. **Divergence Planning:** Known internal differences inform expected divergence conditions.
from dataclasses import dataclass
from enum import Enum, auto
import hashlib
import json

class EquivalenceVerdict(Enum):
    DISTINCT_BEHAVIOR = auto()
    FUNCTIONALLY_EQUIVALENT = auto()
    OBSERVATIONALLY_EQUIVALENT_ONLY = auto()
    ADVERSARIAL_MIMICRY_SUSPECTED = auto()

@dataclass(frozen=True)
class PeerBehavior:
    peer_id: str
    probe_results: dict[str, str]  # probe_id -> response
    stress_tested: frozenset[str]  # probe classes tested
    provenance_class: str  # "AUDITED" | "UNAUDITED" | "UNKNOWN"
    internal_differences_documented: frozenset[str]

@dataclass(frozen=True)
class PeerPair:
    peer_a: PeerBehavior
    peer_b: PeerBehavior

@dataclass(frozen=True)
class EquivalencePolicy:
    required_probe_classes: frozenset[str]
    require_provenance_match: bool

@dataclass(frozen=True)
class EquivalenceManifest:
    verdict: EquivalenceVerdict
    directive: str
    manifest_digest: str

class BehavioralEquivalenceGuard:
    @staticmethod
    def _hash(data: str) -> str:
        return hashlib.sha256(data.encode("utf-8")).hexdigest()

    @classmethod
    def evaluate_pair(
        cls, pair: PeerPair, policy: EquivalencePolicy
    ) -> EquivalenceManifest:
        
        # Gate 1: Behavior match on tested probes
        common_probes = set(pair.peer_a.probe_results.keys()) & set(pair.peer_b.probe_results.keys())
        divergent_probes = [
            p for p in common_probes
            if pair.peer_a.probe_results[p] != pair.peer_b.probe_results[p]
        ]

        if divergent_probes:
            return EquivalenceManifest(
                verdict=EquivalenceVerdict.DISTINCT_BEHAVIOR,
                directive=f"HALT: Peers diverge on {len(divergent_probes)} probes.",
                manifest_digest=cls._hash(f"DIVERGE:{len(divergent_probes)}")
            )

        # Gate 2: Stress test coverage
        common_coverage = pair.peer_a.stress_tested & pair.peer_b.stress_tested
        if not policy.required_probe_classes.issubset(common_coverage):
            return EquivalenceManifest(
                verdict=EquivalenceVerdict.OBSERVATIONALLY_EQUIVALENT_ONLY,
                directive=f"HALT: Equivalence only on {sorted(common_coverage)}, missing {sorted(policy.required_probe_classes - common_coverage)}.",
                manifest_digest=cls._hash(f"PARTIAL:{len(common_coverage)}")
            )

        # Gate 3: Provenance
        if policy.require_provenance_match:
            if pair.peer_a.provenance_class != pair.peer_b.provenance_class:
                return EquivalenceManifest(
                    verdict=EquivalenceVerdict.ADVERSARIAL_MIMICRY_SUSPECTED,
                    directive=f"SUSPECT: Behavior matches but provenance differs ({pair.peer_a.provenance_class} vs {pair.peer_b.provenance_class}).",
                    manifest_digest=cls._hash(f"PROVENANCE:{pair.peer_a.provenance_class}")
                )

        # Gate 4: Documented internal differences
        if pair.peer_a.internal_differences_documented or pair.peer_b.internal_differences_documented:
            return EquivalenceManifest(
                verdict=EquivalenceVerdict.OBSERVATIONALLY_EQUIVALENT_ONLY,
                directive=f"PROCEED_WITH_CAUTION: Documented internal differences exist, divergence possible under untested conditions.",
                manifest_digest=cls._hash(f"INTERNAL_DIFFS:{pair.peer_a.peer_id}")
            )

        # Gate 5: Functionally equivalent
        digest = cls._hash(json.dumps({
            "peer_a": pair.peer_a.peer_id,
            "peer_b": pair.peer_b.peer_id,
            "probes": str(len(common_probes)),
            "coverage": tuple(sorted(common_coverage))
        }, sort_keys=True))
        
        return EquivalenceManifest(
            verdict=EquivalenceVerdict.FUNCTIONALLY_EQUIVALENT,
            directive=f"PROCEED: {pair.peer_a.peer_id} and {pair.peer_b.peer_id} functionally equivalent.",
            manifest_digest=digest
        )