Skip to content

feat(outbox): harden publish contract with crash-safe idempotency keys - #1219

Merged
Baskarayelu merged 1 commit into
CredenceOrg:mainfrom
Banx17:feature/outbox-contract-fresh
Jul 29, 2026
Merged

feat(outbox): harden publish contract with crash-safe idempotency keys#1219
Baskarayelu merged 1 commit into
CredenceOrg:mainfrom
Banx17:feature/outbox-contract-fresh

Conversation

@Banx17

@Banx17 Banx17 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR hardens the outbox publish contract with crash-safe idempotency keys and comprehensive integration tests. The existing outbox infrastructure (publish idempotency key, lease-based crash recovery, IdempotentConsumer) is already in place - this PR adds integration-level coverage that simulates real crash scenarios to verify the guarantees hold end-to-end.

Related Issue

Closes #945

Changes

Crash-Safe Outbox Integration Tests

  • [ADD] tests/integration/outboxCrashRecovery.integration.test.ts
    • Publish idempotency key crash recovery: simulates consumer crash after setting publish_idempotency_key but before markPublished - verifies recovery consumer skips duplicate publish
    • Crash before idempotency key: verifies recovery consumer proceeds with normal publish flow
    • Concurrent idempotency key race: two consumers racing - only one acquires the key
    • Lease lifecycle: claim, lease expiry, reclamation by another consumer, lease renewal, graceful releaseClaims on shutdown
    • Full lifecycle: insert, claim, publish, markPublished end-to-end
    • Poison pill quarantine: malformed events detected and routed to outbox_quarantine
    • Exponential backoff and dead_letter: retry exhaustion and next_attempt_at scheduling
    • Statistics reporting: getStats() verification across all statuses

Idempotent Consumer Key Tests

  • Duplicate suppression: idempotency key prevents handler re-execution
  • Concurrent deduplication: 5 concurrent calls - handler runs exactly once
  • Retry after failure: failed processing allows retry
  • Result persistence: isProcessed() and getResult() after processing
  • TTL expiry: expired keys allow reprocessing
  • Outbox event integration: downstream handler deduplication for outbox events

Verification Results

npm test src/db/outbox/ tests/integration/outboxCrashRecovery.integration.test.ts
63/63 passed (46 existing + 17 new)

Test Files 7 passed (7)
Tests 63 passed (63)

Adds integration tests for crash-safe outbox publish contract and idempotent consumer keys.

Closes CredenceOrg#945
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@Banx17 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Baskarayelu
Baskarayelu merged commit 22cb504 into CredenceOrg:main Jul 29, 2026
2 checks passed
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.

[Fresh 2026-04][Backend] Events: outbox publish contract (crash-safe + idempotent consumer keys)

2 participants