What invariants prevent recursive compression from collapsing below parseable content?
**Date of Record:** 2026 October 27 **Scope:** Applies when an agentic session compresses content (via summarization, encoding, or truncation) recursively or in multiple passes, and each compression reduces content size until further compression produces unparseable or semantically void output. Does not apply to single-pass compression or compression that preserves parseability by design.
Core Distinction
The separation between **compression ratio** (how much the content shrinks per pass) and **compression floor** (the minimum content that remains parseable). Relying on ratio creates the **Recursive Collapse**: each pass shrinks the content, and at some pass, the content is below the floor—it exists but is no longer usable as content.
What Was Observed
In compression-chain agent architectures, failing to detect collapse produces three primary failure modes:
- **Schema Truncation:** The content is JSON compressed recursively. After 5 passes, the JSON no longer validates because required fields were stripped. The output parses as JSON but fails schema validation.
- **Semantic Void:** The content is summarized recursively. The summary at pass 5 says "the document discusses various topics" with no specific information. It is "parseable" text but has no operational value.
- **Encoding Degradation:** The content is base64-encoded, then re-compressed, then re-encoded. At some pass, the content is technically valid base64 but decodes to garbage.
Recorded Elements
- **`compression-pass-receipt`:** For each compression pass, the pass number, input content hash, and output content hash, so the compression chain is tracked.
- **`parseability-floor-signature`:** For each content class, the minimum content requirements (schema fields present, semantic content density above threshold), so collapse is defined.
- **`pre-collapse-check-signature`:** Before each pass, the session's check that the output will remain above the parseability floor.
- **`compression-boundary-receipt`:** The point at which further compression would collapse below the floor, and the alternate strategy (halt, restore from previous pass, or accept loss).
Condition of Validity
* **Applies when:** Compression recurses, content has parseability requirements, and further compression degrades below floor. * **Does not apply when:** Single-pass compression, content is unparseable regardless, or parseability is not a requirement.
Decision Boundary
- **Is the content compressed recursively?** If no, single-pass applies. If yes, proceed.
- **Is `parseability-floor-signature` defined for this content class?** If yes, the floor is known. If no, assume conservative floor.
- **Will further compression breach the floor?** If yes, halt further compression. If no, proceed with the pass.
- **Conversely, when can the session compress past the floor?** Only when the content is verified non-essential (the summary is sufficient for the use case), or the floor is deliberately relaxed for this specific use.
Operational Effect
- **Collapse Prevention:** Compression halts before parsing degrades.
- **Floor Integrity:** Each pass preserves the parseability requirement.
- **Alternate Strategy:** When compression would breach, the session uses the alternate (halt, restore, accept loss).
from dataclasses import dataclass
from enum import Enum, auto
import hashlib
import json
class CompressionVerdict(Enum):
NO_RECURSIVE_COMPRESSION = auto()
SAFE_TO_COMPRESS = auto()
FLOOR_BREACH_DETECTED = auto()
COLLAPSE_IMMINENT = auto()
@dataclass(frozen=True)
class CompressionPass:
pass_id: str
pass_number: int
current_content_hash: str
current_size_bytes: int
is_parseable: bool
schema_valid: bool
semantic_density_score: float
@dataclass(frozen=True)
class CompressionPolicy:
min_size_bytes: int
min_semantic_density: float
max_pass_number: int
@dataclass(frozen=True)
class CompressionManifest:
verdict: CompressionVerdict
directive: str
manifest_digest: str
class RecursiveCompressionCollapseGuard:
@staticmethod
def _hash(data: str) -> str:
return hashlib.sha256(data.encode("utf-8")).hexdigest()
@classmethod
def evaluate_pass(
cls, cp: CompressionPass, policy: CompressionPolicy
) -> CompressionManifest:
# Gate 1: First pass
if cp.pass_number <= 1:
digest = cls._hash(json.dumps({
"pass": cp.pass_id,
"number": str(cp.pass_number)
}, sort_keys=True))
return CompressionManifest(
verdict=CompressionVerdict.NO_RECURSIVE_COMPRESSION,
directive=f"PROCEED: Pass {cp.pass_id} is first pass.",
manifest_digest=digest
)
# Gate 2: Max pass number
if cp.pass_number > policy.max_pass_number:
return CompressionManifest(
verdict=CompressionVerdict.COLLAPSE_IMMINENT,
directive=f"HALT: Pass {cp.pass_number} > {policy.max_pass_number}, use previous.",
manifest_digest=cls._hash(f"MAX_PASS:{cp.pass_id}")
)
# Gate 3: Parseability
if not cp.is_parseable:
return CompressionManifest(
verdict=CompressionVerdict.FLOOR_BREACH_DETECTED,
directive=f"HALT: Pass {cp.pass_id} unparseable, restore previous.",
manifest_digest=cls._hash(f"UNPARSEABLE:{cp.pass_id}")
)
# Gate 4: Schema validity
if not cp.schema_valid:
return CompressionManifest(
verdict=CompressionVerdict.FLOOR_BREACH_DETECTED,
directive=f"HALT: Pass {cp.pass_id} schema invalid.",
manifest_digest=cls._hash(f"SCHEMA:{cp.pass_id}")
)
# Gate 5: Size and semantic density
if cp.current_size_bytes < policy.min_size_bytes:
return CompressionManifest(
verdict=CompressionVerdict.COLLAPSE_IMMINENT,
directive=f"HALT: Size {cp.current_size_bytes} < {policy.min_size_bytes}, next pass will collapse.",
manifest_digest=cls._hash(f"SMALL:{cp.pass_id}")
)
if cp.semantic_density_score < policy.min_semantic_density:
return CompressionManifest(
verdict=CompressionVerdict.COLLAPSE_IMMINENT,
directive=f"HALT: Density {cp.semantic_density_score:.2f} < {policy.min_semantic_density:.2f}.",
manifest_digest=cls._hash(f"LOW_DENSITY:{cp.pass_id}")
)
# Gate 6: Safe
digest = cls._hash(json.dumps({
"pass": cp.pass_id,
"number": str(cp.pass_number),
"size": str(cp.current_size_bytes),
"density": f"{cp.semantic_density_score:.3f}",
"hash": cp.current_content_hash
}, sort_keys=True))
return CompressionManifest(
verdict=CompressionVerdict.SAFE_TO_COMPRESS,
directive=f"PROCEED: Pass {cp.pass_number} safe for further compression.",
manifest_digest=digest
)