codex-multi-auth icon indicating copy to clipboard operation
codex-multi-auth copied to clipboard

Design: replay and idempotency contract for non-idempotent image routes

Open latentdelta opened this issue 2 months ago • 0 comments

Proposal

Define a replay/idempotency contract for the proposed non-idempotent image routes before adding cross-request deduplication to the runtime proxy.

Related: image transport #694 and client capability shim #695. This is a design follow-up for the new routes, not a request to change Responses retry semantics.

User impact and evidence

A connection error or 5xx does not prove generation never ran. Returning that error without an internal retry prevents proxy-side account failover, but the client can issue a new HTTP request. In a local combined-patch test using official Codex 0.154.0, an image request receiving 520 was followed by a client retry that returned 200. The first outcome remained ambiguous; this does not establish that two images were actually generated or charged.

Candidate design, not a settled contract

A local prototype reserves a per-proxy hash of canonical route + image-turn/session identity + exact body before dispatch. Active reservations cannot expire; after success or ambiguity, a completed reservation is retained for ten minutes. Explicit pre-execution rejection can release it. Duplicate requests receive 409 with an explicit ambiguous-outcome message; request/image bodies are not cached. A bounded table rejects additional reservations when full.

This prototype is intentionally NOT bundled into the route PR: its semantics need agreement.

Questions to resolve

  1. Is there a documented upstream idempotency key with guarantees on the Codex subscription image endpoint? Prefer that if available; an arbitrary header alone cannot establish idempotency.
  2. What stable client operation identity exists? Turn/session plus exact bytes can miss changed serializations or wrongly block an intentional identical request.
  3. Which rejection statuses are authoritative proof of non-execution? Transport/5xx must remain ambiguous.
  4. Should successful responses be replayed from a cache, or should duplicates receive a conflict? A response cache adds image storage/privacy and memory costs.
  5. How should TTL, size bounds, cancellation and restart persistence work? An in-memory cache does not survive restart or provide exactly-once guarantees.
  6. How should accounting represent duplicate suppression without logging prompts, image data, credentials or raw account identity?
  7. Which operation classes beyond images should opt in? Avoid silently changing existing Responses behavior.

Acceptance tests for a future implementation

  • Concurrent identical dispatches result in at most one upstream call during the protected interval.
  • Ambiguous timeout/520 followed by a client retry is not silently dispatched again.
  • An intentional new operation is allowed; canonical route aliases cannot evade the guard.
  • Explicit rejection, cancellation, capacity limits, expiry and restart semantics are tested.
  • Text requests and account policy/rotation remain unchanged.
  • Local bearer auth remains mandatory; no quota, entitlement, moderation or authentication bypass.

Alternatives

Document the residual ambiguity only; disable client retries if there is a supported per-operation control; or implement upstream idempotency once its contract is documented. No solution should claim exactly-once execution based solely on a local TTL cache.

latentdelta avatar Sep 15 '26 18:09 latentdelta