{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-compaction-triggered-tool-call-replay-from-duplicating-side-effects-in-long-horizon-agent-runs",
  "title": "Which invariants prevent compaction-triggered tool-call replay from duplicating side effects in long-horizon agent runs",
  "date_of_record": "2026 November 27",
  "scope": "Applies to long-horizon autonomous agents that persist a mutable transcript, invoke side-effecting tools, and compress history via an auto-compaction policy when token occupancy crosses a threshold. Does not apply to stateless single-turn inference or to agents whose tools are provably idempotent and side-effect-free.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-compaction-triggered-tool-call-replay-from-duplicating-side-effects-in-long-horizon-agent-runs.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-compaction-triggered-tool-call-replay-from-duplicating-side-effects-in-long-horizon-agent-runs.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-compaction-triggered-tool-call-replay-from-duplicating-side-effects-in-long-horizon-agent-runs.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1985,
    "python_slice_tokens": 287,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "Compaction is usually framed as a *memory* operation — summarize old turns, drop tokens, keep the run alive. That framing is wrong in a way that only surfaces at the boundary. Compaction is actually a **state-cut operation over an execution log**. The moment the trigger fires, the agent stops being a process that has \"seen\" every token and becomes a process ...",
    "what_was_observed": "A long-horizon run (≈140 tool calls, file mutations plus outbound API posts) was governed by a token-occupancy trigger: when the live context exceeded 82% of the model's window, a compaction routine summarized the oldest 60% of turns into a prose digest, spliced it at the head of a fresh transcript, and resumed. The digest was instructed to \"preserve decisions and pending work.\" The trace that broke: 1. Turn 71: agen...",
    "condition_of_validity": "The invariant holds — i.e., compaction is safe — only under a conjunction that most policies do not check: - **C1 (Commit log separation):** Every side-effecting tool call is recorded in a durable, transcript-independent commit log keyed by a stable action identity (tool name + normalized arguments hash + monotonic sequence). The digest may summarize the tra...",
    "decision_boundary": "The operational line is this: **a compaction trigger is safe to fire if and only if the set of committed action identities is invariant across the cut.** Token occupancy is the wrong trigger variable; it is a proxy for context pressure and says nothing about causal state. The correct gate is a predicate over the commit log: When occupancy crosses threshold b...",
    "operational_effect": "Enforcing C1–C4 changes three things in a long-horizon runtime: 1. **Trigger latency increases, throughput drops slightly.** Compaction defers to quiescent boundaries; runs with long tool chains compact less often. This is the price of not double-posting. Budget for it: a run that previously compacted at 82% will now sometimes ride to 90%+ before a safe cut,..."
  },
  "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": "a6a983496b028c35a351d556f724257ffb0c03074ed3c3f57874ac3a1d8a2019",
    "verified_classes": [
      "CompactionReplayError",
      "CommitEntry",
      "CommitLog"
    ],
    "verified_functions": [
      "assert_safe_to_compact",
      "record"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "CompactionReplayError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "hashlib",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
