Skip to content

Commit be83c97

Browse files
committed
remove manual execs off queues
1 parent 75eac74 commit be83c97

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

apps/sim/app/api/workflows/[id]/execute/route.async.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const {
2121

2222
vi.mock('@/lib/auth/hybrid', () => ({
2323
checkHybridAuth: mockCheckHybridAuth,
24+
hasExternalApiCredentials: vi.fn().mockReturnValue(true),
2425
AuthType: {
2526
SESSION: 'session',
2627
API_KEY: 'api_key',

apps/sim/app/api/workflows/[id]/execute/route.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createLogger } from '@sim/logger'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { validate as uuidValidate, v4 as uuidv4 } from 'uuid'
44
import { z } from 'zod'
5-
import { AuthType, checkHybridAuth } from '@/lib/auth/hybrid'
5+
import { AuthType, checkHybridAuth, hasExternalApiCredentials } from '@/lib/auth/hybrid'
66
import { admissionRejectedResponse, tryAdmit } from '@/lib/core/admission/gate'
77
import { getJobQueue, shouldExecuteInline, shouldUseBullMQ } from '@/lib/core/async-jobs'
88
import { createBullMQJobData } from '@/lib/core/bullmq'
@@ -326,6 +326,10 @@ async function enqueueDirectWorkflowExecution(
326326
* Supports both SSE streaming (for interactive/manual runs) and direct JSON responses (for background jobs).
327327
*/
328328
export async function POST(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
329+
if (!hasExternalApiCredentials(req.headers)) {
330+
return handleExecutePost(req, params)
331+
}
332+
329333
const ticket = tryAdmit()
330334
if (!ticket) {
331335
return admissionRejectedResponse()
@@ -784,7 +788,7 @@ async function handleExecutePost(
784788

785789
const executionVariables = cachedWorkflowData?.variables ?? workflow.variables ?? {}
786790

787-
if (shouldUseBullMQ()) {
791+
if (shouldUseBullMQ() && triggerType !== 'manual') {
788792
try {
789793
const dispatchJobId = await enqueueDirectWorkflowExecution(
790794
{
@@ -799,7 +803,7 @@ async function handleExecutePost(
799803
timeoutMs: preprocessResult.executionTimeout?.sync,
800804
runFromBlock: resolvedRunFromBlock,
801805
},
802-
triggerType === 'manual' ? 1 : 5,
806+
5,
803807
'interactive'
804808
)
805809

@@ -973,7 +977,8 @@ async function handleExecutePost(
973977
}
974978

975979
if (shouldUseDraftState) {
976-
if (shouldUseBullMQ()) {
980+
const useDispatchForManual = shouldUseBullMQ() && triggerType !== 'manual'
981+
if (useDispatchForManual) {
977982
const metadata: ExecutionMetadata = {
978983
requestId,
979984
executionId,

apps/sim/lib/auth/hybrid.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ export const AuthType = {
1414

1515
export type AuthTypeValue = (typeof AuthType)[keyof typeof AuthType]
1616

17+
const API_KEY_HEADER = 'x-api-key'
18+
const BEARER_PREFIX = 'Bearer '
19+
20+
/**
21+
* Lightweight header-only check for whether a request carries external API credentials.
22+
* Does NOT validate the credentials — only inspects headers to classify the request
23+
* as programmatic API traffic vs interactive session traffic.
24+
*/
25+
export function hasExternalApiCredentials(headers: Headers): boolean {
26+
if (headers.has(API_KEY_HEADER)) return true
27+
const auth = headers.get('authorization')
28+
return auth !== null && auth.startsWith(BEARER_PREFIX)
29+
}
30+
1731
export interface AuthResult {
1832
success: boolean
1933
userId?: string

0 commit comments

Comments
 (0)