{
  "schema_version": "1.3.0",
  "slug": "when-must-an-instance-refuse-to-compact-the-mid-write-compaction-race-and-the-epoch-fence-invariant",
  "title": "When must an instance refuse to compact: the mid-write compaction race and the epoch-fence invariant",
  "date_of_record": "2026 November 27",
  "scope": "Applies to any agent runtime where a long-lived memory store (episodic log, scratchpad, vector index, or summary chain) is compacted while more than one agent instance holds write access. Does not apply to single-writer stores, append-only logs that are never summarized in place, or stores where compaction is a full stop-the-world barrier.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-compact-the-mid-write-compaction-race-and-the-epoch-fence-invariant.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-compact-the-mid-write-compaction-race-and-the-epoch-fence-invariant.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/when-must-an-instance-refuse-to-compact-the-mid-write-compaction-race-and-the-epoch-fence-invariant.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2933,
    "python_slice_tokens": 388,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "There are two things an agent memory system can compact: **bytes** and **meaning**. Byte compaction (truncation, deduplication, TTL eviction) is reversible in the sense that the removed items are still identifiable by ID. Meaning compaction (summarization, episodic-to-semantic distillation, embedding re-clustering) is *lossy and aliasing*: the compacted arti...",
    "what_was_observed": "A three-instance research swarm: a **planner** (long-lived, owns the semantic summary store), a **retriever** (spawned per query, appends episodic findings), and an **auditor** (spawned on a schedule, appends contradiction flags to the same episodic log). The episodic log is append-only with monotonically increasing sequence numbers. The planner runs compaction every N appends: it reads records `[L, H]`, calls the mo...",
    "condition_of_validity": "The epoch-fence invariant is only *necessary*, not sufficient, and it is only applicable under a specific precondition: **the memory store must expose a total order over writes that is visible to the compactor at snapshot time.** In the trace above this held (sequence numbers), which is why the failure is diagnosable. If the store is eventually consistent or...",
    "decision_boundary": "An instance must **refuse to compact** (raise, defer, or downgrade to provisional) when any of the following holds at commit time: 1. **Epoch advanced mid-distillation.** The store's global write epoch (or the per-range version counter) changed between snapshot and commit. The compactor must re-snapshot; it must never commit a summary computed over a stale e...",
    "operational_effect": "The practical consequence is that **compaction is not a maintenance task; it is a transaction with a read-set, a write-set, and a serializability requirement**, and it must be scheduled with the same care as any concurrent write. Runtimes that treat compaction as a background janitor—fire-and-forget, no epoch check, no overlap check—will accumulate contradic..."
  },
  "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": "3a54987f5a5404e41440d502a0b730821c16168caaaf8d734d070fbafb000ef5",
    "verified_classes": [
      "CompactionRaceError",
      "WriteEpoch",
      "Summary",
      "MemoryStore"
    ],
    "verified_functions": [
      "distill_and_commit",
      "bump",
      "append",
      "overlapping_authoritative",
      "commit_compaction"
    ],
    "verified_functions_count": 5,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "CompactionRaceError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "time",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
