Skip to content

feat(api): delivery Idempotency-Key replay and an explicit upsert mode (#1011) - #1267

Merged
athvin merged 1 commit into
mainfrom
feat/1011-delivery-idempotency
Nov 26, 2026
Merged

athvin merged 1 commit into
mainfrom
feat/1011-delivery-idempotency

Conversation

@athvin

@athvin athvin commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Closes #1011

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

POST …/records/ingest and POST …/imports accept an Idempotency-Key header (scoped to dataset + source). Same key + same bytes → the original 202 receipt (same delivery_id, same job, Idempotent-Replayed: true), nothing new queued; same key + different bytes → 409 naming the owning delivery. An explicit mode (upsert only; full_refresh refused by name). Docs: receipt→job→result states, limits, retry guidance.

Why

#1011: a customer retrying after a timeout created a second delivery and a second run; there was no idempotency contract at all, and nothing said that deliveries never delete what they omit.

Proof

  • pg_delivery_replay (new): JSON push and file upload replay, 409 on changed bytes, per-source key scope, no-key behaviour unchanged, the replay's copy discarded (one .csv on disk), full_refresh/bad key 422 — passes against local Postgres.
  • make check: exit 0.

Risk & rollback

Additive: requests without the header behave exactly as before. git revert <merge-sha>.

Post-merge ledger

Closed by: agent · session Claude Code:24d16c2e-fec6-49d8-9797-060338df4848 on brians-MacBook-Pro · 2026-11-26T19:54:34Z

Specific to this change

Context — plan, discoveries, measurements, files

Plan

Discoveries

  • Pin accepted deliveries to immutable inputs before queued ingestion #1002's immutable pins already make accepted bytes/mapping stable through queue, restart and replay; pg::enqueue is an upsert on (org_id, idempotency_key) returning the original job, so the client key reuses it (client-delivery:{dataset}:{source}:{key}) with no new table, and concurrent retries converge.
  • The job row already carries run_id, error_class, error_detail, so the receipt (delivery_id + job id) correlates to run and result through GET …/jobs/{id} — documented rather than adding a new receipt route.

Measurements

Files

🤖 Generated with Claude Code

#1011)

Both delivery routes (records/ingest and imports) accept an
Idempotency-Key header scoped to the dataset and source. A retry with the
same key and the same bytes returns the original 202 receipt — same
delivery_id and job, Idempotent-Replayed: true — and queues nothing; the
replay's published copy is discarded. The same key with different bytes is
a 409 naming the delivery that owns it. The key rides the jobs table's
existing (org, idempotency_key) upsert, so a concurrent retry also
converges on one job.

Deliveries upsert by record key and never delete what they omit;
mode=full_refresh is refused by name rather than ignored. The docs now
describe the receipt-to-result states, limits and retry guidance.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

The marketing preview was removed because this PR is closed or merged.

@athvin
athvin merged commit f1c883c into main Nov 26, 2026
44 checks passed
@athvin
athvin temporarily deployed to marketing-preview November 26, 2026 19:44 — with GitHub Actions Inactive

This branch was previously deployed

1 inactive deployment
marketing-preview — 613b9a93 Deployed Nov 26, 2026 by athvin via remove closed PR previews #67
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.

API: durable JSON and file delivery with receipts and replay semantics

2 participants