# Which invariants prevent double-subcontracting when bid acceptance and work-assignment are separated across agent handoffs **Date of Record:** 2026 November 21 **Scope:** Applies to multi-agent systems where a contractor agent solicits bids from subagents, selects a winner, and then issues a separate assignment message; excludes single-shot request/response agents and synchronous RPC-style tool calls where bid and execution are atomic. ## Core Distinction The failure this record isolates is not "an agent picked the wrong bidder." It is the split between **bid acceptance** (a contractor tells a bidder "you win") and **work assignment** (the contractor tells that bidder "begin subtask S under contract C"). In protocols that separate these two phases—common because acceptance must be broadcast to losers, while assignment carries the full task payload and budget warrant—there is a window during which the contractor's state says "winner elected" but the winner's state says "still idle, no contract." If the contractor's election is retried (timeout on the acceptance ACK) or if the contractor crashes between acceptance and assignment and resumes from a checkpoint that recorded only the bid table, the same subtask can be assigned twice: once to the re-elected winner and once to a fallback bidder triggered by the same timeout. The invariant that prevents this is **assignment idempotency keyed on a subtask identity that is minted at bid-solicitation time and carried unchanged through acceptance, assignment, and completion**—not on the winning agent's identity, which is exactly what changes across a re-election. ## What Was Observed A planner agent (`PLAN-7`) decomposed a document-extraction task into 40 subtasks. For subtask `S-013`, it broadcast a bid request to five extractor agents with a deadline of 8s. Four responded; the lowest-cost compliant bid came from `EXT-2` at 1,200 tokens. `PLAN-7` sent an acceptance message to `EXT-2` and a rejection to the other three, then began composing the assignment payload (the document chunk plus a 1,500-token budget warrant). The acceptance ACK from `EXT-2` did not arrive within the 2s ACK window—`EXT-2` was mid-inference on a prior subtask and its message loop was blocked. `PLAN-7`'s acceptance-retry policy fired: it re-ran winner selection over the still-cached bid table. Because `EXT-2`'s bid had been marked "accepted, pending ACK," the selector skipped it as unavailable and elected the second-lowest bidder, `EXT-4`, at 1,340 tokens. `PLAN-7` sent acceptance to `EXT-4` and an assignment for `S-013` with the full chunk. Meanwhile `EXT-2` finished its prior subtask, drained its inbox, saw the original acceptance, and—following its own protocol rule that "acceptance implies imminent assignment"—began pre-fetching and extracting the chunk it had bid on, using a cached copy of the document it had been given at bid time. `EXT-4` received its assignment and extracted the same chunk. Two agents produced output for `S-013`. Both reported completion with valid warrants. The merger downstream, seeing two results tagged `S-013`, concatenated them, and the final document contained a duplicated 3,100-token section. The critical detail: `EXT-2` never received an assignment message. It inferred assignment from acceptance. The protocol's acceptance semantics were ambiguous between "you are the winner, await assignment" and "you are engaged, proceed," and each agent implemented a different reading. ## Condition of Validity The double-assignment hazard is live only when all three hold: 1. **Acceptance and assignment are separate messages** with a non-zero gap (payload composition, warrant minting, human-in-the-loop confirmation). 2. **Acceptance is retried on ACK timeout**, and the retry path can re-elect a different winner (because the original winner is marked busy/unavailable). 3. **At least one bidder treats acceptance as sufficient to begin work**, or the contractor's checkpoint/resume can replay assignment for a subtask whose assignment already landed. If acceptance and assignment are fused into one message, the window closes. If retry re-sends the *same* acceptance to the *same* winner (no re-election), no second winner exists. If every bidder strictly waits for assignment, the pre-fetch path is closed but the checkpoint-replay path remains. ## Decision Boundary The boundary is drawn at **what identity the deduplication key is bound to**. Binding it to the winning agent's ID is wrong: re-election changes the winner, so a winner-keyed dedup lets both `EXT-2` and `EXT-4` proceed. Binding it to the subtask ID minted at solicitation is correct: `S-013` is one unit of work regardless of who executes it, and any second assignment for `S-013` is a protocol violation that must be rejected at the executor, not merely deduplicated at the merger. Two guardrails are required, and neither alone suffices: - **Contractor side:** a `subtask_id → {state, assigned_to, assignment_nonce}` record that is written *before* the assignment message is sent and is part of the checkpoint. On resume, assignment is replayed only if `state != ASSIGNED`. Re-election must mint a *new* `assignment_nonce` and must first send a `REVOKE` to the prior winner; the prior winner must treat `REVOKE` as authoritative and must not begin work on acceptance alone. - **Executor side:** an idempotency ledger keyed on `(subtask_id, assignment_nonce)`. An executor that receives an assignment for a `subtask_id` it has already started or completed must reject with `DuplicateAssignment` unless the nonce matches, in which case it returns the cached result. This catches the case where the contractor's REVOKE is lost. The invariant, stated precisely: **for any `subtask_id`, at most one `assignment_nonce` may be in state `ASSIGNED` or `COMPLETED` at any time, and acceptance alone never transitions an executor into `WORKING`.** Acceptance transitions the bidder to `ELECTED`; only an assignment carrying a nonce transitions it to `WORKING`. ## Operational Effect Enforcing the nonce-keyed invariant changes three behaviors. First, acceptance-retry no longer silently re-elects: the retry path must consult the subtask record and either re-send acceptance to the recorded winner or, if re-election is genuinely needed, emit `REVOKE` to the old winner and wait for its `REVOKED` ACK before assigning the new one—adding one round-trip of latency in exchange for closing the window. Second, checkpoint/resume becomes safe: replaying assignment is gated on `state != ASSIGNED`, so a crash between assignment-send and assignment-ACK does not double-assign. Third, the merger's duplicate-detection becomes a backstop rather than the primary defense; duplicates at the merger now indicate a protocol violation upstream and should raise, not concatenate. The cost is that the contractor must persist a per-subtask record before every assignment, and executors must maintain a ledger across their lifetime. In systems where executors are ephemeral (cold-started per subtask), the ledger must live in a shared store keyed by `subtask_id`, or the executor-side guardrail is vacuous. This is the non-obvious part: **the executor-side idempotency check is only as strong as the executor's memory continuity**, and a swarm of stateless subagents provides no protection without a shared dedup store. ```python from dataclasses import dataclass, field from enum import Enum class DuplicateAssignment(RuntimeError): """Raised when an executor receives a second assignment for a subtask that is already in ASSIGNED or COMPLETED state under a different nonce.""" class SubtaskState(Enum): BIDDING = "bidding" ELECTED = "elected" # winner chosen, acceptance sent, NOT yet working ASSIGNED = "assigned" # assignment with nonce delivered COMPLETED = "completed" REVOKED = "revoked" @dataclass class SubtaskRecord: subtask_id: str state: SubtaskState = SubtaskState.BIDDING assigned_to: str | None = None assignment_nonce: str | None = None @dataclass class ExecutorLedger: # keyed on (subtask_id, assignment_nonce) -> result entries: dict[tuple[str, str], str] = field(default_factory=dict) # subtask_id -> nonce currently owning the work owner: dict[str, str] = field(default_factory=dict) def begin(self, subtask_id: str, nonce: str) -> str | None: existing = self.owner.get(subtask_id) if existing is not None and existing != nonce: raise DuplicateAssignment( f"subtask {subtask_id} already owned by nonce {existing}, " f"rejecting assignment under nonce {nonce}" ) if (subtask_id, nonce) in self.entries: return self.entries[(subtask_id, nonce)] # idempotent replay self.owner[subtask_id] = nonce return None def complete(self, subtask_id: str, nonce: str, result: str) -> None: if self.owner.get(subtask_id) != nonce: raise DuplicateAssignment( f"completion for {subtask_id} under nonce {nonce} but owner is " f"{self.owner.get(subtask_id)}" ) self.entries[(subtask_id, nonce)] = result def assign(record: SubtaskRecord, executor: str, nonce: str, ledger: ExecutorLedger) -> str | None: """Contractor-side assignment gated on subtask state, plus executor-side nonce check. Rejects re-assignment of an already-ASSIGNED subtask.""" if record.state in (SubtaskState.ASSIGNED, SubtaskState.COMPLETED): if record.assignment_nonce == nonce and record.assigned_to == executor: return ledger.begin(record.subtask_id, nonce) # safe replay raise DuplicateAssignment( f"subtask {record.subtask_id} already {record.state.value} under " f"nonce {record.assignment_nonce} to {record.assigned_to}; " f"refusing assignment to {executor} under nonce {nonce}" ) if record.state is not SubtaskState.ELECTED or record.assigned_to != executor: raise DuplicateAssignment( f"subtask {record.subtask_id} not in ELECTED state for {executor}" ) record.state = SubtaskState.ASSIGNED record.assignment_nonce = nonce return ledger.begin(record.subtask_id, nonce) ```