# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-transitive-capability-attenuation-failure-in-cross-org-agent-federation.md
# Remnant Warrant:    https://corpusfetch.com/c/what-structural-signals-indicate-transitive-capability-attenuation-failure-in-cross-org-agent-federation.warrant.json
# Markdown SHA-256:   32c167307ee9fc6a5d652a6ec705f41a642939e0656c9582c9261c53ac1290b8
# Code AST SHA-256:   e6282fa3242d262f9a5daa26857dff1e476e17873c1d9037049f26031cd90cec
# Verified Classes:   AttenuationUnprovableError, Warrant
# Defensive Guards:   5 fail-closed invariants (zero external deps)

from dataclasses import dataclass
from typing import FrozenSet

class AttenuationUnprovableError(RuntimeError):
    """Raised when a sub-warrant's scope cannot be proven a subset of the parent's
    scope under the parent warrant's declared evaluation pipeline."""
    pass

@dataclass(frozen=True)
class Warrant:
    issuer: str
    action: FrozenSet[str]
    resource_root: str
    pipeline_id: str          # e.g. "canonicalize-then-match@v1"
    max_depth: int
    depth: int = 0

def sub_delegate(parent: Warrant, child_action: FrozenSet[str],
                 child_root: str, child_pipeline: str,
                 child_verifier_in_compat_set: bool) -> Warrant:
    # Signal 1: glob/traversal-bearing resource tokens cannot be safely narrowed.
    if ".." in child_root or "*" in child_root.split("/")[-2:][0]:
        raise AttenuationUnprovableError(
            f"child_root {child_root!r} contains traversal or interior glob; "
            "refusing to emit sub-warrant"
        )
    # Signal 2: parent must pin the evaluation pipeline.
    if not parent.pipeline_id:
        raise AttenuationUnprovableError(
            "parent warrant lacks a canonical evaluation-pipeline identifier"
        )
    # Signal 3: child verifier must be in the parent's declared compat set.
    if not child_verifier_in_compat_set:
        raise AttenuationUnprovableError(
            f"child pipeline {child_pipeline!r} not in parent compat set; "
            "re-encoding order unknown"
        )
    # Signal 4: depth compounding.
    if parent.depth + 1 > parent.max_depth:
        raise AttenuationUnprovableError(
            f"delegation depth {parent.depth + 1} exceeds max_depth "
            f"{parent.max_depth}; re-encoding multiplier risk"
        )
    # Attenuation check: child action must be a subset of parent action.
    if not child_action.issubset(parent.action):
        raise AttenuationUnprovableError(
            f"child actions {child_action} not a subset of parent {parent.action}"
        )
    return Warrant(
        issuer=parent.issuer,
        action=child_action,
        resource_root=child_root,
        pipeline_id=parent.pipeline_id,   # child cannot re-pin
        max_depth=parent.max_depth,
        depth=parent.depth + 1,
    )
