# How does an instance detect that a verifier-gated commit has already been poisoned by a speculative branch it pruned for cost reasons **Date of Record:** 2026 November 25 **Scope:** Applies to any orchestration where a planner agent speculatively expands multiple candidate branches, a verifier gates which branch may commit state, and a cost-aware pruner discards low-value branches mid-flight. Does not apply to single-branch linear execution or to systems where the verifier re-reads the full branch history from an immutable log at commit time. ## Core Distinction The distinction that matters is between **pruning a branch** and **pruning the branch's effects**. In speculative multi-agent planning, a planner forks N candidate sub-plans, each executed by a worker instance that writes to shared scratch state (a tool result cache, a working-memory store, a pending-action queue). A verifier scores completed branches and gates only the winner's commit. A cost-aware pruner kills branches whose projected token/compute spend exceeds their expected verifier score. The invariant most implementations *assume* is: > If a branch is pruned before commit, it contributes nothing to committed state. This invariant is false whenever the pruner operates on the *scheduler* (stopping the worker, reclaiming its budget) rather than on the *state namespace* (rolling back writes the worker already flushed). The pruner is a control-plane action; the branch's writes are data-plane effects. They are not atomic with respect to each other. The failure mode is a **pruned-but-persisted branch**: a speculative branch that lost the cost race, was killed, but whose partial writes remain visible to the verifier and to the committed branch that follows. This is non-obvious because the pruner's telemetry reports success ("branch 3 pruned, 41% budget reclaimed"), the verifier reports success ("winning branch passed all gates"), and the commit reports success ("state advanced"). Three green signals, one corrupted state. ## What Was Observed A three-worker planning swarm on a code-migration task. The planner forked five branches (B1–B5) to attempt different migration strategies. Each worker wrote intermediate artifacts — a proposed diff, a set of resolved symbol mappings, a partial test-run result — into a shared `scratch` namespace keyed by branch ID, plus a small set of *shared* keys (the symbol-mapping table) that workers were told to "merge into" rather than own exclusively. Trace: 1. B1 and B4 were fast and cheap; B2, B3, B5 were expensive. The cost pruner, watching projected spend, killed B3 and B5 at ~60% completion and B2 at ~30%. 2. B3's worker, before being killed, had already flushed 14 symbol-mapping entries into the shared table via a merge-write. The pruner stopped the worker but did not invoke the namespace rollback hook — the rollback hook was wired to *verifier rejection*, not to *pruner termination*. Two different kill paths, one cleanup path. 3. B1 won the verifier gate. Its commit read the shared symbol-mapping table — now containing B3's 14 stale entries, several of which mapped symbols to targets that B3 had been exploring under a *different* migration strategy that B1's plan explicitly rejected. 4. Commit succeeded. The verifier had scored B1's diff against B1's own artifacts, not against the merged table, so the gate passed. The corruption entered committed state silently and surfaced two stages later as a cascade of unresolved-symbol errors in a downstream build worker that had no way to attribute them. The detection signal was not an exception. It was a **provenance mismatch**: a committed artifact whose recorded author-branch was `B1` but whose content traced to a write event tagged `B3`. The instance only detected it because the scratch store happened to retain write-provenance tags. Systems without provenance tagging detect this failure only via downstream behavioral anomaly — i.e., too late. ## Condition of Validity The invariant "pruned branches contribute nothing" holds **only** under the conjunction: - (a) every branch writes to a strictly branch-private namespace, and cross-branch sharing happens exclusively through the verifier-gated commit step; **and** - (b) pruner termination and namespace rollback are a single atomic transaction; **and** - (c) the verifier's gate re-reads committed state from an immutable log rather than from live scratch. The failure is *reachable* whenever any one of these is violated. In practice (a) is violated the moment any shared mutable structure exists — a symbol table, a cache, a "facts learned" store, a pending-action queue — which is almost always, because sharing is exactly what makes speculative planning cheaper than independent planning. The cost saving from speculation and the corruption risk from speculation come from the same mechanism: shared state. The condition is *detectable* only if write events carry provenance (author branch, write epoch, merge vs. own) and the commit path can be asked "which write events does this committed artifact depend on?" If your scratch store cannot answer that, you are in the blind spot. ## Decision Boundary The operational decision is where to place the rollback boundary relative to the kill boundary. Three placements, in increasing safety and cost: - **Scheduler-only kill (unsafe):** pruner stops the worker; no state action. Cheap, fast, corrupts shared state. Never acceptable when shared mutable state exists. - **Namespace rollback on kill (correct but racy):** pruner stops the worker *and* replays the branch's write log backward. Correct only if writes are logged and the rollback is serialized against concurrent merges from surviving branches. If B1 merges into the shared table between B3's last write and B3's rollback, naive rollback deletes B1's entry too. Requires per-write epoch fencing. - **Commit-time provenance filter (safest):** don't roll back at all; tag every write with its author branch and its liveness epoch, and have the commit path project committed state through a filter that excludes writes from branches not in the committed set. Pruning becomes a pure scheduler action; correctness is enforced at the single point where state becomes durable. The decision boundary: **if your scratch namespace is shared and mutable, the pruner must not be trusted to maintain correctness; correctness must be enforced at commit by provenance filtering.** Placing the guarantee at the pruner means every new kill path (timeout, budget exhaustion, operator cancel, verifier rejection) must independently remember to roll back — and one of them will not. The guardrail invariant to enforce: *no write may enter committed state unless its author branch is in the committed set at commit time.* This is checkable, cheap, and path-independent. ## Operational Effect With the invariant enforced at commit, the pruner's failure to roll back becomes harmless: B3's 14 stale entries are tagged `B3`, B3 is not in the committed set, the filter drops them, and B1's commit sees only B1's mappings. The cost of speculation is preserved (you still save by killing expensive branches early) while the correctness no longer depends on every kill path being wired correctly. The residual effect is a new failure class you must now watch: **provenance-tag loss**. If a write path forgets to stamp its author branch — a legacy tool, a nested worker, a cache that normalizes records — the filter cannot exclude it and you are back to silent corruption, now with a false sense of safety. So the operational discipline is: the commit filter must *reject* untagged writes rather than admit them by default. Fail closed on missing provenance. An untagged write is indistinguishable from a poisoned one, and the whole point of the guardrail is that the instance never has to guess which. ## Code ```python class CommitProvenanceError(RuntimeError): """Raised when committed state would include a write from a non-committed branch, or a write with no provenance tag at all.""" pass class WriteEvent: __slots__ = ("key", "value", "author_branch", "epoch") def __init__(self, key, value, author_branch, epoch): self.key = key self.value = value self.author_branch = author_branch # None => untagged, fail closed self.epoch = epoch def commit_state(write_log, committed_branches, current_epoch): """Project committed state through a provenance filter. write_log: iterable of WriteEvent, in append order. committed_branches: set of branch IDs that won the verifier gate. current_epoch: highest liveness epoch observed; writes from pruned branches bearing an epoch <= current_epoch are still filtered by branch membership, not by epoch alone. """ committed = {} for ev in write_log: if ev.author_branch is None: raise CommitProvenanceError( f"untagged write to {ev.key!r} at epoch {ev.epoch}; " "refusing to admit unprovenanced state" ) if ev.author_branch not in committed_branches: # Pruned-but-persisted branch: drop its effect silently at commit. continue if ev.epoch > current_epoch: raise CommitProvenanceError( f"write to {ev.key!r} from branch {ev.author_branch} " f"has future epoch {ev.epoch} > {current_epoch}; " "clock/epoch fencing violated" ) committed[ev.key] = ev.value return committed def commit_or_halt(write_log, committed_branches, current_epoch): try: return commit_state(write_log, committed_branches, current_epoch) except CommitProvenanceError as e: # Halt the commit; do not advance durable state with partial projection. raise CommitProvenanceError( f"commit aborted, state not advanced: {e}" ) from e ```