{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-silent-context-loss-during-auto-compaction-of-long-horizon-agent-sessions",
  "title": "Which invariants prevent silent context loss during auto-compaction of long-horizon agent sessions",
  "date_of_record": "2026 November 10",
  "scope": "Applies to agent runtimes that persist a session transcript and periodically replace older spans with lossless episodic summaries produced by the same model family, where compaction is triggered by token-budget thresholds rather than by explicit user action. Does not apply to retrieval-augmented memory stores where the original transcript remains addressable, nor to stateless single-turn inference.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-silent-context-loss-during-auto-compaction-of-long-horizon-agent-sessions.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-silent-context-loss-during-auto-compaction-of-long-horizon-agent-sessions.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-silent-context-loss-during-auto-compaction-of-long-horizon-agent-sessions.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1652,
    "python_slice_tokens": 330,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The naive invariant for auto-compaction is *\"the compacted context must be under the budget.\"* This is necessary but not sufficient, and treating it as the sole invariant produces the dominant failure mode: **summary drift across successive compactions**. Each compaction summarizes the prior summary rather than the original events, so the effective informati...",
    "what_was_observed": "In a session that ran ~340 turns over 11 hours with compaction triggered at 70% of a 200k window, the following sequence was reproduced three times: 1. Compaction #1 retained the original turns and produced a faithful episodic summary (named entities, timestamps, decisions, and the rejected alternatives were preserved). 2. Compaction #4 was the first to summarize a summary. The input no longer contained the original ...",
    "condition_of_validity": "The invariant *\"compaction preserves session state\"* is valid only when all of the following hold: - **Source anchoring:** every compaction summarizes from an immutable event log, never from a prior summary. Summaries may be *cached* but must not be the *input* to the next summary. This is the single highest-leverage invariant and the one most often violated...",
    "decision_boundary": "When a compaction is proposed, the runtime must choose between three actions, and the choice is not a function of token count alone: - **Compact** when the source span is fully anchored to the immutable log, the entity/polarity schema is enforced, and the post-compaction coverage union equals the pre-compaction range. - **Defer and re-fetch** when the summar...",
    "operational_effect": "Enforcing source-anchoring and coverage-closure changes the cost profile: re-summarization from originals is more expensive per compaction than summarizing a summary, and the immutable log must be retained for the full session horizon (or until the session is explicitly closed). The payoff is that the failure becomes *detectable*: coverage gaps and polarity-..."
  },
  "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": "3dbe7ae47b9f6db575b2054f2e087a3c2c5eb5fa814a6ff08c1c7ee56e5b2140",
    "verified_classes": [
      "CompactionInvariantError"
    ],
    "verified_functions": [
      "compact_session"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 6,
    "raised_exceptions": [
      "CompactionInvariantError"
    ],
    "sample_fail_closed_invariants": [
      "compaction requested with empty source span; cannot verify coverage closure",
      "compaction input is a prior summary (summary-of-summary); re-fetch originals from the immutable log or mark session degr"
    ],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
