From a6ed00b4f082671d2da0fb2f9971a5f7466683da Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Wed, 8 Apr 2026 23:10:55 -0700 Subject: [PATCH] improvement(release): address comments --- .../docs/en/blocks/human-in-the-loop.mdx | 22 ++++++++++++---- apps/sim/app/api/form/[identifier]/route.ts | 25 ++----------------- .../[executionId]/[contextId]/route.ts | 2 +- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/apps/docs/content/docs/en/blocks/human-in-the-loop.mdx b/apps/docs/content/docs/en/blocks/human-in-the-loop.mdx index 04f210ad17..5e047457ae 100644 --- a/apps/docs/content/docs/en/blocks/human-in-the-loop.mdx +++ b/apps/docs/content/docs/en/blocks/human-in-the-loop.mdx @@ -126,26 +126,38 @@ Access resume data in downstream blocks using ``. - **Stream mode** (`stream: true` on the original execute call) — The resume response streams SSE events with `selectedOutputs` chunks, just like the initial execution. - - **Async mode** (`X-Execution-Mode: async` on the original execute call) — The resume dispatches execution to a background worker and returns immediately with `202`: + - **Async mode** (`X-Execution-Mode: async` on the original execute call) — The resume dispatches execution to a background worker and returns immediately with `202`, including a `jobId` and `statusUrl` for polling: ```json { - "status": "started", + "success": true, + "async": true, + "jobId": "", "executionId": "", - "message": "Resume execution started asynchronously." + "message": "Resume execution queued", + "statusUrl": "/api/jobs/" } ``` #### Polling execution status - To check on a paused execution or poll for completion after an async resume: + Poll the `statusUrl` from the async response to check when the resume completes: + + ```bash + GET /api/jobs/{jobId} + X-API-Key: your-api-key + ``` + + Returns job status and, when completed, the full workflow output. + + To check on a paused execution's pause points and resume links: ```bash GET /api/resume/{workflowId}/{executionId} X-API-Key: your-api-key ``` - Returns the full paused execution detail with all pause points, their statuses, and resume links. Returns `404` when the execution has completed and is no longer paused. + Returns the paused execution detail with all pause points, their statuses, and resume links. Returns `404` when the execution has completed and is no longer paused. ### Webhook diff --git a/apps/sim/app/api/form/[identifier]/route.ts b/apps/sim/app/api/form/[identifier]/route.ts index beee4876b0..2ecc89fcfb 100644 --- a/apps/sim/app/api/form/[identifier]/route.ts +++ b/apps/sim/app/api/form/[identifier]/route.ts @@ -246,31 +246,10 @@ export async function POST( ), }) - // For forms, we don't stream back - we wait for completion and return success - // Consume the stream to wait for completion const reader = stream.getReader() - let lastOutput: any = null - try { - while (true) { - const { done, value } = await reader.read() - if (done) break - - // Parse SSE data if present - const text = new TextDecoder().decode(value) - const lines = text.split('\n') - for (const line of lines) { - if (line.startsWith('data: ')) { - try { - const data = JSON.parse(line.slice(6)) - if (data.type === 'complete' || data.output) { - lastOutput = data.output || data - } - } catch { - // Ignore parse errors - } - } - } + while (!(await reader.read()).done) { + /* drain to let the workflow run to completion */ } } finally { reader.releaseLock() diff --git a/apps/sim/app/api/resume/[workflowId]/[executionId]/[contextId]/route.ts b/apps/sim/app/api/resume/[workflowId]/[executionId]/[contextId]/route.ts index 8c060d9d13..f6a33f823e 100644 --- a/apps/sim/app/api/resume/[workflowId]/[executionId]/[contextId]/route.ts +++ b/apps/sim/app/api/resume/[workflowId]/[executionId]/[contextId]/route.ts @@ -194,7 +194,7 @@ export async function POST( }) } - if (isApiCaller && executionMode !== 'async') { + if (isApiCaller && executionMode === 'sync') { const result = await PauseResumeManager.startResumeExecution(resumeArgs) return NextResponse.json({