Skip to content

BUG-31: an Idempotency-Key never expires, and the design says 24 hours #142

Closed

Description

@ephico2real2

Part of #17

What is wrong: An Idempotency-Key has no time limit. The design says that the same key and caller return the first response for 24 hours. The code returns the first request for that key at any age. After 24 hours, the same key with another body still answers 409 idempotency-replay, and a new request with that key cannot be stored.

Where: cmapi/src/cmapi/core/db/repo.py:111-113, RequestRepo.by_idempotency, which has no condition on the age of the row. The unique index uq_cr_idempotency on (requester_sub, idempotency_key) in cmapi/src/cmapi/core/db/migrations/versions/0001_cmapi_schema.py:60 has no time limit. The design is docs/02-technical-design-v2.md:128. The header's description in cmapi/src/cmapi/routers/__init__.py also says "for 24 hours".

How to prove it: In the service suite, create a namespace request with a key. Set created_at of its row to 25 hours ago. Send another body with the same key and the same caller. The answer must be 202 with a new request. Today it is 409 idempotency-replay.

Measured or inferred: Read from the code at ecc5cb3 on 2026-11-13: grep -n "24\|hours" cmapi/src/cmapi/core/db/repo.py finds no time condition. The 409 is inferred until the test runs.

Severity: Low. A client that makes each key new is not affected.

What must hold after the fix: Within 24 hours, the same key and caller get the first response, and another body gets 409. After 24 hours, the key is free: a request with that key is a new request. The database clock decides the age, not the clock of a pod. The old request keeps its other data.

Research: Read the IETF draft "The Idempotency-Key HTTP Header Field" for the expiry of a key. The owner's cache rule applies: use PostgreSQL, the database's now(), and no other store (kvpg design choice D7).

Solution (inline, not applied): Before the lookup, in the same transaction, clear idempotency_key and idempotency_fingerprint on rows of that caller and key that are older than 24 hours by the database's now(). Then the unique index needs no change.

Class: No class. The fix brings the designed behaviour and adds nothing new.

Activity

  1. added
    bug
    status:open
    sev:low
    Backlog
    on Nov 13, 2026
  2. added
    In-Progress
    and removed
    Backlog
    on Nov 13, 2026
  3. ephico2real2 commented on Nov 13, 2026

    @ephico2real2
    OwnerAuthor

    In-Progress: the fix is on branch fix-idempotency-expiry, in a draft pull request on top of PR #135. The new test fails before the fix (409) and passes after it.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-Progressbugsev:lowstatus:open

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions