Check-then-insert is a race
Two requests can both check that an action does not exist and then both insert it. That failure occurs before remote idempotency recovery. Define the real business identity carefully: a deliberate creative retry must remain possible as a new approved attempt.
What to do next
- 01
Define the action key
Choose a scoped identity such as project, approved revision and attempt number. Persist the user's approved creative snapshot with it, and ensure a genuine new attempt advances the attempt identity rather than reusing an old one.
- 02
Enforce it at insertion
Add a unique database constraint and handle the losing insert by returning the existing action. Compare its immutable snapshot before treating it as equivalent, so a conflicting payload does not silently borrow another action's identity.
- 03
Run concurrent creation tests
Send several identical commands concurrently to separate backend processes. Assert one action row and one dispatch intent, then submit a deliberately new attempt and confirm it creates a distinct approved action.
A concrete example
Illustrative example: two rapid clicks reach different application servers for project P, revision 6, attempt 1. The unique key permits one action. Choosing Try another result later creates attempt 2 after a fresh approval.
Before you call it ready
- Uniqueness is database-enforced.
- Conflicting payloads are rejected.
- Intentional new attempts remain distinct.
A locally executed, reproducible check
A database constraint rejects a second local action for the same approval.
We executed this exact synthetic fixture on November 16, 2026 with Python 3.12.10 and SQLite 3.49.1. It ran locally with no network requests, account data or model generation. The recorded output below is an observation from that environment, not a platform benchmark. Copy the code into a separate Python file to repeat it in a suitable local environment; compare the mechanism and check your runtime version.
import sqlite3
c=sqlite3.connect(':memory:')
c.execute('CREATE TABLE actions(id TEXT PRIMARY KEY, approval TEXT UNIQUE)')
c.execute("INSERT INTO actions VALUES('a1','approved-7')")
try:
c.execute("INSERT INTO actions VALUES('a2','approved-7')")
except sqlite3.IntegrityError:
print('second approval insert: rejected by UNIQUE')
print('stored actions:', c.execute('SELECT count(*) FROM actions').fetchone()[0])
Recorded output and interpretation
The constraint protects this local table even if a caller performs two inserts. It does not supply AISwapLab idempotency, authorize a retry, or enforce uniqueness in another database.
A matching local output establishes only the illustrated library or database behavior under these inputs. It does not certify a production integration. Preserve the approved action, authorization boundaries and current AISwapLab request contract when applying the idea.
second approval insert: rejected by UNIQUE
stored actions: 1
When to stop or choose another method
Stop depending on a preliminary existence query or disabled button as the sole defense against concurrent creation of local actions.
