Let server route resolvers answer the caller synchronously (#23233)

## Problem

A server route resolver can only return a dispatch target (`{
workspaceId, targetLogicFunctionUniversalIdentifier, payload }`), and
`ServerRouteTriggerService` always acks `202 {queued:true}`. The target
function runs off the queue, after the response has been sent, so its
return value can never reach the caller.

That makes it impossible to integrate a provider whose webhook URL has
to be proven with a handshake on the same response. Slack's Events API
is the case that surfaced it: `url_verification` sends `{ type,
challenge }` and will not accept the Request URL unless the challenge
comes back on that POST.

## Change

A resolver may now return a `Response` (the existing
`LogicFunctionHttpResponse`) instead of a dispatch target. The route
sends it as-is via `buildRouteTriggerResponse` and enqueues nothing.

- Reuses the marker and builder that HTTP route triggers already use, so
there is no new response shape.
- Dispatch results behave exactly as before; the resolver error path is
unchanged, just hoisted out of `parseResolverResult` so it runs before
the branch.
- SDK: `ServerRouteResolverResult` becomes `ServerRouteDispatchResult |
LogicFunctionHttpResponse`.

Additive: a resolver that returns a dispatch target sees no behavior
change. Previously, returning this shape threw
`RESOLVER_INVALID_RESULT`.

## Testing

`server-route-trigger.service.spec.ts` gains a case asserting the
resolver's response is sent verbatim and nothing is enqueued. 15/15
pass.

## Context

Split out of #22984 (Slack conversational assistant), which needs this
to complete the Slack Events URL verification. That PR depends on this
one merging first.

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/23233?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
This commit is contained in:
Abdul Rahman
2026-07-24 12:26:34 +05:30
committed by GitHub
parent 5bc97f8591
commit 148dc6dfaa
11 changed files with 249 additions and 74 deletions
@@ -6,6 +6,7 @@ import { syncApplication } from 'test/integration/metadata/suites/application/ut
import { uploadApplicationFile } from 'test/integration/metadata/suites/application/utils/upload-application-file.util';
import { expectOneNotInternalServerErrorHttpResponseSnapshot } from 'test/integration/utils/expect-one-not-internal-server-error-http-response-snapshot.util';
import { type LogicFunctionManifest } from 'twenty-shared/application';
import { LOGIC_FUNCTION_HTTP_RESPONSE_MARKER } from 'twenty-shared/types';
import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
@@ -22,6 +23,8 @@ const AUTH_REQUIRED_RESOLVER_UNIVERSAL_IDENTIFIER =
'3c3f983f-5c1a-4c60-a3c8-7d0e2a4a33c3';
const TARGET_FUNCTION_UNIVERSAL_IDENTIFIER =
'4d4f983f-5c1a-4c60-a3c8-7d0e2a4a44d4';
const HANDSHAKE_RESOLVER_UNIVERSAL_IDENTIFIER =
'5e5f983f-5c1a-4c60-a3c8-7d0e2a4a55e5';
const TARGET_FUNCTION_RESPONSE = { greeting: 'hello from target function' };
@@ -33,6 +36,13 @@ const RESOLVER_BUILT_HANDLER_CODE = `export const main = async () => ({
});
`;
const HANDSHAKE_RESOLVER_BUILT_HANDLER_CODE = `export const main = async (event) => ({
${LOGIC_FUNCTION_HTTP_RESPONSE_MARKER}: true,
status: 200,
body: { challenge: event.body.challenge },
});
`;
const TARGET_BUILT_HANDLER_CODE = `export const main = async () => (${JSON.stringify(
TARGET_FUNCTION_RESPONSE,
)});
@@ -107,6 +117,11 @@ describe('ServerRouteTrigger authorization (integration)', () => {
builtHandlerCode: RESOLVER_BUILT_HANDLER_CODE,
});
await uploadBuiltHandlerFile({
builtHandlerPath: 'dist/handshake-resolver.mjs',
builtHandlerCode: HANDSHAKE_RESOLVER_BUILT_HANDLER_CODE,
});
await uploadBuiltHandlerFile({
builtHandlerPath: 'dist/target-function.mjs',
builtHandlerCode: TARGET_BUILT_HANDLER_CODE,
@@ -136,6 +151,12 @@ describe('ServerRouteTrigger authorization (integration)', () => {
serverRouteExposed: true,
authRequired: true,
}),
buildLogicFunctionManifest({
universalIdentifier: HANDSHAKE_RESOLVER_UNIVERSAL_IDENTIFIER,
name: 'handshake-resolver',
serverRouteExposed: true,
authRequired: false,
}),
buildLogicFunctionManifest({
universalIdentifier: TARGET_FUNCTION_UNIVERSAL_IDENTIFIER,
name: 'target-function',
@@ -177,6 +198,15 @@ describe('ServerRouteTrigger authorization (integration)', () => {
expect(response.body).toEqual({ queued: true });
}, 60000);
it('answers the caller with the response returned by the resolver', async () => {
const response = await request(baseUrl)
.post(`/webhooks/server/${HANDSHAKE_RESOLVER_UNIVERSAL_IDENTIFIER}`)
.send({ type: 'url_verification', challenge: 'abc123' });
expect(response.status).toBe(200);
expect(response.body).toEqual({ challenge: 'abc123' });
}, 60000);
it('rejects a server-route-exposed resolver that requires authentication before executing it', async () => {
const response = await request(baseUrl)
.post(`/webhooks/server/${AUTH_REQUIRED_RESOLVER_UNIVERSAL_IDENTIFIER}`)