rohitg00/ai-engineering-from-scratch · error · ReliabilityError

idempotency key was reused with different arguments

Error message

idempotency key was reused with different arguments

What it means

Error "idempotency key was reused with different arguments" thrown in rohitg00/ai-engineering-from-scratch.

Source

Thrown at phases/13-tools-and-protocols/29-mcp-reliability-cancellation-and-flow-control/code/main.py:352

        if cents <= 0:
            raise ReliabilityError("charge must be positive")
        fingerprint = self._fingerprint(account, cents)
        with self._lock:
            self._connection.execute("BEGIN IMMEDIATE")
            try:
                if idempotency_key is not None:
                    stored = self._connection.execute(
                        """
                        SELECT fingerprint, result_json
                        FROM idempotency_records
                        WHERE idempotency_key = ?
                        """,
                        (idempotency_key,),
                    ).fetchone()
                    if stored is not None:
                        stored_fingerprint, stored_json = stored
                        if stored_fingerprint != fingerprint:
                            raise ReliabilityError(
                                "idempotency key was reused with different arguments"
                            )
                        self._connection.execute("COMMIT")
                        return json.loads(stored_json)

                row = self._connection.execute(
                    "SELECT executions FROM mutation_counter WHERE singleton = 1"
                ).fetchone()
                if row is None:
                    raise ReliabilityError("mutation counter is missing")
                execution_number = int(row[0]) + 1
                result = {
                    "receipt": f"charge-{execution_number:03d}",
                    "rpcId": rpc_id,
                    "account": account,
                    "cents": cents,
                }
                result_json = json.dumps(

View on GitHub (pinned to 39ea8a1c6d)

When it happens

Trigger: Thrown at phases/13-tools-and-protocols/29-mcp-reliability-cancellation-and-flow-control/code/main.py:352 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26). Data as JSON: /api/errors/28491b6578d9330d. Report an issue: GitHub.