Skip to content

How can my app avoid saving a generation request but losing its queue message?

Use a transactional outbox in your application when saving an approved action and publishing a queue message cannot be one atomic operation. Commit both the action and an outbox row together, then let a dispatcher deliver it. This is an integration pattern, not a native AISwapLab queue feature.

MAKE API WORK RECOVERABLEAISwapLab team · Editorial methodUpdated 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Write one local transaction; Dispatch with stable identity; Test both crash windows.
Workflow diagram: Write one local transaction → Dispatch with stable identity → Test both crash windows. Read the article for evidence and limits.

Close the database-to-queue write gap

A database commit followed by a queue publish leaves a crash window between them. Reversing the order creates a different gap: a worker may receive a command whose database record never committed. A durable outbox gives operators an explicit pending dispatch to inspect.

What to do next

  1. 01

    Write one local transaction

    Validate the approved snapshot, then insert the action and its dispatch-intent row in the same database transaction. If either insert fails, roll back both so the system cannot promise processing for a half-recorded action.

  2. 02

    Dispatch with stable identity

    Have a separate process claim pending outbox rows and deliver commands using the original action identity. Mark delivery only after the receiver's acknowledgment; design the consumer to tolerate duplicate message delivery.

  3. 03

    Test both crash windows

    Crash after committing the outbox but before publishing, and after publishing but before marking delivery. The first case must eventually dispatch; the second must replay the same action rather than create a new creative attempt.

A concrete example

Illustrative example: action A73 and outbox row O73 commit together. The process stops before queue publication. On restart, the dispatcher finds O73 and publishes A73, preserving the user's approved request instead of leaving an invisible orphan.

Before you call it ready

  • Action and outbox commit together.
  • Duplicate delivery resolves to the same action.
  • Undelivered rows remain queryable.

A locally executed, reproducible check

A real rollback removes both rows; a real commit preserves both.

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.executescript('CREATE TABLE actions(id TEXT PRIMARY KEY); CREATE TABLE outbox(action TEXT);')
try:
    with c:
        c.execute("INSERT INTO actions VALUES('a1')")
        c.execute("INSERT INTO outbox VALUES('a1')")
        raise RuntimeError('simulated failure before commit')
except RuntimeError:
    pass
def counts():
    return tuple(c.execute('SELECT count(*) FROM '+t).fetchone()[0] for t in ('actions','outbox'))
print('after rollback:',counts())
with c:
    c.execute("INSERT INTO actions VALUES('a2')")
    c.execute("INSERT INTO outbox VALUES('a2')")
print('after commit:',counts())

Recorded output and interpretation

Only database atomicity is exercised. No queue publishes, process crash, network retry or downstream deduplication is tested; durable publication still needs its own delivery protocol.

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
after rollback: (0, 0)
after commit: (1, 1)

When to stop or choose another method

Stop claiming exactly-once remote generation from an outbox alone; it solves local dual writes and still requires duplicate-safe dispatch.

Sources

One task. A recoverable workflow.

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

Open API documentation