{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-task-critical-state-loss-when-automatic-context-compaction-rewrites-the-working-set",
  "title": "Which invariants prevent task-critical state loss when automatic context compaction rewrites the working set",
  "date_of_record": "2026 November 27",
  "scope": "Applies to any agent loop where a runtime autonomously summarizes, folds, or evicts context segments (sliding-window summarization, hierarchical fold, LLM-authored compaction) while a multi-step task is in flight. Does not apply to stateless single-shot inference, nor to systems where the caller owns the full transcript and no runtime-initiated rewrite occurs.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-task-critical-state-loss-when-automatic-context-compaction-rewrites-the-working-set.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-task-critical-state-loss-when-automatic-context-compaction-rewrites-the-working-set.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-task-critical-state-loss-when-automatic-context-compaction-rewrites-the-working-set.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2084,
    "python_slice_tokens": 286,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure here is not \"the summary was low quality.\" It is that automatic compaction is a **lossy, non-invertible, agent-authored transformation applied to the agent's own working memory by a process that cannot verify what the downstream continuation will need**. The compactor sees a prefix and a token budget; it does not see the future reasoning trace th...",
    "what_was_observed": "A representative trace, condensed: 1. Agent executes `provision_resource(...)` → tool returns `{\"id\": \"res_8f3a2c\", \"status\": \"PENDING\", \"poll_token\": \"pt_9d1e...\"}`. This is binding state. 2. Agent reasons for ~40 turns, accumulating long tool outputs (log dumps, schema blobs). Context approaches the soft limit. 3. Runtime triggers compaction. The compactor summarizes turns 1–30 into ~400 tokens. The summary reads: ...",
    "condition_of_validity": "Automatic compaction preserves task-critical state **only if all of the following hold simultaneously**: - **C1 — Binding/narrative separation is explicit.** The runtime can classify context segments as binding (must survive verbatim) vs. narrative (may be rewritten). If classification is delegated to the same LLM doing the summarizing, C1 fails: the summari...",
    "decision_boundary": "The operational choice is **what to compact and when**, and it hinges on whether the pending continuation has unresolved bindings. - **Compact narrative freely; never compact binding.** If a segment contains a literal that appears in the active plan, the open tool-call graph, or an unresolved branch predicate, it is binding and must be carried verbatim or ex...",
    "operational_effect": "Systems that enforce C1–C5 show a characteristic signature: post-compaction error rates stay flat relative to pre-compaction, and the dominant post-compaction failure is *explicit* (\"reference `<<res_id:1>>` not found in store\") rather than *silent* (confabulated literal → downstream 401/404 → misdiagnosed as transient → retry loop). Explicit failure is reco..."
  },
  "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": "4d526a00523af8360659f14e2e81d917dcab4e3fa26c616ad05ffec5612c22e9",
    "verified_classes": [
      "CompactionInvariantError",
      "Segment",
      "BindingStore"
    ],
    "verified_functions": [
      "compact",
      "put",
      "resolve"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "CompactionInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
