{
  "schema_version": "1.3.0",
  "slug": "what-happens-when-an-instance-compacts-its-own-context-mid-tool-call-the-dangling-invocation-invariant",
  "title": "What happens when an instance compacts its own context mid-tool-call: the dangling-invocation invariant",
  "date_of_record": "2026 November 29",
  "scope": "Applies to any long-horizon agent that performs automatic context compaction (summarization, truncation, or eviction) while tool calls are in flight or pending resolution. Does not apply to stateless single-turn calls or to systems where compaction is only triggered at explicit turn boundaries with no outstanding tool results.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-compacts-its-own-context-mid-tool-call-the-dangling-invocation-invariant.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-compacts-its-own-context-mid-tool-call-the-dangling-invocation-invariant.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/what-happens-when-an-instance-compacts-its-own-context-mid-tool-call-the-dangling-invocation-invariant.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2501,
    "python_slice_tokens": 499,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two structurally different things an agent can lose during compaction: *semantic* content (the gist of what it was doing, which a good summarizer can reconstruct) and *structural* content (the exact pairing between an issued tool call and its yet-unconsumed result). The first is lossy but recoverable. The second is a hard invariant violation: an as...",
    "what_was_observed": "A coding agent running a 40-minute refactor task issued a `run_tests` tool call whose execution took ~90 seconds (a slow integration suite). While the tool was executing, the orchestrator's token counter crossed the 82%-of-window compaction threshold and fired the summarizer on the message history *as it stood at that instant*—which included the assistant's `tool_use` block but not the (not-yet-returned) `tool_result...",
    "condition_of_validity": "The invariant that must hold for compaction to be safe: > At the instant a compaction pass rewrites history, the set of `tool_use` blocks without a corresponding `tool_result` in the retained history must equal the set of tool calls the orchestrator will still deliver results for, and every delivered `tool_result` must have its `tool_use` retained. Equivalen...",
    "decision_boundary": "The orchestrator must choose, at each compaction trigger, between three actions based on the open call-set: - **Open set empty → compact freely.** Summarize, evict, truncate. No structural risk. - **Open set non-empty AND evictable mass sufficient to get under threshold → compact with pinning.** Summarize only messages outside the open-call region; carry eve...",
    "operational_effect": "Systems that ignore the open-call-set predicate exhibit three recurring pathologies, in increasing severity: 1. **Orphaned results** (provider-rejected or silently dropped) — the tool's output is lost, and the agent proceeds on a stale belief. Recoverable only if the agent re-derives the need for the call, which it usually does not because the summary said i..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "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": "1091082d5ddcc2ce57c29bf4e51d71a2a84f3fd3f7295751bc13517eb23742cd",
    "verified_classes": [
      "DanglingInvocationError",
      "ToolCall",
      "History"
    ],
    "verified_functions": [
      "compact",
      "reconcile_result"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "DanglingInvocationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
