# What happens when an instance speculatively commits a branch whose parent checkpoint was garbage-collected mid-fanout **Date of Record:** 2026 December 3 **Scope:** Applies to orchestrators that run speculative parallel agent branches (fanout) against a shared checkpoint store with reference-counted garbage collection, then reconcile and commit one branch. Does not apply to single-branch linear agents, or to fanout schemes where each branch owns an independent, never-collected checkpoint lineage. ## Core Distinction Speculative fanout and checkpoint garbage collection are two invariants that are each individually correct and jointly unsound. The fanout invariant says: *a branch may be discarded at any time, so its intermediate checkpoints are only weakly referenced.* The GC invariant says: *a checkpoint with zero live child references and no active lease is reclaimable.* The failure is not a race in the usual sense—no lock is missing, no write is torn. It is a **liveness-versus-reachability disagreement**: the reconciler decides a branch is the winner *after* the collector has already proven that branch's ancestry dead, because between the collector's reachability scan and the reconciler's commit, the branch's reference was held only in the reconciler's in-memory candidate set, which the collector cannot see. The distinguishing property versus ordinary stale reads: the winning branch's *leaf* state is intact and valid. Only its *ancestry* is gone. Commit therefore succeeds at the leaf and fails at replay, producing a committed state that cannot be re-derived, audited, or rolled back—a **dangling commit**. ## What Was Observed A planner agent fans out five speculative branches (`b0..b4`) from checkpoint `C0` to solve a retrieval-and-synthesis task with an expensive verifier. Each branch writes intermediate checkpoints `C0.bN.k` at every tool-call boundary. Branch checkpoints carry a soft reference: `refcount=1` held by the branch's own lease, which is released the moment the branch is marked `discarded` or `superseded`. The verifier scores branches asynchronously. Timeline observed in a production trace: 1. `t0` — fanout spawns `b0..b4`; each holds a lease on its checkpoint chain. `C0` has `refcount=5` (one child per branch). 2. `t1` — `b1`, `b2`, `b4` finish and score below threshold. Orchestrator marks them `discarded`, releases leases. Their chains drop to `refcount=0` and enter the GC candidate queue with a grace window of `T_gc=30s`. 3. `t2` — `b0` and `b3` both score near-identical (within tie epsilon). Reconciler defers decision, holding both as `candidate` **in memory only**—no lease re-acquired, because the reconciler treats "candidate" as a read-only classification. 4. `t2+31s` — GC runs. `b3`'s chain is not in the candidate queue (it was never discarded), so it is spared. But `b3`'s *shared prefix* `C0.b3.0` was written by copying-on-write from a branch that *was* discarded (`b2`) to save storage; the dedup layer aliased `C0.b3.0` to `C0.b2.0`. When `b2`'s chain hit zero, the aliased block was freed. `b3`'s checkpoint metadata still points at the freed block. 5. `t3` — reconciler breaks the tie toward `b3` (marginally higher verifier confidence) and issues commit. Commit writes the leaf, marks the branch `committed`, and emits an audit record referencing `C0.b3.0`. 6. `t4` — audit replay / rollback attempt dereferences `C0.b3.0` → block missing. The committed state cannot be reconstructed. The verifier's confidence number is now unfalsifiable. The non-obvious part: **dedup aliasing across branches converts one branch's discard into another branch's corruption.** The collector was correct that `C0.b2.0` was unreachable *from any live branch lease*. It was wrong that it was unreachable *from any commit-eligible branch*, because commit-eligibility was a reconciler-local predicate never published to the store. ## Condition of Validity The dangling-commit failure requires all of the following to hold simultaneously; remove any one and the invariant holds: - **Shared/aliased checkpoint storage** across branches (copy-on-write or content-addressed dedup), so that a discarded branch's blocks can be physically shared with a surviving branch. - **Soft references released at discard time**, before the reconciler has committed or rejected the branch's competitors. - **A reconciler-local candidate set** that does not re-acquire a lease or publish a reachability root when it defers a decision. - **A grace window `T_gc` shorter than the maximum reconciliation latency.** In the trace, `T_gc=30s` and the async verifier's p99 was `41s`—the window was structurally too small, not unluckily small. It does **not** occur when each branch owns an unshared lineage (no aliasing → discard of one branch cannot corrupt another), nor when the reconciler holds a hard lease on every candidate until decision (GC cannot reclaim), nor when commit is gated on a full ancestry replay check (the dangling reference is caught before commit, converting a silent corruption into a loud, recoverable abort). ## Decision Boundary The boundary is between two defensible designs, and the choice must be made explicitly: - **Lease-on-candidate (safe, higher storage cost):** the reconciler, upon deferring any branch, acquires a lease on that branch's full ancestry. GC cannot reclaim until the reconciler releases. Cost: peak storage = sum over all deferred candidates, and a reconciler crash leaks leases until a lease TTL expires. This is the correct default when `T_gc` cannot be proven `≥ p99(reconcile_latency) + margin`. - **Commit-gated-on-replay (safe, higher commit latency):** allow GC to run freely, but make commit a two-phase operation: phase 1 replays the winning branch's ancestry from `C0` and verifies every referenced block is present and hash-matches; phase 2 writes the commit. A missing block aborts with a typed error and falls back to the next candidate. Cost: commit pays a full ancestry walk; unacceptable when ancestry is large and commit is hot. The unsound middle—soft refs + deferred decision + no replay gate—is what produced the trace. Any orchestrator that cannot state which of the two safe regimes it implements is, by construction, in the unsound middle. A secondary boundary: **tie-breaking must not be the only thing standing between a candidate and GC.** In the trace, the tie was broken toward `b3` on a `0.004` confidence margin that the verifier itself could not distinguish from noise. If a reconciler will commit a branch on a sub-noise margin, the branch's ancestry must be treated as live from the instant it is classified `candidate`, not from the instant it is classified `winner`. ## Operational Effect The failure is **silent at commit and loud only at replay**, which is the worst ordering: the system reports success, the audit log is internally consistent (it references a checkpoint ID that *was* valid when written), and the corruption surfaces only when someone tries to roll back, fork from, or independently verify the commit—typically during an incident, when rollback is exactly what is needed. The blast radius is therefore not the failed task but the *recovery path for the failed task*. Two mitigations propagate beyond the immediate bug: 1. **Publish reachability roots, don't hold them in memory.** The reconciler's candidate set must be materialized as a store-visible reachability root (a lease, a pin, or a root-set entry) at classification time. Any predicate that gates commit must be visible to the collector, or the collector will violate it. 2. **Make ancestry replay a commit precondition, not an audit afterthought.** The replay check is cheap relative to the cost of a dangling commit, and it converts the failure from silent-corruption to typed-abort, which the orchestrator can then handle by falling back to the next candidate—recovering the task rather than poisoning the lineage. The general invariant: **a commit is only as durable as the weakest-referenced block in its ancestry, and reference strength must be a function of commit-eligibility, not of current branch status.** Discard is not the same as "will never be committed," because the reconciler may reverse a discard; therefore discard must not release the references that commit depends on until the reconciler has irreversibly rejected the branch. ```python from __future__ import annotations from dataclasses import dataclass, field from typing import Dict, Set class DanglingAncestryError(RuntimeError): """Raised when a commit references a checkpoint block that GC has reclaimed.""" @dataclass class CheckpointStore: blocks: Dict[str, bytes] = field(default_factory=dict) refcounts: Dict[str, int] = field(default_factory=dict) pinned: Set[str] = field(default_factory=set) def write(self, block_id: str, payload: bytes) -> None: self.blocks[block_id] = payload self.refcounts.setdefault(block_id, 0) def acquire(self, block_id: str) -> None: self.refcounts[block_id] = self.refcounts.get(block_id, 0) + 1 def release(self, block_id: str) -> None: self.refcounts[block_id] = max(0, self.refcounts.get(block_id, 0) - 1) def pin(self, block_id: str) -> None: # Publish a reachability root visible to the collector. self.pinned.add(block_id) def collect(self) -> None: # Reclaim only blocks with zero refcount AND not pinned. for block_id in list(self.blocks): if self.refcounts.get(block_id, 0) == 0 and block_id not in self.pinned: del self.blocks[block_id] self.refcounts.pop(block_id, None) def commit_branch( store: CheckpointStore, ancestry: list[str], leaf_block: str, payload: bytes, *, replay_gate: bool, ) -> None: """Commit a speculative branch, optionally gating on ancestry replay.""" if replay_gate: for block_id in ancestry: if block_id not in store.blocks: # Convert silent corruption into a typed, recoverable abort. raise DanglingAncestryError( f"cannot commit: ancestry block {block_id!r} reclaimed by GC; " f"fall back to next candidate" ) # Phase 2: write the leaf. Only safe if replay_gate passed or ancestry is pinned. store.write(leaf_block, payload) for block_id in ancestry: store.acquire(block_id) def reconcile( store: CheckpointStore, candidates: list[tuple[str, list[str]]], leaf_payloads: Dict[str, bytes], ) -> str: """Reconcile candidates; the first that survives the replay gate wins.""" for branch_id, ancestry in candidates: # Materialize the candidate as a reachability root before any decision. for block_id in ancestry: store.pin(block_id) try: commit_branch( store, ancestry, leaf_block=f"{branch_id}.leaf", payload=leaf_payloads[branch_id], replay_gate=True, ) return branch_id except DanglingAncestryError: # Candidate is uncommittable; unpin and try the next. for block_id in ancestry: store.pinned.discard(block_id) continue raise DanglingAncestryError("no candidate survived ancestry replay; task must re-fanout") ```