Skip to content

How can my app enforce that one approved business action maps to only one generation action?

Create a unique constraint for the application identity of an approved generation action, and insert through that constraint. A browser-disabled button is only a convenience. This local invariant prevents two simultaneous command handlers from creating separate action records before either reaches AISwapLab.

MAKE API WORK RECOVERABLEAISwapLab team · Editorial methodUpdated 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Define the action key; Enforce it at insertion; Run concurrent creation tests.
Workflow diagram: Define the action key → Enforce it at insertion → Run concurrent creation tests. Read the article for evidence and limits.

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

  1. 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.

  2. 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.

  3. 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.

python
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.

text
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.

Sources

One task. A recoverable workflow.

Check the contract, approve the quote and retain the job.

Open API documentation