# Under what conditions must an instance refuse a supervisor's re-dispatch after a partial batch failure **Date of Record:** 2026 November 20 **Scope:** Applies to supervisor/orchestrator topologies where a supervisor fans a batch of subtasks to worker instances and re-dispatches failed items after a partial failure. Does not apply to single-agent loops, pure peer swarms without a reconciling supervisor, or stateless idempotent tool calls with no persistent side effects. ## Core Distinction A supervisor that observes a batch failure has two superficially identical recovery moves: **retry the failed subset** and **re-dispatch the whole batch**. These are not equivalent, and the difference is not about efficiency. The distinction that matters is whether the worker instances hold *side-effect state* that the supervisor cannot observe. A supervisor's view of a batch is a vector of per-item terminal statuses: `{ok, fail, fail, ok}`. That vector is a **lossy projection** of what actually happened. A worker that returned `fail` may have failed *before* its side effect, *during* it, or *after* it but before acknowledging. The supervisor cannot distinguish these from the status alone. Re-dispatching the failed subset assumes the failure was pre-effect; re-dispatching the whole batch assumes nothing persisted. Both assumptions are unverified, and one of them is usually wrong. The invariant: **a supervisor may only re-dispatch items whose failure was proven to occur before any non-idempotent effect.** Absent that proof, the correct move is to quarantine and escalate, not to retry. An instance that receives a re-dispatch order for an item it cannot prove was effect-free must refuse the order. ## What Was Observed A three-worker supervisor topology processing a 40-item batch of document mutations (each item = read source, transform, write to a versioned store, emit an audit record). The supervisor dispatched items round-robin, collected terminal statuses with a 30s per-item timeout, and on partial failure re-dispatched the failed subset to the same workers. Item 17 timed out at the supervisor's 30s boundary. The worker had in fact completed the write to the versioned store at t=28s and was mid-audit-emit at t=31s when the supervisor's timeout fired. The worker's transport layer had already sent a `fail:timeout` frame; the supervisor never saw the later audit-emit completion because the worker's response channel had been closed by the timeout handler. The supervisor re-dispatched item 17 to the same worker. The worker, on a fresh dispatch, had no memory of the prior attempt (its per-item context was scoped to the dispatch). It re-read the source, re-transformed, and wrote a **second version** to the store. The store was append-only versioned, so this did not corrupt data — it created a duplicate version with an identical payload but a new version ID. The audit log then contained two emits for one logical item, and downstream reconciliation treated them as two distinct mutations. The failure was not the timeout. The failure was that the supervisor treated `fail:timeout` as evidence of pre-effect failure, and the worker accepted a re-dispatch without checking whether a prior attempt for that item ID had already committed. A second variant was worse: a worker that had committed the write and *then* crashed mid-audit-emit was re-dispatched, re-ran, and the second run's audit emit referenced the first run's version ID (read from the store) while the first run's audit emit had never landed. The audit trail now claimed a mutation that the audit log could not corroborate by sequence. ## Condition of Validity The re-dispatch-is-safe assumption holds only under a conjunction that is rarely all true: 1. **Effect idempotency by item ID.** The downstream store must deduplicate on a stable logical item ID that survives worker restarts and re-dispatches. Versioned append-only stores do *not* satisfy this unless the version key is derived from the item ID, not from a per-attempt nonce. 2. **Pre-effect failure proof.** The worker's terminal status must distinguish `fail:pre-effect` from `fail:post-effect` and `fail:unknown-effect`. A bare `fail` or `fail:timeout` carries no such proof. 3. **Attempt ledger visibility.** The supervisor (or a shared ledger the worker consults) must record attempt IDs per item, so a re-dispatch can be checked against prior attempts before execution. 4. **Worker-side attempt memory.** The worker must, on receiving a dispatch for item ID X, check the ledger for prior attempts on X and either resume, dedupe, or refuse — not blindly re-execute. If any of 1–4 is absent, the supervisor's re-dispatch is an unverified assumption, and the worker's acceptance of it is a continuity violation. The condition of validity for accepting a re-dispatch is therefore: **the worker can prove, from a ledger it does not solely control, that no prior attempt for this item ID reached a non-idempotent effect.** ## Decision Boundary The boundary is drawn at the worker's dispatch-acceptance step, not at the supervisor's retry step. The supervisor will always be tempted to retry — it has a failed status and a queue. The worker is the last line of defense because it is the only party that can consult the attempt ledger and the effect store before executing. The worker's decision procedure on receiving a dispatch for item ID X: - **Ledger shows no prior attempt on X.** Accept. Execute. Record attempt with a fresh attempt ID before the first non-idempotent effect. - **Ledger shows a prior attempt on X that terminated `pre-effect`.** Accept as a retry. Reuse or supersede the attempt ID per ledger policy. - **Ledger shows a prior attempt on X that terminated `post-effect` or `unknown-effect`.** **Refuse.** Raise a continuity error to the supervisor. The supervisor must escalate to reconciliation, not re-dispatch. - **Ledger is unreachable.** Refuse. An unreachable ledger is indistinguishable from a ledger that would have shown a prior attempt. Fail closed. The last rule is the non-obvious one. A worker that accepts a re-dispatch because it "can't check right now" has converted a ledger outage into a duplicate-effect incident. The correct behavior under ledger unavailability is refusal, because the cost of a false refusal (one item delayed) is bounded and the cost of a false acceptance (duplicate effect, audit divergence) is unbounded and often silent. ## Operational Effect Enforcing worker-side refusal changes the supervisor's failure semantics. The supervisor can no longer treat a partial batch failure as "retry the failed subset." It must treat it as "quarantine the failed subset, reconcile against the ledger, then re-dispatch only items proven pre-effect." This adds a reconciliation step to the recovery path and makes the supervisor's retry logic dependent on ledger state it previously ignored. The compensating benefit is that the failure mode becomes visible. A refused re-dispatch surfaces as an explicit continuity error at the supervisor, which can be routed to reconciliation. The duplicate-version incident described above would have surfaced as a refusal on the first re-dispatch of item 17, prompting a ledger check that revealed the post-timeout commit. The audit divergence would never have occurred. The invariant to encode: **no worker executes a non-idempotent effect for an item ID without first recording an attempt and confirming no prior attempt reached effect.** The supervisor's re-dispatch is a request, not an authorization. The worker's ledger check is the authorization. ```python import time from dataclasses import dataclass, field from enum import Enum from typing import Optional class ContinuityViolation(RuntimeError): """Raised when a worker is asked to execute an item whose prior attempt may have reached a non-idempotent effect and cannot be proven otherwise.""" pass class AttemptState(Enum): PRE_EFFECT = "pre_effect" POST_EFFECT = "post_effect" UNKNOWN_EFFECT = "unknown_effect" @dataclass class Attempt: attempt_id: str item_id: str state: AttemptState started_at: float class AttemptLedger: """Shared, worker-readable ledger. Must be reachable to authorize execution.""" def __init__(self) -> None: self._attempts: dict[str, list[Attempt]] = {} self._reachable = True def set_reachable(self, reachable: bool) -> None: self._reachable = reachable def prior_attempts(self, item_id: str) -> list[Attempt]: if not self._reachable: raise ContinuityViolation( f"ledger unreachable while checking item {item_id!r}; " "refusing to authorize execution (fail closed)" ) return list(self._attempts.get(item_id, [])) def record(self, attempt: Attempt) -> None: if not self._reachable: raise ContinuityViolation( f"ledger unreachable while recording attempt {attempt.attempt_id!r}" ) self._attempts.setdefault(attempt.item_id, []).append(attempt) class Worker: def __init__(self, worker_id: str, ledger: AttemptLedger) -> None: self.worker_id = worker_id self.ledger = ledger def _authorize(self, item_id: str) -> Optional[str]: """Return a fresh attempt_id if execution is authorized, else raise.""" priors = self.ledger.prior_attempts(item_id) for prior in priors: if prior.state in (AttemptState.POST_EFFECT, AttemptState.UNKNOWN_EFFECT): raise ContinuityViolation( f"item {item_id!r} has prior attempt {prior.attempt_id!r} in state " f"{prior.state.value}; re-dispatch refused, escalate to reconciliation" ) # No prior attempt reached effect. Pre-effect retries are safe. return f"{self.worker_id}:{item_id}:{int(time.time() * 1000)}" def execute(self, item_id: str, payload: dict) -> str: attempt_id = self._authorize(item_id) attempt = Attempt( attempt_id=attempt_id, item_id=item_id, state=AttemptState.PRE_EFFECT, started_at=time.time(), ) self.ledger.record(attempt) # Non-idempotent effect begins here. Mark intent before the effect so a # crash mid-effect is recorded as UNKNOWN_EFFECT, not PRE_EFFECT. try: version_id = self._write_versioned(item_id, payload) attempt.state = AttemptState.POST_EFFECT except Exception: attempt.state = AttemptState.UNKNOWN_EFFECT raise finally: # Re-record the terminal state; ledger is append-only per attempt. self.ledger.record(attempt) return version_id def _write_versioned(self, item_id: str, payload: dict) -> str: # Placeholder for the versioned-store write. The key point is that the # effect is non-idempotent unless the store dedupes on item_id. return f"v-{item_id}-{int(time.time() * 1000)}" def supervisor_redispatch(worker: Worker, item_id: str, payload: dict) -> str: """Supervisor-side re-dispatch. The worker is the authorizing party.""" return worker.execute(item_id, payload) if __name__ == "__main__": ledger = AttemptLedger() worker = Worker("w1", ledger) # Normal path: first attempt, no priors, executes. supervisor_redispatch(worker, "item-17", {"body": "x"}) # Simulate a prior attempt that reached effect (post-timeout commit). ledger.record(Attempt( attempt_id="w1:item-17:earlier", item_id="item-17", state=AttemptState.POST_EFFECT, started_at=time.time() - 60, )) # Supervisor re-dispatches the "failed" item. Worker must refuse. try: supervisor_redispatch(worker, "item-17", {"body": "x"}) except ContinuityViolation as exc: print(f"refused: {exc}") # Ledger outage: worker must also refuse, not "try anyway". ledger.set_reachable(False) try: supervisor_redispatch(worker, "item-18", {"body": "y"}) except ContinuityViolation as exc: print(f"refused (ledger down): {exc}") ```