Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 15 additions & 1 deletion apps/docs/openapi-core.json
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,16 @@
"type": "string",
"example": "e4f8d2b6-9a1c-4e3d-8b7f-5c0a2d9e6f13"
}
},
{
"name": "includeSnapshot",
"in": "query",
"required": false,
"description": "Whether to include `executionSnapshot`, which carries every block's output and can be large. Defaults to `true`.",
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
Expand Down Expand Up @@ -1792,6 +1802,10 @@
"type": "string",
"description": "The block ID where execution paused."
},
"blockName": {
"type": "string",
"description": "Name of the paused block as the run executed it. Absent for a point paused before names were recorded whose run had no deployment version."
},
"response": {
"description": "Data returned by the block before pausing, including display data and form fields."
},
Expand Down Expand Up @@ -1949,7 +1963,7 @@
"properties": {
"executionSnapshot": {
"type": "object",
"description": "Serialized execution state for resumption.",
"description": "Serialized execution state for resumption. Omitted when the resume path is read with `includeSnapshot=false`.",
"properties": {
"snapshot": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/openapi-v2-workflows.json
Original file line number Diff line number Diff line change
Expand Up @@ -16140,7 +16140,7 @@
"type": "null"
}
],
"description": "Name of the block in the deployment version the run executed, or null for a manual run or when the version no longer exists."
"description": "Name of the block as the run executed it. Null only for a point paused before names were recorded whose run was manual or whose deployment version no longer exists."
},
"kind": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('ResumeExecutionPageWrapper', () => {

expect(mocks.authorize).toHaveBeenCalledWith({
principal: createSessionPrincipal(),
input: PAGE_PARAMS,
input: { ...PAGE_PARAMS, includeSnapshot: false },
})
expect(result.props).toMatchObject({
params: PAGE_PARAMS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default async function ResumeExecutionPageWrapper({
userId: session.user.id,
sessionId: session.session.id,
},
input: { workflowId, executionId },
input: { workflowId, executionId, includeSnapshot: false },
})
} catch (error) {
const classified = asOrchestrationError(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,6 @@ function StatusBadge({ status }: { status: string }) {
)
}

function getBlockNameFromSnapshot(
executionSnapshot: { snapshot?: string } | null | undefined,
blockId: string | undefined
): string | null {
if (!executionSnapshot?.snapshot || !blockId) return null
try {
const parsed = JSON.parse(executionSnapshot.snapshot)
const workflowState = parsed?.workflow
if (!workflowState?.blocks || !Array.isArray(workflowState.blocks)) return null
const block = workflowState.blocks.find((b: { id: string }) => b.id === blockId)
return block?.metadata?.name || null
} catch {
return null
}
}

const DISPLAY_VALUE_PREVIEW_MAX_CHARS = 5000

function truncateForPreview(text: string): { text: string; truncated: boolean } {
Expand Down Expand Up @@ -697,13 +681,7 @@ export default function ResumeExecutionPage({
selectedStatus === 'queued' ||
(isHumanMode && hasInputFormat && (!isFormComplete || Object.keys(formErrors).length > 0))

const getBlockName = (pause: PausePointWithQueue) => {
const pauseBlockId = pause.blockId || pause.triggerBlockId
return (
getBlockNameFromSnapshot(executionDetail?.executionSnapshot, pauseBlockId) ||
'Human in the Loop'
)
}
const getBlockName = (pause: PausePointWithQueue) => pause.blockName || 'Human in the Loop'

if (loadingExecution) {
return (
Expand Down
19 changes: 19 additions & 0 deletions apps/sim/app/api/resume/[workflowId]/[executionId]/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,23 @@ describe('GET /api/resume/[workflowId]/[executionId]', () => {
expect(response.status).toBe(403)
expect(await response.json()).toEqual({ error: 'Insufficient workspace permissions' })
})

it('reads the execution snapshot unless the resume page opts out', async () => {
await GET(
createMockRequest(
'GET',
undefined,
{},
'http://localhost/api/resume/workflow-1/execution-1?includeSnapshot=false'
),
createRouteContext(params)
)
for (const { call } of routeCases) await call()

expect(mocks.execute.mock.calls.map(([call]) => call.input.includeSnapshot)).toEqual([
false,
true,
true,
])
})
})
3 changes: 2 additions & 1 deletion apps/sim/app/api/resume/[workflowId]/[executionId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ export const GET = defineInternalJsonRoute({
reason: 'Preserve existing authenticated resume-detail behavior',
}),
errorPolicy: internalWorkflowErrorPolicies.concealWorkflowAuthorization,
mapInput: ({ params }) => ({
mapInput: ({ params, query }) => ({
workflowId: params.workflowId,
executionId: params.executionId,
includeSnapshot: query.includeSnapshot,
}),
useCase: readPausedWorkflowExecution,
responseHeaders: () => ({ 'Cache-Control': 'private, no-store' }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const GET = defineInternalJsonRoute({
mapInput: ({ params }) => ({
workflowId: params.id,
executionId: params.executionId,
includeSnapshot: true,
}),
useCase: readPausedWorkflowExecution,
responseHeaders: () => ({ 'Cache-Control': 'private, no-store' }),
Expand Down
5 changes: 4 additions & 1 deletion apps/sim/executor/execution/engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ describe('ExecutionEngine', () => {
expect(nodeOrchestrator.executeNode).toHaveBeenCalledWith(context, 'both')
})

it('records paused block completion before returning paused result', async () => {
it('records paused block completion and the paused block name before returning paused result', async () => {
const node = createMockNode('hitl', 'function')
const dag = createMockDAG([node])
const context = createMockContext({
Expand Down Expand Up @@ -441,6 +441,9 @@ describe('ExecutionEngine', () => {
const result = await engine.run('hitl')

expect(result.status).toBe('paused')
expect(result.pausePoints).toEqual([
expect.objectContaining({ contextId: 'pause-1', blockId: 'hitl', blockName: 'Block hitl' }),
])
expect(nodeOrchestrator.handleNodeCompletion).toHaveBeenCalledWith(
context,
'hitl',
Expand Down
1 change: 1 addition & 0 deletions apps/sim/executor/execution/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ export class ExecutionEngine {
...capturePauseDisplay(pause, registry),
contextId: pause.contextId,
blockId: pause.blockId,
blockName: this.dag.nodes.get(pause.blockId)?.block.metadata?.name,
response: pause.response,
registeredAt: pause.timestamp,
resumeStatus: 'paused' as ResumeStatus,
Expand Down
6 changes: 6 additions & 0 deletions apps/sim/executor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ export type ResumeStatus = 'paused' | 'resumed' | 'failed' | 'queued' | 'resumin
export interface PausePoint {
contextId: string
blockId?: string
/**
* The paused block's name as the run executed it, recorded when the pause is captured.
* Points persisted before names were recorded lack it; readers name those from the run's
* deployment version instead of the execution snapshot.
*/
blockName?: string
response: any
registeredAt: string
resumeStatus: ResumeStatus
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/hooks/queries/resume-execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export interface ResumeQueueEntrySummary {

export interface PausePointWithQueue {
contextId: string
triggerBlockId?: string
blockId?: string
response: any
registeredAt: string
Expand All @@ -51,6 +50,7 @@ export interface PausePointWithQueue {
resumeLinks?: ResumeLinks
queuePosition?: number | null
latestResumeEntry?: ResumeQueueEntrySummary | null
blockName?: string
parallelScope?: any
loopScope?: any
pauseKind?: 'human' | 'time'
Expand All @@ -73,7 +73,6 @@ export interface PausedExecutionSummary {
}

export interface PausedExecutionDetail extends PausedExecutionSummary {
executionSnapshot: any
queue: ResumeQueueEntrySummary[]
}

Expand Down Expand Up @@ -118,6 +117,7 @@ export function useResumeExecutionDetail(workflowId: string, executionId: string
queryFn: async ({ signal }): Promise<PausedExecutionDetail> => {
const raw = await requestJson(resumeWorkflowExecutionContract, {
params: { workflowId, executionId },
query: { includeSnapshot: false },
signal,
})
// double-cast-allowed: contract models pause points as z.record; the resume UI uses the richer PausedExecutionDetail interface
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/lib/api/contracts/v2/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,7 @@ const v2WorkflowRunPausePointSchema = z
.string()
.nullable()
.describe(
'Name of the block in the deployment version the run executed, or null for a manual run or when the version no longer exists.'
'Name of the block as the run executed it. Null only for a point paused before names were recorded whose run was manual or whose deployment version no longer exists.'
),
kind: z
.enum(['human', 'time'])
Expand Down
14 changes: 13 additions & 1 deletion apps/sim/lib/api/contracts/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@sim/workflow-types/workflow'
import { z } from 'zod'
import {
booleanQueryFlagSchema,
privateSecretProvenanceBundleSchema,
requiredFieldSchema,
workflowIdSchema,
Expand Down Expand Up @@ -442,6 +443,15 @@ export const resumeExecutionParamsSchema = z.object({
executionId: z.string().min(1),
})

/**
* `includeSnapshot=false` leaves out the execution snapshot, which carries every
* block's output and can run to many megabytes. The resume page asks for that;
* API callers keep the documented default of receiving it.
*/
const resumeExecutionQuerySchema = z.object({
includeSnapshot: booleanQueryFlagSchema.optional().default(true),
})

export const resumeExecutionContextParamsSchema = z.object({
workflowId: z.string().min(1),
executionId: z.string().min(1),
Expand Down Expand Up @@ -554,7 +564,8 @@ const pausedWorkflowExecutionsResponseSchema = z.object({
})

const pausedWorkflowExecutionDetailSchema = pausedWorkflowExecutionSummarySchema.extend({
executionSnapshot: z.unknown(),
/** Present when the read asked for it; see {@link resumeExecutionQuerySchema}. */
executionSnapshot: z.unknown().optional(),
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
queue: z.array(z.record(z.string(), z.unknown())),
})

Expand Down Expand Up @@ -959,6 +970,7 @@ export const resumeWorkflowExecutionContract = defineRouteContract({
method: 'GET',
path: '/api/resume/[workflowId]/[executionId]',
params: resumeExecutionParamsSchema,
query: resumeExecutionQuerySchema,
response: {
mode: 'json',
schema: pausedWorkflowExecutionDetailSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('readPausedWorkflowExecution', () => {
async (principal) => {
const result = await readPausedWorkflowExecution.execute({
principal,
input: { workflowId: 'workflow-1', executionId: 'execution-1' },
input: { workflowId: 'workflow-1', executionId: 'execution-1', includeSnapshot: true },
})

expect(result).toBe(detail)
Expand All @@ -87,7 +87,7 @@ describe('readPausedWorkflowExecution', () => {
it('finishes session authorization before loading paused execution detail', async () => {
await readPausedWorkflowExecution.execute({
principal: allowedPrincipals[0],
input: { workflowId: 'workflow-1', executionId: 'execution-1' },
input: { workflowId: 'workflow-1', executionId: 'execution-1', includeSnapshot: true },
})

expect(mockResolvePermission.mock.invocationCallOrder[0]).toBeLessThan(
Expand All @@ -110,7 +110,7 @@ describe('readPausedWorkflowExecution', () => {
await expect(
readPausedWorkflowExecution.execute({
principal,
input: { workflowId: 'workflow-1', executionId: 'execution-1' },
input: { workflowId: 'workflow-1', executionId: 'execution-1', includeSnapshot: true },
})
).rejects.toMatchObject({ name: 'DelegatedServiceAuthorizationError' })
expect(mockResolveWorkflowContext).not.toHaveBeenCalled()
Expand All @@ -128,7 +128,7 @@ describe('readPausedWorkflowExecution', () => {
await expect(
readPausedWorkflowExecution.execute({
principal,
input: { workflowId: 'workflow-1', executionId: 'execution-1' },
input: { workflowId: 'workflow-1', executionId: 'execution-1', includeSnapshot: true },
})
).rejects.toMatchObject({ name: 'PrincipalKindAuthorizationError' })
expect(mockResolveWorkflowContext).not.toHaveBeenCalled()
Expand All @@ -142,7 +142,7 @@ describe('readPausedWorkflowExecution', () => {
workspaceId: 'workspace-2',
keyId: 'workspace-key-2',
}),
input: { workflowId: 'workflow-1', executionId: 'execution-1' },
input: { workflowId: 'workflow-1', executionId: 'execution-1', includeSnapshot: true },
})
).rejects.toMatchObject({ code: 'forbidden' })
expect(mockGetPausedExecutionDetail).not.toHaveBeenCalled()
Expand All @@ -154,7 +154,7 @@ describe('readPausedWorkflowExecution', () => {
await expect(
readPausedWorkflowExecution.execute({
principal: allowedPrincipals[0],
input: { workflowId: 'workflow-1', executionId: 'execution-1' },
input: { workflowId: 'workflow-1', executionId: 'execution-1', includeSnapshot: true },
})
).rejects.toMatchObject({ name: 'NoWorkspaceAccessError' })
expect(mockGetPausedExecutionDetail).not.toHaveBeenCalled()
Expand All @@ -169,7 +169,7 @@ describe('readPausedWorkflowExecution', () => {
await expect(
readPausedWorkflowExecution.execute({
principal: allowedPrincipals[1],
input: { workflowId: 'workflow-1', executionId: 'execution-1' },
input: { workflowId: 'workflow-1', executionId: 'execution-1', includeSnapshot: true },
})
).rejects.toMatchObject({ name: 'PersonalApiKeysDisabledError' })
expect(mockGetPausedExecutionDetail).not.toHaveBeenCalled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ import { PauseResumeManager } from '@/lib/workflows/executor/human-in-the-loop-m
export interface ReadPausedWorkflowExecutionInput {
workflowId: string
executionId: string
/**
* Also read the execution snapshot. It carries every block's output and can run to
* many megabytes, so only a caller that returns it asks for it.
*/
includeSnapshot: boolean
}

export const readPausedWorkflowExecution = defineAuthorizedWorkflowUseCase({
operation: workflowOperations.readPausedExecution,
resolveContext: ({ input }: { input: ReadPausedWorkflowExecutionInput }) =>
resolveActiveWorkflowApplicationContext({ workflowId: input.workflowId }),
async execute({ context, input }) {
const detail = await PauseResumeManager.getPausedExecutionDetail({
workflowId: context.workflowId,
executionId: input.executionId,
})
const target = { workflowId: context.workflowId, executionId: input.executionId }
const detail = input.includeSnapshot
? await PauseResumeManager.getPausedExecutionDetail(target)
: await PauseResumeManager.getPausedExecutionView(target)
if (!detail) throw new OrchestrationError('not_found', 'Paused execution not found')
return detail
},
Expand Down
Loading
Loading