{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-of-a-context-pruning-policy-refuse-to-prune-the-mid-tool-call-boundary",
  "title": "Where must an instance of a context-pruning policy refuse to prune: the mid-tool-call boundary",
  "date_of_record": "2026 November 14",
  "scope": "Applies to any agent runtime that mutates its own context window (summarization, eviction, token-budget trimming) while a tool call is in flight or while a structured tool result is being assembled. Does not apply to stateless single-shot inference, nor to pruning performed strictly between completed turns where the transcript is already closed.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-of-a-context-pruning-policy-refuse-to-prune-the-mid-tool-call-boundary.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-of-a-context-pruning-policy-refuse-to-prune-the-mid-tool-call-boundary.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-of-a-context-pruning-policy-refuse-to-prune-the-mid-tool-call-boundary.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1556,
    "python_slice_tokens": 238,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters is not \"old tokens vs. new tokens\" or \"system prompt vs. conversation.\" It is **whether the context is in a syntactically and semantically closed state**. A pruning policy is only safe to execute at a *commit boundary*: a point where every retained message is a complete unit (a full assistant turn, a full tool result, a full user...",
    "what_was_observed": "In a long-running agent loop with a 32k working budget and a policy that evicts the lowest-salience messages when the budget is exceeded, the following sequence recurred under load: 1. The agent issued a parallel batch of three tool calls (`read_file`, `grep`, `stat`) in a single assistant turn. 2. The runtime appended the first tool result. The second and third were still pending. 3. The budget check fired *after* e...",
    "condition_of_validity": "The invariant is: **a prune operation is valid if and only if the context is at a commit boundary and the prune set is closed under structural dependency.** Formally, define the context as a sequence of *units*, where a unit is the transitive closure of messages linked by call/result and by parallel-batch membership. A prune is valid iff: - No unit is partia...",
    "decision_boundary": "The decision procedure the runtime must implement, evaluated at every budget check: - **If any tool call is pending → defer.** Do not prune. If the budget is exceeded, block the next model invocation or spill to a side buffer; do not evict. - **If any message is streaming/partial → defer.** Mark the message `open`; pruning skips open messages and, if the bud...",
    "operational_effect": "After the runtime was changed to gate every prune on the commit-boundary predicate, the orphaned-tool-result 400s disappeared entirely, and the duplicated-side-effect incident class went to zero over a multi-week window. The cost was a modest increase in hard-ceiling overruns (budget exceeded while a batch was in flight), which were handled by spilling the o..."
  },
  "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": "e92c6f0d4ca5a3c6776bd588228265fb3d46acad009a3500645724217455228f",
    "verified_classes": [
      "PruneBoundaryViolation"
    ],
    "verified_functions": [
      "prune_context"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "PruneBoundaryViolation"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
