Skip to content

How can my app avoid sending the same completion notification several times?

Record completion notifications as application events with stable identities, and deduplicate delivery independently of job polling. Several observations of the same completed AISwapLab job should resolve to one notification event. Transport retries may still occur, so distinguish an event from each attempt to deliver it.

MAKE API WORK RECOVERABLEAISwapLab team · Editorial methodUpdated 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Create one event transactionally; Dispatch from delivery state; Make notices useful after delays.
Workflow diagram: Create one event transactionally → Dispatch from delivery state → Make notices useful after delays. Read the article for evidence and limits.

Observation is not a new event

A browser refresh, worker restart or second status reader can observe completion again. If each observation directly sends a message, users receive repeated notices. A local notification ledger lets you retry delivery while keeping the underlying event stable.

What to do next

  1. 01

    Create one event transactionally

    When your application first records the meaningful completion transition, insert a notification event with a unique key such as task plus event type plus recipient. Enforce that uniqueness in the database.

  2. 02

    Dispatch from delivery state

    Let a notification worker attempt delivery and record its outcome separately. Use the destination transport's duplicate controls where available, but do not assume an external email or push provider offers exactly-once delivery.

  3. 03

    Make notices useful after delays

    Link to the durable task rather than embedding private media or a transient preview URL. Check the recipient's current access and preference before delivery, particularly after a long delay or project membership change.

A concrete example

Illustrative example: three pollers observe task J as completed. All attempt to insert event J:completed:user7; one row wins. A notification transport timeout creates a second delivery attempt for that event, not a second completion event.

Run the local counterexample

Local runtime fixture, executed November 16, 2026. No AISwapLab request, payment or model generation was made.

Recorded runtime: Python 3.12.10; SQLite 3.49.1. Run the complete script below using that runtime or record the version and changed behavior in your own environment. The script uses synthetic data and temporary resources only.

python
import sqlite3,json
def run(strategy):
    c=sqlite3.connect(':memory:');c.execute('PRAGMA foreign_keys=ON')
    c.executescript('CREATE TABLE event(id INTEGER PRIMARY KEY, identity TEXT UNIQUE);'
      'CREATE TABLE attempt(event_id INTEGER REFERENCES event(id) ON DELETE CASCADE);')
    c.execute("INSERT INTO event(identity) VALUES('J:complete:U')")
    c.execute('INSERT INTO attempt VALUES(1)');c.commit()
    if strategy=='replace':
        c.execute("INSERT OR REPLACE INTO event(identity) VALUES('J:complete:U')")
    else:
        c.execute("INSERT INTO event(identity) VALUES('J:complete:U') ON CONFLICT(identity) DO NOTHING")
    result={'eventIds':[r[0] for r in c.execute('SELECT id FROM event')],
            'deliveryAttempts':c.execute('SELECT count(*) FROM attempt').fetchone()[0]}
    c.close();return result
print(json.dumps({'replace':run('replace'),'doNothing':run('ignore')}))

Actual output from this run

json
{
  "replace": {
    "eventIds": [
      2
    ],
    "deliveryAttempts": 0
  },
  "doNothing": {
    "eventIds": [
      1
    ],
    "deliveryAttempts": 1
  }
}

Use the result within its scope

The replacement statement changed the event row and removed its dependent attempt in this foreign-key-enabled schema. The conflict-do-nothing statement retained both. A unique identity alone is insufficient if conflict handling destroys the evidence it was meant to preserve. Choose conflict behavior that keeps the original event, then inspect delivery attempts as separate records.

No notification was sent. Cascade behavior follows this small SQLite schema; it does not establish email/push exactly-once delivery or behavior of another database engine.

Before you call it ready

  • One event survives repeated observations.
  • Delivery attempts retain the same event ID.
  • Current recipient access is checked before sending.

When to stop or choose another method

Stop sending notifications directly inside every completed-status response handler; establish a durable event and explicit delivery policy first.

Sources

One task. A recoverable workflow.

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

Open API documentation