Skip to content

AI agent order retries generate new client_order_id — duplicate positions possible #135

@azender1

Description

@azender1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions