Repository navigation
Description
Summary
Add an Idempotency-Key contract at every producer boundary that creates executions: /api/internal/... (scheduler), /api/webhooks/{token} (#291), MCP chat_with_agent and fan_out, sync /chat, async /task, event subscriptions, and self-execute. Backend stores (key → execution_id) for 24 h and short-circuits duplicates with the original execution result instead of dispatching twice.
Context
From the orchestration architecture review (2026-04-26):
No idempotency at the producer boundary. Webhook re-deliveries, MCP client retries, scheduler-to-backend network blips — all create duplicate executions. Unifying every trigger through one funnel (
TaskExecutionService) actually makes this worse, because the funnel doesn't dedupe — it just trusts the producer.
This is most acute for webhooks (external systems retry on 5xx and on perceived timeouts) and scheduler dispatch (network blip between scheduler container and backend creates phantom retries). Today the only mitigation is "be a well-behaved producer," which external webhook senders are not.
Acceptance Criteria
-
Idempotency-KeyHTTP header accepted on:/api/agents/{name}/chat,/api/agents/{name}/task,/api/internal/agents/{name}/execute-task,/api/webhooks/{token}, MCP-originated executions (chat_with_agent,fan_out), event-subscription dispatch. - New
idempotency_keystable:(key, scope, execution_id, created_at, response_snapshot)with 24 h TTL and a unique constraint on(scope, key). - On duplicate key: return the original execution_id and (if execution finished) the original result, with HTTP 200 +
X-Idempotent-Replay: trueheader. Do not dispatch a second execution. - Webhook trigger auto-derives a key from
(webhook_token, body_hash)if the caller doesn't supply one — covers naive webhook senders that retry without idempotency awareness. - Scheduler dispatch supplies a deterministic key derived from
(schedule_id, fire_time)so a transient backend 5xx + APScheduler retry never produces duplicates. - Audit log entry for every idempotent replay (so duplicate-storms are observable).
- Documented in architectural invariants — every new trigger type must accept idempotency keys before merging.
Technical Notes
- Place enforcement in
TaskExecutionService.execute_task()(or a thin pre-check ahead of it) so all trigger paths inherit it for free — consistent with the "single funnel" architecture. - Key scoping: per-tenant or per-agent to prevent cross-tenant collision.
- Body hashing for webhooks: SHA-256 of canonicalized body, header-independent.
- Related: pairs naturally with retry-in-funnel (currently only the scheduler retries, see ORCHESTRATION_RELIABILITY plan).
Activity
docs(planning): add Tier 2.6 hardening + actor-model destination roadmap
docs(planning): mark #291 (WEBHOOK-001) shipped, Sprint C now 5/5
Release: v0.5.0 (#608)
test(webhooks): stub services.idempotency_service in rate-limit loade…
Merge origin/dev into feature/525-idempotency-keys
feat(reliability): idempotency keys at execution trigger boundaries (#…
vybe commentedon Jun 2, 2026
Closed by #1019 (squash-merged to
devafter resolving append-collisions in database.py + migrations.py against current dev — keep-both, no migration renumber since the codebase uses named migrations; CI incl. schema-parity + backend-boots + multi-seed pytest re-ran green on the merge commit).Implements RELIABILITY-006: an
Idempotency-Keycontract at every execution trigger boundary (chat/task/internal/webhook/fan-out/scheduler/MCP). Atomic claim viaPRIMARY KEY (scope, idempotency_key)(INSERT-or-conflict, cross-process safe), 24h TTL, fail-open dedup layer, replay short-circuit (200/202 + X-Idempotent-Replay, in-flight → 409). Newidempotency_keystable,db/idempotency.py+services/idempotency_service.py, and architectural Invariant #18. Ships tomainon next release.docs(feature-flows): sync idempotency-keys (#525) + richer /health si…
refactor(chat): extract execute+finalize into _run_chat_and_finalize (#…
refactor(chat): decompose chat_with_agent into admit/prepare/execute …
docs(user-docs): sync to post-v0.6.0 platform state
feat(reliability): effect-scoped idempotency keys for outbound side e…
fix(webhooks): only dedupe on explicit Idempotency-Key — stop swallow…
feat(pull-migration): pull coordination core — claim/CAS, lease-reape…
feat(pull-migration): pull coordination core — claim/CAS, lease-reape…
feat(pull-migration): pull/work-stealing coordination Phases 0–3 (dar…
fix(canary): make E-01 lease-aware so a healthy pull turn stops pagin…
fix(webhooks): a busy schedule is a healthy 202, not a 503 (#1968)
fix(webhooks): a busy schedule is a healthy 202, not a 503 (#1968)
fix(scheduler): return a real execution_id, and 409 when nothing star…