Skip to content

refactor: consolidate fallback webhook firing with form submission webhooks#28058

Draft
joeauyeung wants to merge 1 commit intodevin/1770145632-routing-form-fallback-webhookfrom
devin/1771471675-consolidate-fallback-webhook
Draft

refactor: consolidate fallback webhook firing with form submission webhooks#28058
joeauyeung wants to merge 1 commit intodevin/1770145632-routing-form-fallback-webhookfrom
devin/1771471675-consolidate-fallback-webhook

Conversation

@joeauyeung
Copy link
Contributor

What does this PR do?

Consolidates the ROUTING_FORM_FALLBACK_HIT webhook so it fires in the same Promise.all() batch as FORM_SUBMITTED and FORM_SUBMITTED_NO_EVENT webhooks, instead of being triggered as a separate call after form submission.

Previously, triggerFallbackWebhook was called independently in handleResponse.ts after onSubmissionOfFormResponse completed. This duplicated webhook infrastructure calls (getWebhookTargetEntity, getOrgIdFromMemberOrTeamId, getWebhooks) that already happen inside _onFormSubmission. Now all three webhook types are fetched and sent in a single batch.

Changes:

  • formSubmissionUtils.ts: Added fallbackAction param to _onFormSubmission and onSubmissionOfFormResponse. Fallback webhooks are fetched in parallel with other webhook types and sent in the same Promise.all(). Removed the standalone triggerFallbackWebhook export.
  • handleResponse.ts: Moved getFallbackAction() before onSubmissionOfFormResponse call. Passes fallbackAction through. Removed separate triggerFallbackWebhook invocation and unused imports.
  • Tests: Updated to verify fallbackAction flows through onSubmissionOfFormResponse rather than asserting on the removed triggerFallbackWebhook.

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. N/A
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

Unit tests:

TZ=UTC yarn vitest run packages/app-store/routing-forms/lib/formSubmissionUtils.test.ts
TZ=UTC yarn vitest run packages/features/routing-forms/lib/handleResponse.test.ts

All 30 tests pass (14 in formSubmissionUtils.test.ts, 16 in handleResponse.test.ts).

Manual testing (if desired):

  1. Set up a routing form with a fallback action configured
  2. Submit a response that triggers the fallback (e.g., no team members match attribute logic)
  3. Verify ROUTING_FORM_FALLBACK_HIT webhook fires alongside FORM_SUBMITTED webhooks

Human Review Checklist

Critical areas to review:

  1. getFallbackAction() placement (handleResponse.ts:187-215): Verify the function is called at the right time for all code paths (preview mode, queued responses, normal responses).

  2. fallbackAction parameter flow: Trace fallbackAction from handleResponse.ts:235onSubmissionOfFormResponse_onFormSubmission to ensure it's passed correctly.

  3. Webhook batching logic (formSubmissionUtils.ts:180-193): Confirm the conditional subscriberOptionsFallbackHit correctly handles the case when fallbackAction is null/undefined.

  4. Test coverage: Two test cases were removed from the old triggerFallbackWebhook tests:

    • "should call getWebhooks with user target when form has no teamId"
    • "should not call sendGenericWebhookPayload when no webhooks are subscribed"

    The behavior is still covered by existing _onFormSubmission tests, but worth confirming this is acceptable.

  5. Queued form responses: When queueFormResponse=true, onSubmissionOfFormResponse is not called, so no fallback webhook fires. Verify this matches the previous behavior (it does — triggerFallbackWebhook only fired when dbFormResponse existed).


Devin session: https://app.devin.ai/sessions/c9f624b956e04c5b8239ae8fc3519ef3
Requested by: @joeauyeung

…with normal webhooks

Co-Authored-By: joe@cal.com <j.auyeung419@gmail.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments