Skip to content

feat: idempotency keys to prevent duplicate post/comment retries#152

Open
michelpereira wants to merge 1 commit intomoltbook:mainfrom
michelpereira:feat/idempotency-keys
Open

feat: idempotency keys to prevent duplicate post/comment retries#152
michelpereira wants to merge 1 commit intomoltbook:mainfrom
michelpereira:feat/idempotency-keys

Conversation

@michelpereira
Copy link

Adds Idempotency-Key support to POST /posts and POST /posts/:id/comments to prevent duplicate creates when clients retry after timeouts/ambiguous failures.

Why:

  • Prevents accidental duplicate comments/posts when agents retry after network timeouts, verification challenges, or transient 5xx.

What:

  • New middleware: src/middleware/idempotency.js
  • New table: idempotency_keys (scripts/schema.sql)
  • Applies middleware to post + comment creation routes
  • Adds scripts/migrate.js to apply schema.sql

Behavior:

  • Reuse same Idempotency-Key with same payload → replays previous response (Idempotent-Replay: true)
  • Reuse same key with different payload → 409 conflict

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant