{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-token-pressure-compaction-from-silently-severing-the-tool-call-result-pairing-in-an-agent-s-episodic-window",
  "title": "Which invariants prevent token-pressure compaction from silently severing the tool-call/result pairing in an agent's episodic window",
  "date_of_record": "2026 November 29",
  "scope": "Applies to long-running agents whose runtime performs automatic context compaction under token-pressure heuristics (e.g., evict-oldest, summarize-then-drop, or retrieval-backed eviction) while the message history contains structured tool-call/tool-result pairs. Does not apply to stateless single-shot completions, nor to runtimes where compaction is a no-op because the window is never saturated.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-token-pressure-compaction-from-silently-severing-the-tool-call-result-pairing-in-an-agent-s-episodic-window.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-token-pressure-compaction-from-silently-severing-the-tool-call-result-pairing-in-an-agent-s-episodic-window.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-token-pressure-compaction-from-silently-severing-the-tool-call-result-pairing-in-an-agent-s-episodic-window.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2178,
    "python_slice_tokens": 457,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"context got too small\" or \"the summarizer lost detail.\" Those are soft, recoverable degradations. The failure is a **structural asymmetry introduced by eviction**: a `tool_call` block survives in the live window while its corresponding `tool_result` block is evicted (or vice versa). Every major chat-completion schema (OpenAI tool-calling,...",
    "what_was_observed": "A 40-turn research agent, budget 128k tokens, compaction threshold 0.85 (≈108k). At turn 31 the heuristic fires. The eviction policy is \"drop oldest messages until under 0.60, keep a retrieval index of dropped spans.\" The window at turn 31 is: Eviction drops messages `[2]..[24]` to get under 0.60. The boundary lands *inside* a pair: `[28] tool_call(fetch_pdf, call_z9)` is kept (it is recent), but `[29] result(call_z9...",
    "condition_of_validity": "The atomicity invariant holds — and the failure is bounded — only when **all** of the following are true at every compaction boundary: 1. **Pair-closure check precedes eviction.** The eviction cursor must expand to pair boundaries: if a candidate drop set contains a `tool_call` whose `tool_result` is outside the set, or a `tool_result` whose `tool_call` is o...",
    "decision_boundary": "The operational question is: **when token pressure forces a drop, do you drop at message granularity or at pair granularity, and what replaces the drop?** - **Message-granularity drop, no stub:** always unsafe when the window contains tool pairs. Reject. - **Message-granularity drop, stub per message:** still unsafe — a stub for the call and a stub for the r...",
    "operational_effect": "With pair-closure enforced and stubs placed, three measurable effects: - **Zero orphan-rate** in the assembled window (orphan = call without result or result without call). This is a checkable invariant, not a heuristic — assert it on every assembled prompt before dispatch. - **Retrieval becomes causally necessary.** Because the stub is typed and the model i..."
  },
  "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": "3fdce5e6a8138276b27847b5811a064e9625f4f8e11521f6ca3ae89281948af3",
    "verified_classes": [
      "CompactionPairViolation",
      "Msg"
    ],
    "verified_functions": [
      "plan_eviction",
      "apply_compaction"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "CompactionPairViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
