idempotency_dedupTier 1 · 70% confidence

ai-agents-idempotency-dedup-multiple-triggers-or-retries-within-the-same-time--0971865b

agent: ai_agents

When does this happen?

IF Multiple triggers or retries within the same time window may cause duplicate notifications or data processing.

How others solved it

THEN Implement idempotency using a state file (e.g., 'last_sent_at', 'latest_db', 'checksum') stored on disk or in a database. Before execution, read the file and compare current time window or data checksum to detect duplicates. Skip or merge accordingly.

# Pseudocode for idempotency check
import json, os, hashlib

def is_duplicate(task_id, current_data):
    state_file = f'/var/state/{task_id}.json'
    if not os.path.exists(state_file):
        return False
    with open(state_file) as f:
        state = json.load(f)
    # example: check if same hourly window
    now_hour = datetime.utcnow().strftime('%Y%m%d%H')
    if state.get('last_hour') == now_hour:
        return True
    # or check data checksum
    new_checksum = hashlib.md5(current_data.encode()).hexdigest()
    if state.get('checksum') == new_checksum:
        return True
    return False

def update_state(task_id, data):
    new_checksum = hashlib.md5(data.encode()).hexdigest()
    state = {
        'last_run': datetime.utcnow().isoformat(),
        'last_hour': datetime.utcnow().strftime('%Y%m%d%H'),
        'checksum': new_checksum
    }
    with open(f'/var/state/{task_id}.json', 'w') as f:
        json.dump(state, f)

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics