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