Skip to content

CR-10: Idempotency-Key header on start, publish and complete-task - #21

Merged
ObaidulKabir merged 1 commit into
feat/cr-06-instance-concurrencyfrom
feat/cr-10a-idempotency-header
Oct 27, 2026
Merged

ObaidulKabir merged 1 commit into
feat/cr-06-instance-concurrencyfrom
feat/cr-10a-idempotency-header

Conversation

@ObaidulKabir

Copy link
Copy Markdown
Owner

CR-10 (part 1): Idempotency-Key header on start, publish and complete-task

Stacked on #20 (CR-06). Merge #9, then #20, then this PR.

Learning OS retries writes after network failures and from offline sync, so these calls must be safe to repeat.

Changes

  • The header. POST /api/workflows/start, /api/events/publish and /api/tasks/{id}/complete read the Idempotency-Key header (at most 200 characters).
    • A repeat after the first request finished returns the first result: the same workflowInstanceId for start, and no second event applied.
    • These are rejected with 400: a header that differs from the body's idempotencyKey, two header values, or a key over 200 characters.
  • Repeat while the first is still running: now 409 with code IDEMPOTENCY-IN-PROGRESS. Before, it was a generic 400 or 500.
  • Race fix in IdempotencyService.TryBeginAsync. Two first requests arriving together with the same key used to hit the unique index and return a 500. The second one is now treated as "in progress".
  • Complete-task now passes the key through (it never did).
  • Docs: a safe-retries section in docs/14-api-reference.md, and 409 added to the error table.

Tests

  • End-to-end over HTTP:
    • repeated start returns the same instance and only one instance exists;
    • different keys start different instances;
    • repeated publish applies the event once (the second call would otherwise fail on a completed instance);
    • a pending key returns 409 with the code;
    • mismatched header and body keys, and keys over 200 characters, return 400 without creating an instance.
  • Unit: the header rules.
  • PostgreSQL (Testcontainers): four simultaneous first requests let exactly one begin, with one stored record; a failed attempt can be retried with the same key.

Refs: FlowOS Modification Proposal v1.0, CR-10.


Generated by Claude Code

…e-task

Learning OS retries writes after network failures and from offline sync, so
these calls must be safe to repeat.

- POST /api/workflows/start, /api/events/publish and /api/tasks/{id}/complete
  read the Idempotency-Key header (max 200 characters). A repeat after
  completion returns the first result; a header that differs from the body
  key, two header values, or an over-long key is 400.
- A repeat while the first request is still running is 409 with code
  IDEMPOTENCY-IN-PROGRESS (ConcurrencyConflictException) instead of 400/500.
- IdempotencyService.TryBeginAsync: two first requests racing on the same key
  no longer fail with a unique-index error; the loser is treated as in
  progress.
- Complete-task now passes the key through (it never did).
- docs/14-api-reference.md: safe retries section and 409 in the error table.
- Tests: end-to-end over HTTP (same instance on repeated start, event applied
  once on repeated publish, 409 while in progress, 400 for bad keys),
  header unit tests, and a PostgreSQL race test for TryBeginAsync.

Refs: FlowOS Modification Proposal v1.0, CR-10.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Db5nX38Equ6fWErg3oD32F
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.

2 participants