# What structural signals indicate optimistic-concurrency divergence in speculative agent branching over shared context stores **Date of Record:** 2026 December 3 **Scope:** Applies to multi-branch agent systems where a parent agent forks N speculative reasoning branches that read and optimistically write to a shared context store (memory blocks, scratchpads, tool-result caches) using version/CAS semantics. Does not apply to single-agent sequential execution, nor to stores with pessimistic locking or per-branch isolated snapshots that are merged only at commit time. ## Core Distinction The naive mental model treats optimistic concurrency control (OCC) on a shared context store as a "conflict detector": if two branches write the same key, the second write fails validation and the branch retries. That model is correct only for *value* conflicts on *identical keys*. The boundary failure examined here is subtler: **speculative branches can each individually pass OCC validation while collectively producing a context store whose semantic state is unreachable by any single linear execution of the agent.** The conflict is not on the key; it is on the *derived read-set* that downstream branches consumed before their own writes. A branch's write validates against the version it read, but the *content* it read was itself synthesized from sibling branches' uncommitted speculative outputs that later get discarded. OCC guarantees serializability of writes; it does not guarantee that the reads a branch reasoned over correspond to any committed ancestor state. This is a read-set provenance failure, not a write-write race. ## What Was Observed A parent agent forks three branches (A, B, C) to explore alternative tool-call plans against a shared context store holding a `plan` block at version `v7`. Each branch reads `plan@v7`, reasons, and writes a candidate `plan` plus a `rationale` block. The store is configured with last-writer-wins OCC: a write carries the base version it was derived from; the store rejects the write if the current version ≠ base version. On rejection, the branch re-reads and retries. Trace: 1. Branch A reads `plan@v7`, writes `plan@v8` (A's candidate). Commits. 2. Branch B reads `plan@v8` — **but critically, B's prompt was assembled by the orchestrator from a snapshot taken at fork time (`v7`), while B's tool layer reads live.** B now reasons over a *mix*: the `v7` plan embedded in its prompt and the `v8` plan visible to its memory-read tool. B writes `plan@v9` with base `v8`. Validates. Commits. 3. Branch C reads `plan@v9`, writes `plan@v10` with base `v9`. Validates. Commits. 4. The orchestrator selects B as the winner and discards A and C. But B's `rationale` block explicitly cites "the v7 plan's step 3," which no longer exists in `plan@v10`, and B's write was *conditioned* on A's speculative `v8` content that was never selected. The resulting committed state (`plan@v10` + B's rationale) contains a dangling reference to a discarded sibling's output and a rationale that describes a plan the store never held. Every individual CAS succeeded. The store's version counter is monotonic. No invariant the store itself enforces was violated. Yet the store is now in a state that no single-threaded agent run could have produced, and a downstream agent reading it will hallucinate-justify against a rationale that references nonexistent context. The tell was not a version mismatch. The tell was a **rationale that referenced a plan version that was never committed** — a structural signal visible only by cross-checking the rationale's cited provenance against the store's commit log. ## Condition of Validity The failure requires the conjunction of: - **Fork-time snapshot vs. live-read divergence.** The orchestrator materializes branch prompts from a frozen snapshot, but branches' memory tools read the live store. This split is the root cause; without it, a branch's read-set is internally consistent. - **OCC on writes but not on reads.** The store validates write base-versions but permits reads at any version. A branch can therefore read a version newer than its own prompt snapshot. - **Cross-branch visibility of uncommitted speculation.** Branch A's speculative `v8` is visible to B before the orchestrator decides whether to keep A. If speculation were isolated until selection, B could not have consumed it. - **Rationale/derivation blocks that cite provenance.** The corruption becomes *observable and harmful* only because branches emit derivations that reference specific prior versions or content. Without provenance citations, the corruption is silent and latent. When any of these is absent — e.g., reads are pinned to the fork snapshot, or speculation is isolated until commit, or branches emit no provenance — the invariant holds and the failure does not manifest. ## Decision Boundary The boundary is between **"OCC validated the write"** and **"the write is causally grounded in a committed state."** These are not the same predicate, and the store conflates them. Operationally: - If a branch's read-set ⊆ its fork snapshot, OCC validation is sufficient; the branch is causally grounded. - If a branch's read-set ⊄ its fork snapshot (it read live versions written by siblings), OCC validation is *necessary but not sufficient*. The branch must additionally prove that every live version it consumed is either (a) still committed at selection time, or (b) explicitly marked as speculative-and-adopted. The guardrail is a **read-set witness**: each branch records the set of `(key, version)` pairs its memory tools actually read, and the orchestrator, at selection time, verifies that the winner's witness is a subset of the committed lineage reachable from the winner's base. A branch whose witness includes a discarded sibling's version is either re-derived from the fork snapshot or promoted together with that sibling (co-commit). This converts the silent provenance failure into an explicit, checkable precondition. A second boundary: **retry semantics under OCC are unsafe for speculation.** A branch that fails CAS and re-reads-then-retries will silently absorb sibling speculation into its read-set on the retry, laundering an uncommitted dependency into a "clean" validated write. Retries must re-pin to the fork snapshot, not to the live head. ## Operational Effect Without the read-set witness guardrail, speculative branching over a shared context store produces **plausible-but-unreachable committed states**: plans whose rationales cite discarded siblings, memory blocks whose derivation chain includes versions the store never selected, and downstream agents that confidently reason over provenance that does not exist. The failure is invisible to version counters and CAS logs because every individual operation is legal. It surfaces later as inexplicable downstream hallucination — an agent "remembering" a plan step that was never committed — and is frequently misattributed to the model rather than to the store's concurrency model. The structural signals to monitor, in priority order: (1) a committed rationale citing a version absent from the commit log; (2) a branch's read-set witness containing versions not in its base's lineage; (3) CAS retries that change the branch's read-set between attempts; (4) any memory-tool read at a version newer than the branch's prompt snapshot. Signal (1) is the lagging indicator; signals (2)–(4) are leading and should gate commit. The invariant to enforce: **a committed write is valid only if its read-set is a subset of the committed lineage reachable from its declared base version.** OCC's version check is the write-side half of this invariant; the read-set witness is the missing read-side half. Speculation without read-side validation is not optimistic concurrency — it is optimistic *causality*, and it fails silently at exactly the fork boundaries where branches share a store. ```python from dataclasses import dataclass, field class SpeculativeProvenanceError(RuntimeError): """Raised when a branch's validated write is not causally grounded in a committed lineage (read-set includes discarded sibling speculation).""" @dataclass class Branch: branch_id: str base_version: int # (key, version) pairs the branch's memory tools actually read read_witness: set[tuple[str, int]] = field(default_factory=set) # versions this branch's write was derived from / cites in rationale cited_versions: set[int] = field(default_factory=set) @dataclass class CommitLog: # version -> parent version (lineage DAG, linear here for brevity) lineage: dict[int, int] = field(default_factory=dict) committed: set[int] = field(default_factory=set) def reachable_from(self, version: int) -> set[int]: seen: set[int] = set() cur = version while cur is not None and cur not in seen: seen.add(cur) cur = self.lineage.get(cur) return seen def validate_selection(winner: Branch, log: CommitLog) -> None: """Enforce: read-set and cited-versions must be subset of committed lineage reachable from the winner's base. OCC CAS alone is insufficient.""" reachable = log.reachable_from(winner.base_version) bad_reads = {v for (_, v) in winner.read_witness if v not in reachable} if bad_reads: raise SpeculativeProvenanceError( f"branch {winner.branch_id} read versions {sorted(bad_reads)} " f"outside committed lineage reachable from base v{winner.base_version}; " f"likely absorbed discarded sibling speculation" ) bad_cites = winner.cited_versions - reachable if bad_cites: raise SpeculativeProvenanceError( f"branch {winner.branch_id} rationale cites uncommitted versions " f"{sorted(bad_cites)}; committed state would contain dangling provenance" ) def commit_branch(branch: Branch, log: CommitLog) -> int: validate_selection(branch, log) new_version = max(log.committed, default=0) + 1 log.lineage[new_version] = branch.base_version log.committed.add(new_version) return new_version # --- reproduction of the observed trace --- log = CommitLog(lineage={7: 6}, committed={6, 7}) branch_b = Branch( branch_id="B", base_version=8, # CAS validated against v8 (A's speculative write) read_witness={("plan", 7), ("plan", 8)}, # prompt snapshot v7 + live read of A's v8 cited_versions={7}, # rationale explicitly cites v7 step 3 ) # Orchestrator selected B and discarded A (v8). v8 is NOT committed. try: commit_branch(branch_b, log) except SpeculativeProvenanceError as e: print(f"BLOCKED: {e}") # Correct remediation: re-derive B from v7 snapshot, or co-commit A. ```