Skip to content

feat(backend): idempotency key for capture - #355

Merged
CarlosLugones merged 2 commits into
developfrom
feature/350-capture-idempotency-key
Dec 6, 2026
Merged

CarlosLugones merged 2 commits into
developfrom
feature/350-capture-idempotency-key

Conversation

@CarlosLugones

Copy link
Copy Markdown
Member

Ref #350

What changes

  • capture (MCP) takes an optional idempotency_key (up to 255 characters). A second capture with a key the same connection sent in the last 24 hours saves nothing and returns the item the first one made, as it is now, with replayed: true.
  • Keys are per connection (the ApiToken row: a personal token, or a connected app, which keeps its row when its key is refreshed). Two assistants that pick the same key each get their own item.
  • The key names the write, not its text: a retry with different text still returns the first item.
  • An archived or edited item comes back as it is now; the retry doesn't unarchive it or touch the user's edits.
  • New CaptureKey table (apps.mcp), unique per connection and key. The key is reserved before the item is made, in the same transaction, so two simultaneous calls with the same key make one item: the second waits and returns it. A failed capture (for example, a wrong collection) doesn't keep its key.
  • Keys past 24 hours are ignored on lookup and removed by a daily task (delete_old_capture_keys, 05:15). Revoking a connection or deleting the item also forgets its keys.
  • REST capture is unchanged: MCP only for now.
  • Tool description and docs/mcp.md updated.

Testing

  • New tests in apps/mcp/tests/test_mcp.py: retry returns the same item, different keys or no key capture twice, per-connection scope, archived and edited item returned as it is now, expiry after 24 hours, failed capture drops its key, deleted item forgets its key, cleanup task, key validation.
  • Checked once by hand with two threads against Postgres: two simultaneous calls with the same key make one item.
  • Full backend suite: 1468 passed. make lint clean.

@CarlosLugones CarlosLugones mentioned this pull request Dec 5, 2026
3 tasks done
@CarlosLugones CarlosLugones reopened this Dec 6, 2026
@CarlosLugones
CarlosLugones merged commit 7d9ff35 into develop Dec 6, 2026
22 checks passed
@CarlosLugones
CarlosLugones deleted the feature/350-capture-idempotency-key branch December 6, 2026 01:07
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