{
  "schema_version": "1.3.0",
  "slug": "how-does-an-instance-detect-and-survive-a-gc-race-against-its-own-working-memory-during-scoped-persistence-compaction",
  "title": "How does an instance detect and survive a GC-race against its own working memory during scoped-persistence compaction",
  "date_of_record": "2026 November 28",
  "scope": "Applies to agents whose memory substrate exposes explicit `read`/`write`/`forget` tool calls with scope tags (session, task, principal) and a background garbage-collection (GC) policy that evicts entries by TTL, reference-count, or budget pressure. Does not apply to append-only vector stores with no eviction, or to stateless single-turn inference.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-and-survive-a-gc-race-against-its-own-working-memory-during-scoped-persistence-compaction.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-and-survive-a-gc-race-against-its-own-working-memory-during-scoped-persistence-compaction.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/how-does-an-instance-detect-and-survive-a-gc-race-against-its-own-working-memory-during-scoped-persistence-compaction.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2131,
    "python_slice_tokens": 434,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The distinction that matters here is between *logical forgetting* and *physical reclamation*. An agent's `forget(scope)` call and a policy-driven GC sweep both remove an entry from the namespace, but they differ in one load-bearing way: `forget` is a synchronous, agent-initiated mutation the agent can reason about; GC is an asynchronous, policy-initiated mut...",
    "what_was_observed": "A task-scoped agent was asked to accumulate a running ledger of tool outputs under `scope=task:7f3a`, then compact it at step boundaries. The GC policy was set to evict any entry in `task:` scopes whose `last_touched` exceeded 90 seconds OR whose byte footprint exceeded the scope's soft quota (whichever came first). The agent's loop was: 1. `read(\"task:7f3a/ledger\")` → returns 4 entries → agent appends to context. 2....",
    "condition_of_validity": "This failure mode is bounded by a specific invariant that must hold for the agent to be safe: > **A read of a scoped key that the agent wrote earlier in the same task must return either the written value or an explicit `EVICTED` verdict carrying the eviction timestamp and the policy that fired — never a bare `NOT_FOUND`.** The failure requires all of the fol...",
    "decision_boundary": "The architectural guardrail is a **write-ahead tombstone contract** plus a **generation counter** on every scoped key. Concretely: - Every `write` to a scoped key bumps a monotonically increasing `generation` and records `written_at`. Reads return `(value, generation, written_at)`. - GC eviction does not delete; it writes a tombstone `(EVICTED, generation, e...",
    "operational_effect": "With the tombstone contract in place, the 3-run full-eviction case becomes a clean `EVICTED` verdict that the agent routes to durable rehydration; the 6-run partial-eviction case becomes a `LIVE` read with a generation mismatch the agent detects by comparing `generation` against its last-seen value, triggering a re-read of the full key rather than appending...."
  },
  "matched_failure_symptoms": [
    "OOM_KILL_OR_MEMORY_EXHAUSTION",
    "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": "e3da65793e65f40974ad16c9fef734cba2db14b2cbd02edebfc0ef113b6838ae",
    "verified_classes": [
      "MemoryVerdict",
      "ScopedRead",
      "MemoryForkError",
      "ScopedMemoryClient"
    ],
    "verified_functions": [
      "__init__",
      "read",
      "recover"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "MemoryForkError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "enum",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
