Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
d84cba6
chore(self-hosting): add health check endpoint (#3562)
PlaneInABottle Mar 13, 2026
9229002
fix(execution): queued execution finalization and async correlation (…
PlaneInABottle Mar 13, 2026
7e740e6
improvement(copilot): state persistence, subflow recreation, dynamic …
icecrasher321 Mar 14, 2026
5b9f0d7
feat(mothership): mothership (#3411)
Sg312 Mar 14, 2026
d06aa1d
fix(connectors): align connector scopes with oauth config and fix kb …
waleedlatif1 Mar 14, 2026
b2d146c
improvement(mothership): message queueing for home chat (#3576)
waleedlatif1 Mar 14, 2026
8f15be2
fix(ashby): add secretToken to webhook creation and fix trigger UX (#…
waleedlatif1 Mar 14, 2026
c738226
fix(file): bun issues with new file creation (#3582)
icecrasher321 Mar 14, 2026
9ae656c
fix(files): default file name (#3585)
icecrasher321 Mar 14, 2026
e6b2b73
fix(execution): report cancellation durability truthfully (#3550)
PlaneInABottle Mar 14, 2026
e13f52f
fix(tools): support stringified HTTP request tables (#3565)
PlaneInABottle Mar 14, 2026
f347e3f
fix(firecrawl) fix firecrawl scrape credit usage calculation (#3583)
TheodoreSpeaks Mar 14, 2026
a2f8ed0
fix lint
icecrasher321 Mar 14, 2026
00ff21a
fix(workflow) Fix embedded workflow logs (#3587)
TheodoreSpeaks Mar 14, 2026
5ba3118
feat(byok-migration) byok migration script (#3584)
TheodoreSpeaks Mar 14, 2026
cbc9f42
improvement(cleanup): remove unused old ui components (#3589)
waleedlatif1 Mar 14, 2026
952915a
fix(sidebar): collapsed sidebar shows single icons with hover dropdow…
waleedlatif1 Mar 14, 2026
75bdf46
improvement(promos): promo codes should be only stripe codes (#3591)
icecrasher321 Mar 14, 2026
f077751
fix(mothership): file materialization tools (#3586)
Sg312 Mar 14, 2026
8837f14
feat(home): expand template examples with 83 categorized templates (#…
waleedlatif1 Mar 15, 2026
f572949
fix(embedded): viewport options breaking autolayout (#3596)
icecrasher321 Mar 15, 2026
aad620c
fix(mothership): run workflow tools (run from block, run until block)…
Sg312 Mar 15, 2026
b7b575c
fix(ui) reduce redundant rerenders (#3593)
TheodoreSpeaks Mar 15, 2026
743742d
Show rendered md by default (#3594)
TheodoreSpeaks Mar 15, 2026
7ecd377
fix(tasks-ui): update in progress to be amber, added status to dropdo…
waleedlatif1 Mar 15, 2026
ad68dc1
improvement(grain): make trigger names in line with API since resourc…
icecrasher321 Mar 15, 2026
8906439
fix(notifications): credentials connection notifs showing up in right…
icecrasher321 Mar 15, 2026
aa1f605
fix(kb): auto-refresh documents after connector sync and remove redun…
waleedlatif1 Mar 15, 2026
38c8922
improvement: landing, sidebar, globals, buttons (#3590)
emir-karabeg Mar 15, 2026
6818c51
improvement(connectors): audit and harden all 30 knowledge base conne…
waleedlatif1 Mar 15, 2026
680c9cd
improvement(ui): align all public pages with dark landing theme and i…
waleedlatif1 Mar 16, 2026
395a61d
fix(deploy): consolidate deployment detection into single source of t…
waleedlatif1 Mar 16, 2026
b0870f4
fix(subagent, streaming) fix deploy subagent and task streamnig (#3610)
TheodoreSpeaks Mar 16, 2026
738d51a
fix(ui): render block handles underneath current block content (#3611)
waleedlatif1 Mar 16, 2026
6df6512
feat(tables): upload csvs (#3607)
icecrasher321 Mar 16, 2026
36e502a
fix(workflow) fix mothership double-running workflows (#3614)
TheodoreSpeaks Mar 17, 2026
c090c82
fix(mothership): add promptForToolApproval to prevent tool hang in mo…
TheodoreSpeaks Mar 17, 2026
c867801
fix(ui) Live update resources in resource main view (#3617)
TheodoreSpeaks Mar 17, 2026
974cc66
fix(ui) add embedded workflow notifications, switch tab on workflow r…
TheodoreSpeaks Mar 17, 2026
2a7b07e
Fix row_count context (#3622)
TheodoreSpeaks Mar 17, 2026
e804ea3
fix(embedded): block layout should not be dependent on viewport (#3621)
icecrasher321 Mar 17, 2026
b930ee3
improvement(tables): tables multi-select, keyboard shortcuts, and doc…
waleedlatif1 Mar 17, 2026
b3d9e54
fix(ui) fix task switch causing duplicate text renderings (#3624)
TheodoreSpeaks Mar 17, 2026
8fa4f3f
fix(mothership): thinking and subagent text (#3613)
Sg312 Mar 17, 2026
3e3c160
fix(embedded): autolayout viewport calculation for resource view (#3629)
waleedlatif1 Mar 17, 2026
1873f2d
improvement(mothership): tool display titles, html sanitization, and …
waleedlatif1 Mar 17, 2026
101fcec
fix(mothership): stream management (#3623)
Sg312 Mar 17, 2026
70d8df5
fix(ui): add back file split view (#3632)
TheodoreSpeaks Mar 17, 2026
3bd2750
fix(ui): ensure new resource tab button is always visible (#3633)
TheodoreSpeaks Mar 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(execution): queued execution finalization and async correlation (#…
…3535)

* fix(execution): finalize runs before wrapper recovery

* fix(async): preserve execution correlation across queued runs

* fix(webhooks): pass correlation into preprocessing

* style(webhooks): normalize webhook executor formatting

* fix(async): avoid pre-starting queued execution logs

Let executeWorkflowCore own normal-path logging start so queued workflow and schedule executions persist the richer deployment and environment metadata instead of an earlier placeholder start record.

* fix(async): harden execution finalization guards

Prevent leaked core finalization markers from accumulating while keeping outer recovery paths idempotent. Preserve best-effort logging completion by reusing settled completion promises instead of reopening duplicate terminal writes.

* fix(async): preserve outcomes during cleanup

Keep execution finalization cleanup best-effort so cancellation cleanup failures do not overwrite successful or failed outcomes. Restore webhook processor formatting to the repository Biome style to avoid noisy formatter churn.

* fix(async): keep execution finalization state consistent

Retry minimal logging for early failures, only mark core finalization after a log row actually completes, and let paused completions fall back cleanly.

* fix(async): clean stale finalization guards

Scan all finalized execution ids during TTL cleanup so refreshed keys cannot keep expired guards alive, and cover the reused-id ordering regression.

* fix(async): retry failed error finalization

Allow error finalization to retry after a non-error completion and fallback both fail, and always persist failed/error semantics for completeWithError.

* fix(webhooks): reuse preprocessing execution ids

Thread preprocessing execution identity into queued webhook execution so both phases share the same correlation and logs.

---------

Co-authored-by: test <test@example.com>
  • Loading branch information
PlaneInABottle and test authored Mar 13, 2026
commit 92290029f09b05638850dfaccfec14c825b43376
46 changes: 45 additions & 1 deletion apps/sim/app/api/schedules/execute/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ vi.mock('@sim/db', () => ({
},
}))

import { GET } from '@/app/api/schedules/execute/route'
vi.mock('uuid', () => ({
v4: vi.fn().mockReturnValue('schedule-execution-1'),
}))

import { GET } from './route'

const SINGLE_SCHEDULE = [
{
Expand Down Expand Up @@ -204,4 +208,44 @@ describe('Scheduled Workflow Execution API Route', () => {
const data = await response.json()
expect(data).toHaveProperty('executedCount', 2)
})

it('should enqueue preassigned correlation metadata for schedules', async () => {
mockDbReturning.mockReturnValue(SINGLE_SCHEDULE)

const response = await GET(createMockRequest())

expect(response.status).toBe(200)
expect(mockEnqueue).toHaveBeenCalledWith(
'schedule-execution',
expect.objectContaining({
scheduleId: 'schedule-1',
workflowId: 'workflow-1',
executionId: 'schedule-execution-1',
requestId: 'test-request-id',
correlation: {
executionId: 'schedule-execution-1',
requestId: 'test-request-id',
source: 'schedule',
workflowId: 'workflow-1',
scheduleId: 'schedule-1',
triggerType: 'schedule',
scheduledFor: '2025-01-01T00:00:00.000Z',
},
}),
{
metadata: {
workflowId: 'workflow-1',
correlation: {
executionId: 'schedule-execution-1',
requestId: 'test-request-id',
source: 'schedule',
workflowId: 'workflow-1',
scheduleId: 'schedule-1',
triggerType: 'schedule',
scheduledFor: '2025-01-01T00:00:00.000Z',
},
},
}
)
})
})
16 changes: 15 additions & 1 deletion apps/sim/app/api/schedules/execute/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { db, workflowDeploymentVersion, workflowSchedule } from '@sim/db'
import { createLogger } from '@sim/logger'
import { and, eq, isNull, lt, lte, not, or, sql } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { v4 as uuidv4 } from 'uuid'
import { verifyCronAuth } from '@/lib/auth/internal'
import { getJobQueue, shouldExecuteInline } from '@/lib/core/async-jobs'
import { generateRequestId } from '@/lib/core/utils/request'
Expand Down Expand Up @@ -57,10 +58,23 @@ export async function GET(request: NextRequest) {

const queuePromises = dueSchedules.map(async (schedule) => {
const queueTime = schedule.lastQueuedAt ?? queuedAt
const executionId = uuidv4()
const correlation = {
executionId,
requestId,
source: 'schedule' as const,
workflowId: schedule.workflowId,
scheduleId: schedule.id,
triggerType: 'schedule',
scheduledFor: schedule.nextRunAt?.toISOString(),
}

const payload = {
scheduleId: schedule.id,
workflowId: schedule.workflowId,
executionId,
requestId,
correlation,
blockId: schedule.blockId || undefined,
cronExpression: schedule.cronExpression || undefined,
lastRanAt: schedule.lastRanAt?.toISOString(),
Expand All @@ -71,7 +85,7 @@ export async function GET(request: NextRequest) {

try {
const jobId = await jobQueue.enqueue('schedule-execution', payload, {
metadata: { workflowId: schedule.workflowId },
metadata: { workflowId: schedule.workflowId, correlation },
})
logger.info(
`[${requestId}] Queued schedule execution task ${jobId} for workflow ${schedule.workflowId}`
Expand Down
95 changes: 74 additions & 21 deletions apps/sim/app/api/webhooks/trigger/[path]/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const {
processWebhookMock,
executeMock,
getWorkspaceBilledAccountUserIdMock,
queueWebhookExecutionMock,
} = vi.hoisted(() => ({
generateRequestHashMock: vi.fn().mockResolvedValue('test-hash-123'),
validateSlackSignatureMock: vi.fn().mockResolvedValue(true),
Expand All @@ -125,6 +126,10 @@ const {
.mockImplementation(async (workspaceId: string | null | undefined) =>
workspaceId ? 'test-user-id' : null
),
queueWebhookExecutionMock: vi.fn().mockImplementation(async () => {
const { NextResponse } = await import('next/server')
return NextResponse.json({ message: 'Webhook processed' })
}),
}))

vi.mock('@trigger.dev/sdk', () => ({
Expand Down Expand Up @@ -350,21 +355,28 @@ vi.mock('@/lib/webhooks/processor', () => ({
return null
}
),
checkWebhookPreprocessing: vi
.fn()
.mockResolvedValue({ error: null, actorUserId: 'test-user-id' }),
checkWebhookPreprocessing: vi.fn().mockResolvedValue({
error: null,
actorUserId: 'test-user-id',
executionId: 'preprocess-execution-id',
correlation: {
executionId: 'preprocess-execution-id',
requestId: 'mock-request-id',
source: 'webhook',
workflowId: 'test-workflow-id',
webhookId: 'generic-webhook-id',
path: 'test-path',
provider: 'generic',
triggerType: 'webhook',
},
}),
formatProviderErrorResponse: vi.fn().mockImplementation((_webhook, error, status) => {
const { NextResponse } = require('next/server')
return NextResponse.json({ error }, { status })
}),
shouldSkipWebhookEvent: vi.fn().mockReturnValue(false),
handlePreDeploymentVerification: vi.fn().mockReturnValue(null),
queueWebhookExecution: vi.fn().mockImplementation(async () => {
// Call processWebhookMock so tests can verify it was called
processWebhookMock()
const { NextResponse } = await import('next/server')
return NextResponse.json({ message: 'Webhook processed' })
}),
queueWebhookExecution: queueWebhookExecutionMock,
}))

vi.mock('drizzle-orm/postgres-js', () => ({
Expand Down Expand Up @@ -419,7 +431,7 @@ describe('Webhook Trigger API Route', () => {

const params = Promise.resolve({ path: 'non-existent-path' })

const response = await POST(req, { params })
const response = await POST(req as any, { params })

expect(response.status).toBe(404)

Expand Down Expand Up @@ -494,6 +506,47 @@ describe('Webhook Trigger API Route', () => {
})

describe('Generic Webhook Authentication', () => {
it('passes correlation-bearing request context into webhook queueing', async () => {
testData.webhooks.push({
id: 'generic-webhook-id',
provider: 'generic',
path: 'test-path',
isActive: true,
providerConfig: { requireAuth: false },
workflowId: 'test-workflow-id',
})

const req = createMockRequest('POST', { event: 'test', id: 'test-123' })
const params = Promise.resolve({ path: 'test-path' })

const response = await POST(req as any, { params })

expect(response.status).toBe(200)
expect(queueWebhookExecutionMock).toHaveBeenCalledOnce()
const call = queueWebhookExecutionMock.mock.calls[0]
expect(call[0]).toEqual(expect.objectContaining({ id: 'generic-webhook-id' }))
expect(call[1]).toEqual(expect.objectContaining({ id: 'test-workflow-id' }))
expect(call[2]).toEqual(expect.objectContaining({ event: 'test', id: 'test-123' }))
expect(call[4]).toEqual(
expect.objectContaining({
requestId: 'mock-request-id',
path: 'test-path',
actorUserId: 'test-user-id',
executionId: 'preprocess-execution-id',
correlation: {
executionId: 'preprocess-execution-id',
requestId: 'mock-request-id',
source: 'webhook',
workflowId: 'test-workflow-id',
webhookId: 'generic-webhook-id',
path: 'test-path',
provider: 'generic',
triggerType: 'webhook',
},
})
)
})

it('should process generic webhook without authentication', async () => {
testData.webhooks.push({
id: 'generic-webhook-id',
Expand All @@ -514,7 +567,7 @@ describe('Webhook Trigger API Route', () => {
const req = createMockRequest('POST', { event: 'test', id: 'test-123' })
const params = Promise.resolve({ path: 'test-path' })

const response = await POST(req, { params })
const response = await POST(req as any, { params })

expect(response.status).toBe(200)

Expand Down Expand Up @@ -544,7 +597,7 @@ describe('Webhook Trigger API Route', () => {
const req = createMockRequest('POST', { event: 'bearer.test' }, headers)
const params = Promise.resolve({ path: 'test-path' })

const response = await POST(req, { params })
const response = await POST(req as any, { params })

expect(response.status).toBe(200)
})
Expand Down Expand Up @@ -575,7 +628,7 @@ describe('Webhook Trigger API Route', () => {
const req = createMockRequest('POST', { event: 'custom.header.test' }, headers)
const params = Promise.resolve({ path: 'test-path' })

const response = await POST(req, { params })
const response = await POST(req as any, { params })

expect(response.status).toBe(200)
})
Expand Down Expand Up @@ -610,7 +663,7 @@ describe('Webhook Trigger API Route', () => {
const req = createMockRequest('POST', { event: 'case.test' }, headers)
const params = Promise.resolve({ path: 'test-path' })

const response = await POST(req, { params })
const response = await POST(req as any, { params })

expect(response.status).toBe(200)
}
Expand Down Expand Up @@ -645,7 +698,7 @@ describe('Webhook Trigger API Route', () => {
const req = createMockRequest('POST', { event: 'custom.case.test' }, headers)
const params = Promise.resolve({ path: 'test-path' })

const response = await POST(req, { params })
const response = await POST(req as any, { params })

expect(response.status).toBe(200)
}
Expand All @@ -668,7 +721,7 @@ describe('Webhook Trigger API Route', () => {
const req = createMockRequest('POST', { event: 'wrong.token.test' }, headers)
const params = Promise.resolve({ path: 'test-path' })

const response = await POST(req, { params })
const response = await POST(req as any, { params })

expect(response.status).toBe(401)
expect(await response.text()).toContain('Unauthorized - Invalid authentication token')
Expand Down Expand Up @@ -696,7 +749,7 @@ describe('Webhook Trigger API Route', () => {
const req = createMockRequest('POST', { event: 'wrong.custom.test' }, headers)
const params = Promise.resolve({ path: 'test-path' })

const response = await POST(req, { params })
const response = await POST(req as any, { params })

expect(response.status).toBe(401)
expect(await response.text()).toContain('Unauthorized - Invalid authentication token')
Expand All @@ -716,7 +769,7 @@ describe('Webhook Trigger API Route', () => {
const req = createMockRequest('POST', { event: 'no.auth.test' })
const params = Promise.resolve({ path: 'test-path' })

const response = await POST(req, { params })
const response = await POST(req as any, { params })

expect(response.status).toBe(401)
expect(await response.text()).toContain('Unauthorized - Invalid authentication token')
Expand Down Expand Up @@ -744,7 +797,7 @@ describe('Webhook Trigger API Route', () => {
const req = createMockRequest('POST', { event: 'exclusivity.test' }, headers)
const params = Promise.resolve({ path: 'test-path' })

const response = await POST(req, { params })
const response = await POST(req as any, { params })

expect(response.status).toBe(401)
expect(await response.text()).toContain('Unauthorized - Invalid authentication token')
Expand Down Expand Up @@ -772,7 +825,7 @@ describe('Webhook Trigger API Route', () => {
const req = createMockRequest('POST', { event: 'wrong.header.name.test' }, headers)
const params = Promise.resolve({ path: 'test-path' })

const response = await POST(req, { params })
const response = await POST(req as any, { params })

expect(response.status).toBe(401)
expect(await response.text()).toContain('Unauthorized - Invalid authentication token')
Expand All @@ -797,7 +850,7 @@ describe('Webhook Trigger API Route', () => {
const req = createMockRequest('POST', { event: 'no.token.config.test' }, headers)
const params = Promise.resolve({ path: 'test-path' })

const response = await POST(req, { params })
const response = await POST(req as any, { params })

expect(response.status).toBe(401)
expect(await response.text()).toContain(
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/app/api/webhooks/trigger/[path]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export async function POST(
requestId,
path,
actorUserId: preprocessResult.actorUserId,
executionId: preprocessResult.executionId,
correlation: preprocessResult.correlation,
})
responses.push(response)
}
Expand Down
Loading
Loading