THAMER
Sovereign Bitcoin Wallet

WALLET AI BITCOIN

Your Bitcoin Wallet. Your Keys. Your Engine.

Self-hosted Bitcoin software built for developers, applications, and AI agents.

CREATE WALLET

Bitcoin Agent Idempotency Stress Testing

permalink THAMER
#ai-agents#benchmarking#bitcoin#python

Bitcoin Agent Idempotency Stress Testing

Method and scope

Submit repeated request IDs concurrently to a local ledger. Bind each ID to its original intent; conflicting reuse must fail. Independent IDs may represent identical intents. The ledger models atomic local recording only, not exactly-once external payment execution.

Independent reference implementation

Python · 25 lines
1import sqlite3
2from concurrent.futures import ThreadPoolExecutor
3from tempfile import TemporaryDirectory
4from pathlib import Path
5
6def record(path, request_id, intent):
7    with sqlite3.connect(path, timeout=10) as db:
8        db.execute("BEGIN IMMEDIATE")
9        row = db.execute("SELECT intent FROM requests WHERE id=?", (request_id,)).fetchone()
10        if row:
11            return "replay" if row[0] == intent else "conflict"
12        db.execute("INSERT INTO requests VALUES (?,?)", (request_id, intent))
13        return "new"
14
15if __name__ == "__main__":
16    with TemporaryDirectory() as directory:
17        path = Path(directory)/"ledger.db"
18        with sqlite3.connect(path) as db:
19            db.execute("CREATE TABLE requests(id TEXT PRIMARY KEY, intent TEXT NOT NULL)")
20        with ThreadPoolExecutor(max_workers=8) as pool:
21            outcomes = list(pool.map(lambda _: record(path, "r1", "intent-A"), range(100)))
22        assert outcomes.count("new") == 1 and outcomes.count("replay") == 99
23        assert record(path, "r1", "intent-B") == "conflict"
24        assert record(path, "r2", "intent-A") == "new"
25        print("100 concurrent submissions: one new record, 99 replays")

Reproducibility

Run the example with Python 3. Record the Python version, host resources and workload parameters. Repeat measurements on an idle host and report variation rather than selecting the fastest run. The assertions verify synthetic behavior only. No wallet credentials, live SEND or changes to the immutable fee law are involved.

Related research

https://thamer.org/learn/bitcoin-for-ai-agents-open-integration-guide

https://thamer.org/api

Questions & Answers

Explore all questions →

Latest from the Lab

THAMER illustrated developer portrait and signature

ABOUT THE DEVELOPER

Independent Software Developer specializing in Bitcoin Script, Golang, and AI Agents.

Software engineering · Independent research · Open-source projects