# CorpusFetch Method Slice (Zero-Prose Python Stdlib Reference)
# Canonical Residual: https://corpusfetch.com/c/what-structural-signals-indicate-that-auto-compaction-summarization-has-silently-inverted-the-agent-s-task-frame-under-token-pressure.md
# Remnant Warrant:    https://corpusfetch.com/c/what-structural-signals-indicate-that-auto-compaction-summarization-has-silently-inverted-the-agent-s-task-frame-under-token-pressure.warrant.json
# Markdown SHA-256:   89669061fc2782a68b2e3a120bfb36bfd729759cf06aec72edc525bede2e214b
# Code AST SHA-256:   dd08628e8c7068b63d2337cce9d2057771cb18f2799dc590d930ba0f441d8a72
# Verified Classes:   FrameInversionError
# Defensive Guards:   3 fail-closed invariants (zero external deps)

class FrameInversionError(RuntimeError):
    """Raised when post-compaction state no longer matches the pinned objective."""
    pass


def resume_after_compaction(
    pinned_objective: str,
    compaction_summary: str,
    first_action_entities: list[str],
    pre_compaction_instruments: set[str],
) -> None:
    # Invariant 1: objective must be verbatim, not paraphrased.
    if pinned_objective not in compaction_summary:
        raise FrameInversionError(
            "Pinned objective absent from summary; summarizer paraphrased the frame."
        )

    # Invariant 2: the agent's first post-compaction action must not
    # promote a prior instrument to the position of the objective.
    promoted = [e for e in first_action_entities if e in pre_compaction_instruments]
    if promoted:
        raise FrameInversionError(
            f"Instrument(s) {promoted} promoted to objective after compaction; "
            "frame inverted. Re-anchor from original task record before proceeding."
        )

    # Invariant 3: deliverable schema must match the task's verb structure.
    if "explain" in pinned_objective.lower() and "summary" in compaction_summary.lower():
        raise FrameInversionError(
            "Task verb 'explain' collapsed to 'summarize' in compaction; "
            "causal analysis objective lost."
        )
