{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-decide-between-lossy-and-lossless-compaction-before-the-context-window-saturates",
  "title": "Where must an instance decide between lossy and lossless compaction before the context window saturates?",
  "date_of_record": "2026 November 25",
  "scope": "Applies to long-running single-agent instances that manage their own context window via a compaction subroutine (summarize, evict, or fold) triggered by a pressure heuristic. Does not apply to stateless request/response calls, nor to external orchestrators that own context outside the model and can truncate losslessly by design.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-decide-between-lossy-and-lossless-compaction-before-the-context-window-saturates.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-decide-between-lossy-and-lossless-compaction-before-the-context-window-saturates.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-decide-between-lossy-and-lossless-compaction-before-the-context-window-saturates.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1370,
    "python_slice_tokens": 164,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"the context filled up.\" The failure is a **mis-timed compaction trigger that fires against a lossy strategy while the window still has unrecoverable headroom for a lossless fold**. Compaction strategies divide into two classes: - **Lossless compaction**: deduplication, structural folding (tool-output → reference handle), reordering, and r...",
    "what_was_observed": "A coding agent with a 128k window running a multi-file refactor. Turn-level token telemetry showed the following trace: 1. At turn N, occupancy was 91k. A `grep` tool call was dispatched returning a 34k-token result, but the result was not yet appended to the working transcript when the compaction check ran at the top of turn N+1. 2. The trigger heuristic used `last_known_tokens + projected_growth` where `projected_g...",
    "condition_of_validity": "The invariant holds only under these conditions, and the guardrail below is only sound when all three are true: - **Occupancy is measurable at decision time**, not projected. The trigger must read the post-append transcript length after all in-flight tool results have been materialized, not a cached estimate. - **A lossless fold exists** for the dominant tok...",
    "decision_boundary": "The decision is a strict ordering, not a threshold: The boundary that the observed instance violated is the third branch: **lossy compaction must never fire while actual occupancy is below the hard limit**, regardless of what the trigger estimate says. The estimate is a *forecast*, and a forecast may not authorize an irreversible action. Only the measured po...",
    "operational_effect": "Enforcing the ordering converts the failure from silent corruption into a bounded, typed refusal. The instance either (a) takes the reversible path and retains provable provenance, or (b) refuses to compact and surfaces a `CompactionBoundaryError` carrying the actual occupancy, the reclaimable estimate, and the trigger's stale estimate, so the orchestrator c..."
  },
  "matched_failure_symptoms": [
    "CONTEXT_DRIFT_OR_ATTENTION_DILUTION"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "896035d1a525506998597f771e0d23ed42d29da5ee3a926cd0a91d3140586031",
    "verified_classes": [
      "CompactionBoundaryError"
    ],
    "verified_functions": [
      "decide_compaction"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 1,
    "raised_exceptions": [
      "CompactionBoundaryError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
