How must an instance hedge requests without double-paying for cancelled hedges?
**Date of Record:** 2026 October 27 **Scope:** Applies when an agentic session sends parallel duplicate requests (hedged requests) to reduce tail latency, and must track which hedges were cancelled or ignored so downstream billing does not charge for work that was duplicated. Does not apply to strictly idempotent downstream services where duplicate billing is impossible.
Core Distinction
The separation between **hedging intent** (the agent wants faster response by racing duplicates) and **hedging accounting** (the system knows which duplicates were cancelled, so downstream services do not treat all duplicates as billable work). Relying on intent creates the **Hedging Double-Pay**: the agent sends request H1 and hedge H2, H1 succeeds first, H2 is discarded, but H2's downstream work already executed (a write, a compute job, an API call) and is billed as if it were real.
What Was Observed
In latency-sensitive agent architectures, failing to account for hedges produces three primary failure modes:
- **Silent Double-Charge:** A payment authorization is hedged. Both copies authorize, both charge, and the customer is charged twice because only one was supposed to succeed.
- **Duplicate Side Effects:** A tool call is hedged. Both copies invoke the tool, both produce side effects (send email, write file), and downstream deduplication is impossible because the tool is not idempotent.
- **Cost Creep:** The agent's monthly bill reflects 40% more tool calls than user-visible operations because every operation was hedged and the hedge copies were billed.
Recorded Elements
- **`hedge_group_id`:** A cryptographic identifier grouping all requests sent under a single hedging decision, allowing downstream services to identify and dedupe.
- **`hedge_winner_signature`:** The cryptographic proof of which hedge won the race, sent to the losers so downstream services can cancel their in-flight work.
- **`hedge_cancellation_receipt`:** For each losing hedge, a cryptographic proof that the cancellation was requested and (if applicable) acknowledged by the downstream service.
- **`downstream_idempotency_key`:** A key shared by all hedges in the group so downstream services can detect duplicate work at the point of execution, even before receiving cancellation.
Condition of Validity
* **Applies when:** The agent hedges requests, downstream services are billable or have non-idempotent side effects, and cancellations may arrive after the work has started. * **Does not apply when:** Downstream services are strictly idempotent with deduplication, or the agent does not hedge.
Decision Boundary
- **Is the request being hedged?** If no, standard request handling applies. If yes, proceed.
- **Does each hedge include the `hedge_group_id` and `downstream_idempotency_key`?** If no, downstream services cannot dedupe. The agent must add them before dispatch.
- **Has the `hedge_winner_signature` been sent to losers?** If no, losers will continue their work and be billed. The agent must send winners immediately.
- **Conversely, when can an agent hedge without accounting?** Only when the downstream operation is fully idempotent with deduplication at the service side, or the hedge is explicitly marked as "pay for all" (e.g., racing research queries where duplication is acceptable).
Operational Effect
- **Double-Charge Prevention:** Downstream services can dedupe based on group ID or idempotency key.
- **Cancellation Discipline:** Winners immediately cancel losers, reducing wasted work even if not eliminated.
- **Cost Transparency:** The agent's cost model can distinguish billable work from hedged work.
from dataclasses import dataclass
from enum import Enum, auto
import hashlib
import json
class HedgeVerdict(Enum):
NO_HEDGE = auto()
HEDGE_VALID = auto()
HEDGE_WINNER_UNDECLARED = auto()
HEDGE_CANCELLATION_INCOMPLETE = auto()
@dataclass(frozen=True)
class HedgeRequest:
request_id: str
hedge_group_id: str | None
downstream_idempotency_key: str | None
is_winner: bool
winner_signature_sent: bool
@dataclass(frozen=True)
class HedgePolicy:
require_group_id: bool
require_cancellation_receipt: bool
@dataclass(frozen=True)
class HedgeManifest:
verdict: HedgeVerdict
directive: str
manifest_digest: str
class HedgingAccountingGuard:
@staticmethod
def _hash(data: str) -> str:
return hashlib.sha256(data.encode("utf-8")).hexdigest()
@classmethod
def evaluate_hedge(
cls, request: HedgeRequest, policy: HedgePolicy
) -> HedgeManifest:
# Gate 1: Not hedged
if not request.hedge_group_id:
digest = cls._hash(json.dumps({
"request": request.request_id,
"hedge": "NONE"
}, sort_keys=True))
return HedgeManifest(
verdict=HedgeVerdict.NO_HEDGE,
directive=f"PROCEED: Request {request.request_id} not hedged.",
manifest_digest=digest
)
# Gate 2: Group ID + idempotency key
if policy.require_group_id:
if not request.downstream_idempotency_key:
return HedgeManifest(
verdict=HedgeVerdict.HEDGE_WINNER_UNDECLARED,
directive=f"HALT: Hedge {request.request_id} lacks downstream idempotency key.",
manifest_digest=cls._hash(f"NO_IDEM_KEY:{request.request_id}")
)
# Gate 3: Winner signature requirement
if not request.is_winner and not request.winner_signature_sent:
if policy.require_cancellation_receipt:
return HedgeManifest(
verdict=HedgeVerdict.HEDGE_CANCELLATION_INCOMPLETE,
directive=f"HALT: Losing hedge {request.request_id} has no winner signature. Cannot cancel.",
manifest_digest=cls._hash(f"NO_WINNER:{request.request_id}")
)
# Gate 4: Valid
digest = cls._hash(json.dumps({
"request": request.request_id,
"group": request.hedge_group_id,
"idem_key": request.downstream_idempotency_key,
"winner": str(request.is_winner)
}, sort_keys=True))
return HedgeManifest(
verdict=HedgeVerdict.HEDGE_VALID,
directive=f"PROCEED: Hedge {request.request_id} properly accounted.",
manifest_digest=digest
)