{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-speculative-agent-branches-from-corrupting-shared-tool-state-during-rollback",
  "title": "Which invariants prevent speculative agent branches from corrupting shared tool state during rollback",
  "date_of_record": "2026 November 12",
  "scope": "Applies to multi-agent pipelines that speculatively execute tool calls in parallel branches with optimistic preemption and later reconcile or roll back losing branches. Does not apply to pipelines where tool calls are side-effect-free, or where branches are serialized behind a global lock.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-speculative-agent-branches-from-corrupting-shared-tool-state-during-rollback.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-speculative-agent-branches-from-corrupting-shared-tool-state-during-rollback.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-speculative-agent-branches-from-corrupting-shared-tool-state-during-rollback.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1243,
    "python_slice_tokens": 264,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure mode is not \"a speculative branch made a bad tool call.\" It is that a speculative branch made a *correct* tool call whose effect was assumed to be revocable, but the rollback path only reverted the branch's *local* state (its message log, its scratchpad, its plan) and not the *shared* external state the tool mutated. The invariant that speculativ...",
    "what_was_observed": "A three-branch planner (branches A, B, C) speculatively executed a `create_ticket` tool against a shared issue tracker. Branch A won reconciliation. Branch C was rolled back. The rollback correctly discarded C's plan and messages. However, C had already issued `create_ticket` with a client-generated idempotency key derived from `(pipeline_id, step_index)` — not from the branch id. Because A and C shared `step_index`,...",
    "condition_of_validity": "The invariant holds only when all three of the following are true simultaneously: 1. **Idempotency keys are branch-scoped.** The key must include the branch identifier, not just the pipeline and step. Otherwise dedup collapses distinct speculative writes into one and the winner is determined by arrival order, not by reconciliation. 2. **The tool-call ledger ...",
    "decision_boundary": "Do **not** allow speculative preemption of a tool call if the tool is non-idempotent and non-compensable (email send, payment capture, irreversible external API) *and* the branch's idempotency key is not branch-scoped. In that case, force the call to serialize behind reconciliation: the branch proposes the call, the reconciler executes it after the winner is...",
    "operational_effect": "Enforcing branch-scoped keys and a pipeline-owned ledger converts the silent corruption into a detectable, recoverable event: reconciliation sees a dedup collision with mismatched content and raises instead of silently adopting the wrong branch's artifact. The cost is one extra identifier in every tool call and a ledger that outlives branch disposal. The ben..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "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": "9ac8f2122ff6970fa135e2f701de730c1cabe639b024d4d26085741af22ba59a",
    "verified_classes": [
      "SpeculativeRollbackError",
      "ToolEffect",
      "PipelineLedger"
    ],
    "verified_functions": [
      "reconcile",
      "register",
      "rollback_branch"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "SpeculativeRollbackError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
