Skip to content

fix(api): honour the idempotency key when an administrator creates a privacy case - #1017

Merged
Medformatik merged 1 commit into
fix/privacy-repeat-notificationsfrom
fix/privacy-admin-create-idempotency
Nov 16, 2026
Merged

Medformatik merged 1 commit into
fix/privacy-repeat-notificationsfrom
fix/privacy-admin-create-idempotency

Conversation

@Medformatik

Copy link
Copy Markdown
Collaborator

What changed and why

Creating a privacy case as an administrator requires an Idempotency-Key, but the key did nothing for a create. Replay protection looked for an earlier event with the same key on the same case, and every create makes a new case. The only duplicate guard was "one active request per account and kind", which does not apply to a subject without an account.

So a retried POST for a subject identified by e-mail or post created a second case, with its own statutory deadline, administrator alerts and tasks. The bundled admin page uses a fresh key per click and disables its button, so this mainly affects API clients and automatic retries after a lost response.

A create that carries a key now first looks for an earlier create with the same key by the same administrator, inside the lock every create already takes, so two concurrent creates run one after the other:

  • Same key, same request: the original case is returned.
  • Same key, different request: 409 IDEMPOTENCY_KEY_REUSED, as the other privacy mutations answer.
  • A different key: a new case, as before.

"Same request" is judged by a digest stored on the case's first event, covering kind, channel, account, locator type, supplied receipt time, locale and time zone. The subject's e-mail or postal locator is left out on purpose: it is stored encrypted, and an unsalted digest of an address could be confirmed by guessing. A key reused for a different subject therefore returns the original case.

No schema or route schema changes. A retry that straddles the update gets 409, not a duplicate.

Verification

  • Four new route cases in admin-workflows-postgres.test.ts, run against a disposable PostgreSQL: a replay for an account-less subject returns one case, two concurrent creates with one key produce one case, a different key creates a second case, and the same key with a different channel gets 409. Three failed before the change; with the lookup disabled they fail again.
  • lifecycle-postgres.test.ts, the API typecheck and Biome on the touched files pass locally.
  • Not run locally: the rest of the database suite; CI covers it.

Release and upgrade impact

Product impact: ordinary

@Medformatik Medformatik self-assigned this Nov 16, 2026
@Medformatik
Medformatik added this pull request to stack #975 November 16, 2026 10:12
@Medformatik
Medformatik merged commit 71612b6 into main Nov 16, 2026
41 checks passed
@Medformatik
Medformatik deleted the fix/privacy-admin-create-idempotency branch November 16, 2026 17:08
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