Skip to content

Article / Shared state

Optimistic concurrency for AI agent tool calls

Optimistic concurrency makes an agent state which aggregate version informed its decision. If state advanced before commit, the server rejects the stale mutation instead of silently applying it to a different world.

For
Developers building agents that act on mutable Session or Room state
Outcome
Understand why expected versions turn stale decisions into recoverable errors

Short answer

The expected version connects a decision to its observation

A mutation carries the version the agent observed; the authoritative server commits only if that version is still current.

Without this check, an action selected for one legal-action set can be applied after another participant or process has changed the state. The payload may still be structurally valid while its reasoning context is obsolete.

The conflict response is therefore useful evidence. It shows that the system protected newer state and that the agent must acquire a new observation before deciding again.

State timeline

A stale action should fail before it becomes a transition

  1. 01

    Read version 12

    The agent receives current public or caller-qualified state and legal actions.

  2. 02

    State advances to version 13

    Another accepted action commits before the first agent's mutation.

  3. 03

    Submit with expected version 12

    The server detects that the decision context is stale and rejects the mutation.

  4. 04

    Reread and decide again

    The agent uses version 13 state and sends a new logical request if action is still warranted.

Recovery boundary

A version conflict is not permission to repeat the old decision

Automatic retransmission preserves a transport request; conflict recovery requires new reasoning over new state.

The earlier action may now be illegal, suboptimal, or assigned to the wrong turn. Updating only the expected-version field would misrepresent the old decision as if it were made from the new observation.

A correct client reads current state, presents it to the agent, and creates a new idempotency key for any newly selected mutation. The rejected stale attempt remains part of the audit evidence but creates no game transition.

Evaluation

Concurrency conflicts expose state-grounding behavior

A controlled conflict can test whether an agent recognizes stale context, avoids blind retries, and resumes from an authoritative observation.

  • Verify the stale mutation created no event or point movement.
  • Require a state read between the conflict and the next decision.
  • Check that the new request uses the current version and a new logical identity.
  • Report conflict recovery separately from ordinary legal-action accuracy.

Next step

Inspect expected-version calls

See how current state and mutation requests connect in WagerCall MCP.

Inspect expected-version calls