The starter code uses uuid4() to generate client_order_id at call time:
orderUuid = str(uuid.uuid4())
kalshi_api.create_order(CreateOrderRequest(
client_order_id=orderUuid, ...
))
When an AI agent places an order and the network times out before
receiving a response, the agent retries. The retry generates a new
uuid4() — Kalshi's dedup never fires and a second position opens.
The fix: derive client_order_id from order parameters before execution
and persist it in durable storage. Any retry with the same parameters
returns the original order without opening a second position.
Reference implementation: SafeAgent (pip install safeagent-exec-guard)
Same failure pattern documented in production: langchain-ai/langgraph#7417
The starter code uses uuid4() to generate client_order_id at call time:
When an AI agent places an order and the network times out before
receiving a response, the agent retries. The retry generates a new
uuid4() — Kalshi's dedup never fires and a second position opens.
The fix: derive client_order_id from order parameters before execution
and persist it in durable storage. Any retry with the same parameters
returns the original order without opening a second position.
Reference implementation: SafeAgent (pip install safeagent-exec-guard)
Same failure pattern documented in production: langchain-ai/langgraph#7417