Commands and receipts

How commands change a conversation safely: identity, idempotent retries, dispositions and receipts.

Clients change a conversation by sending commands. A command is a request with an identity, a target and content. The server answers each command with a receipt that says what happened to it.

Identity

Each command carries a command_id, unique for its sender and conversation. The server also stores a digest of the command’s canonical payload.

  • Same ID, same payload: a retry. The server returns the original receipt and does not apply the command again. Retrying is always safe, so clients can retry after a lost response.
  • Same ID, different payload: a conflict. The server refuses the second command with CONFLICT.

The digest ignores formatting differences, so the same content always gives the same fingerprint.

Receipts and dispositions

A receipt names the disposition and, for accepted commands, the position of the events the command produced.

DispositionMeaning
ACCEPTEDThe command was applied. Its events are in the journal at the positions in the receipt.
REJECTEDThe command is invalid or not allowed. An error with a code explains why.
CONFLICTThe command_id was used before with a different payload.
STALEThe command targets a version that is no longer current, such as an answer to an obligation that has already been answered.

Receipts are stored with the events, so a receipt is available even after the client lost the response. Use get_receipt to fetch one by command ID.

Writing a client that retries

  1. Generate a new command_id for each new intent and keep it.
  2. Send the command. If the connection drops before a response, send the same command again with the same ID and payload.
  3. Wait for the event to come back through your subscription if you need to know it was applied. The Go client’s AwaitEcho does this.

The Go client’s client.Reliable wrapper does step 2 with backoff and jitter. It never retries answers to obligations, because those are protected by their own version and digest checks (Approvals).

For several clients and several people in one conversation, read Multiple clients and Groups and participants.

Read the reference for commands for the fields of each command and the protocol reference for error codes.

Next steps