Add idempotency key support for task deduplication#88
Open
AntoineToussaint wants to merge 1 commit intomainfrom
Open
Add idempotency key support for task deduplication#88AntoineToussaint wants to merge 1 commit intomainfrom
AntoineToussaint wants to merge 1 commit intomainfrom
Conversation
4b21848 to
42e29c1
Compare
Two new fields on SpawnOptions: - `only_once: bool` — auto-derives key from hash(task_name, params) - `idempotency_key: Option<String>` — explicit key (takes precedence) When a key is set, spawn_task checks for an existing non-terminal task with the same key. If found, returns the existing task instead of creating a duplicate. This enables first-served semantics where multiple clients can safely try to spawn the same logical task. DB changes: - New nullable `idempotency_key` column on task tables - Partial unique index on idempotency_key WHERE NOT NULL - Migration adds column/index to all existing queues - ensure_queue_tables updated for new queues Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
42e29c1 to
6023294
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two new fields on
SpawnOptionsfor controlling task deduplication:only_once: bool— auto-derives idempotency key fromhash(task_name, params). First spawn creates the task, duplicates are no-ops.idempotency_key: Option<String>— explicit key for when params differ but the operation is the same. Takes precedence overonly_once.Default behavior (
only_once: false, no key) is unchanged — every spawn creates a new task.Motivation
In multi-instance deployments, multiple clients may observe the same event and independently try to spawn the same logical task. Without dedup, N instances create N tasks that all execute. This is wasteful for expensive operations and incorrect for non-idempotent ones.
DB Changes
idempotency_key TEXTcolumn on task tablesWHERE idempotency_key IS NOT NULLspawn_taskchecks for existing non-terminal task with same key before insertingensure_queue_tablesupdated for new queuesDesign doc
See
docs/design/durable-idempotency-key.mdin the autopilot repo.Test plan
only_once: true— second spawn returns existing taskidempotency_key— same behavior🤖 Generated with Claude Code