Skip to content

feat: per-subscription webhook retry policy override#584

Merged
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
ayomidearegbeshola29-dev:feature/webhook-retry-override
Jun 29, 2026
Merged

feat: per-subscription webhook retry policy override#584
greatest0fallt1me merged 1 commit into
CalloraOrg:mainfrom
ayomidearegbeshola29-dev:feature/webhook-retry-override

Conversation

@ayomidearegbeshola29-dev

Copy link
Copy Markdown
Contributor

Webhook Retry Policy Override

Feature Description

This implementation adds per-subscription override capability for webhook retry policies. Each webhook subscription can now configure custom retry behavior instead of relying solely on the default retry policy.

API Changes

Registration Endpoint

POST /api/webhooks

The registration endpoint now accepts an optional retryPolicy field:

{
  "developerId": "dev-123",
  "url": "https://example.com/webhook",
  "events": ["new_api_call", "settlement_completed"],
  "secret": "optional-secret",
  "retryPolicy": {
    "maxRetries": 5,
    "baseDelayMs": 1000
  }
}

Retry Policy Update Endpoint

PATCH /api/webhooks/:developerId/retry-policy

Updates the retry policy for an existing subscription:

{
  "retryPolicy": {
    "maxRetries": 3,
    "baseDelayMs": 500
  }
}

Response:

{
  "message": "Webhook retry policy updated successfully.",
  "developerId": "dev-123",
  "url": "https://example.com/webhook",
  "events": ["new_api_call"],
  "retryPolicy": {
    "maxRetries": 3,
    "baseDelayMs": 500
  }
  // Note: secrets are never exposed in responses
}

Get Webhook Config

GET /api/webhooks/:developerId

Now includes the retryPolicy field in the response when configured:

{
  "developerId": "dev-123",
  "url": "https://example.com/webhook",
  "events": ["new_api_call"],
  "retryPolicy": {
    "maxRetries": 3,
    "baseDelayMs": 500
  }
}

Validation Rules

The retryPolicy object is validated at the API boundary with the following constraints:

Field Type Range Description
maxRetries integer 0-10 Number of retry attempts (0 = no retries, useful for testing)
baseDelayMs integer 100-60000 Base delay in milliseconds (100ms to 60s to prevent abuse)

Both fields are optional. Unspecified fields use default values:

  • maxRetries: 5
  • baseDelayMs: 1000ms

Behavior

Exponential Backoff

The dispatcher uses exponential backoff with the configured base delay:

Attempt Delay (with baseDelayMs: 1000)
1st retry 1s
2nd retry 2s
3rd retry 4s
4th retry 8s

Override vs Default

When a subscription has no retryPolicy configured or when fields are omitted, the default values are used:

const DEFAULT_RETRY_POLICY = {
    maxRetries: 5,
    baseDelayMs: 1000,
} as const;

Monitor Integration

The webhook monitor (/api/admin/webhooks/monitor) now includes retryPolicy information in the subscription statistics when an override is configured.

Security Considerations

  • Retry policy is validated at the API boundary to prevent abuse (max values limit retry storms)
  • Secrets (both current and previous) are never exposed in any response
  • All retry policy changes are audited via logger.audit() with correlation IDs
  • Structured logging follows the codebase's error envelope pattern

Test Coverage

  • Unit tests for validateRetryPolicy() covering all validation edge cases
  • Unit tests for getEffectiveRetryPolicy() with partial and full overrides
  • Unit tests for calculateBackoff() exponential backoff calculation
  • Integration tests for the PATCH endpoint
  • Integration tests for registration with retry policy
  • Existing dispatcher tests updated to verify per-subscription behavior

closes #518

@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@ayomidearegbeshola29-dev 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

- Add RetryPolicy interface and DEFAULT_RETRY_POLICY constant to webhook.types.ts
- Add validateRetryPolicy() for input validation at API boundary (maxRetries 0-10, baseDelayMs 100-60000)
- Add getEffectiveRetryPolicy() to merge subscription overrides with defaults
- Add calculateBackoff() for exponential backoff calculation
- Update dispatcher to use subscription-specific retry policy
- Add PATCH /api/webhooks/:developerId/retry-policy endpoint
- Include retryPolicy in webhook registration and GET responses
- Update webhook monitor to include retry policy in subscription stats
- Add comprehensive unit and integration tests
@ayomidearegbeshola29-dev ayomidearegbeshola29-dev force-pushed the feature/webhook-retry-override branch from db2ff26 to bbd4ca6 Compare June 28, 2026 15:47
@greatest0fallt1me greatest0fallt1me merged commit 26966b3 into CalloraOrg:main Jun 29, 2026
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.

Add webhook retry policy override per subscription

2 participants