Skip to content

[core] Never ack orchestrator message before step dispatch sends complete (stable) - #2346

Closed
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable
Closed

[core] Never ack orchestrator message before step dispatch sends complete (stable)#2346
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable

Conversation

@pranaygp

@pranaygppranaygp commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Blocked by #2349#2347. Land order: #2349 (broken stable lockfile) → #2347 (waitUntil import, unblocks tsc) → #2346 (this). Until those land, stable CI fails in pnpm install --frozen-lockfile and then in tsc, before this PR's tests run.

Stable (4.x) backport of #2345.

What

In suspension-handler.ts, the progress-critical ops — each step's step_created event write and its __wkf_step_${stepName} queue-dispatch send, plus wait_created writes — are now strictly awaited before the handler returns, instead of also being registered on a detached waitUntil(Promise.all(ops).catch(...)).

This guarantees the invariant: the orchestrator's queue message is never acked until all work that makes the run progress is durably enqueued. A crash before the await leaves the orchestrator message un-acked, so VQS redelivers and replay re-drives the run — rather than acking and orphaning a step whose dispatch send was lost.

It also removes the .catch(err => { ...throw err }) re-throw that fed a detached, unconsumed promise: on a late send failure that produced an unhandledRejection, which Node turns into process.exit(128) — the production crash signature behind the ~305s VQS-lease-recovery latency cluster (and the permanent orphans when the orchestrator chain had already concluded).

Scope

Surgical and orthogonal to #2336 (the safeWaitUntil crash hardening). The genuinely-background waitUntil sites (stream flushes in start.ts / step-executor.ts / step-handler.ts, and the fire-and-forget in resume-hook.ts) are untouched — they're not progress-critical and shouldn't block the ack.

Related

🤖 Generated with Claude Code

…lete
handleSuspension created each step_created event and enqueued its
step-dispatch queue message inside ops, but registered Promise.all(ops) on a
detached waitUntil(...) in addition to awaiting it. The detached copy framed
those progress-critical sends as droppable background work and re-threw send
failures into a promise nothing consumes (unhandled rejection -> process exit
128), which could crash a deployment and leave the orchestrator message acked
with the dispatch never sent, orphaning the step. It now strictly awaits the
sends only, so a crash before they complete leaves the message un-acked for
VQS to redeliver within the lease, re-creating the idempotent step_created and
re-sending the dispatch instead of orphaning the step.
Adds runtime.test.ts ack-ordering tests: the dispatch send must complete
before ack, a hanging send must not ack, and a failing send must reject the
handler (no ack) without rejecting any waitUntil promise.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings June 11, 2026 06:10
@pranaygp
pranaygp requested a review from a team as a code ownerJune 11, 2026 06:10
@vercel

vercelBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackErrorErrorJun 11, 2026 6:20am
example-nextjs-workflow-webpackErrorErrorJun 11, 2026 6:20am
example-workflowErrorErrorJun 11, 2026 6:20am
workbench-astro-workflowErrorErrorJun 11, 2026 6:20am
workbench-express-workflowErrorErrorJun 11, 2026 6:20am
workbench-fastify-workflowErrorErrorJun 11, 2026 6:20am
workbench-hono-workflowErrorErrorJun 11, 2026 6:20am
workbench-nitro-workflowErrorErrorJun 11, 2026 6:20am
workbench-nuxt-workflowErrorErrorJun 11, 2026 6:20am
workbench-sveltekit-workflowErrorErrorJun 11, 2026 6:20am
workbench-tanstack-start-workflowErrorErrorJun 11, 2026 6:20am
workbench-vite-workflowErrorErrorJun 11, 2026 6:20am
workflow-docsErrorErrorJun 11, 2026 6:20am
workflow-swc-playgroundErrorErrorJun 11, 2026 6:20am
workflow-tarballsErrorErrorJun 11, 2026 6:20am
workflow-webErrorErrorJun 11, 2026 6:20am

@github-actions

github-actionsBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

No test result files found.


Some E2E test jobs failed:

  • Vercel Prod: failure
  • Local Dev: skipped
  • Local Prod: skipped
  • Local Postgres: skipped
  • Windows: failure

Check the workflow run for details.

@changeset-bot

changeset-botBot commented Jun 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 63f4bc6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens crash-safety for orchestrator queue handling in @workflow/core by ensuring the suspension handler does not allow progress-critical step-dispatch queue sends to run as detached background work that could be dropped (or crash the process via unhandled rejections) after the orchestrator message is acknowledged.

Changes:

  • Remove the detached waitUntil(Promise.all(ops)) registration in handleSuspension() and rely solely on await Promise.all(ops) so step dispatch sends gate handler completion (and thus message ack).
  • Add a new runtime test suite that asserts ack-ordering and failure/hang behavior for step dispatch during suspension handling.
  • Add a changeset for a patch release of @workflow/core describing the ack-ordering invariant and the fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

FileDescription
packages/core/src/runtime/suspension-handler.tsRemoves detached waitUntil usage so step-dispatch sends complete before the handler resolves (preserving ack-ordering).
packages/core/src/runtime.test.tsAdds “ack ordering” tests that validate dispatch send completion gates handler resolution and failures prevent ack.
.changeset/ack-after-step-dispatch.mdPatch changeset documenting the crash-safety/ack-ordering fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +685 to +688
}) {
const workflowRun = await makeRunningRun(opts.runId);
const order: string[] = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing waitUntilPromises in driveHandler() is a reasonable defensive hardening, but the assertion isn't actually flaky as written. The only test that calls anyWaitUntilPromiseRejected() is the last test in this suite ("rejects the handler ... when the step-dispatch send fails"), and it's preceded by the two other suite tests, each followed by the afterEach that runs waitUntilPromises.length = 0. So the array is already empty when the rejection check runs — leftover entries from earlier describe blocks have been cleared.

The first test in the suite can see leftover entries, but it never inspects waitUntilPromises, so it isn't affected. Moving the reset into driveHandler() (or adding a beforeEach) would make it robust against future reordering/.only usage, but it's not a current correctness issue.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — waitUntilPromises.length = 0 now runs at the start of driveHandler(). Agreed with @vercel-bot that this isn't a current correctness issue (the only test that inspects the array is the last in the suite, after two afterEach resets), but it makes the assertion robust against future reordering/.only. I also applied the no-op .catch() mock hardening here that was flagged on the main PR (#2345), so the two test files stay in sync. Fixed in 63f4bc6.

"@workflow/core": patch
---

Never ack the orchestrator's queue message before the step-dispatch sends that make the run progress are durably enqueued. The suspension handler created each `step_created` event and enqueued its step-dispatch queue message inside `ops`, but registered `Promise.all(ops)` on a detached `waitUntil(...)` in addition to awaiting it. The detached copy framed those progress-critical sends as droppable background work and re-threw send failures into a promise nothing consumes (unhandled rejection → process exit 128), which could crash a deployment and leave the orchestrator message acked with the dispatch never sent — orphaning the step (its `step_created` is persisted but no queue message exists anywhere to drive the run). It now strictly awaits the sends only, so a crash before they complete leaves the message un-acked and VQS redelivers within the lease, re-creating the (idempotent) `step_created` and re-sending the dispatch instead of orphaning the step. Complements the crash fix in #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too verbose. match the format/terseness of other changesets

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed to match the sibling changesets (now ~4 lines, in line with abort-e2e-flakes.md etc). Fixed in 63f4bc6.

- Trim the changeset to match the terseness of sibling changesets.
- Attach a no-op .catch() to each promise the waitUntil mock records so a
rejecting promise can never surface as a real unhandled rejection in the
test process; keep the original promise for allSettled inspection.
- Reset waitUntilPromises at the start of driveHandler() so the rejection
check only observes this invocation's promises (robust to reordering/.only).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Heads up: the pre-existing tsc break on stable (resume-hook.ts:165 using waitUntil without importing it) that's flagged in this PR's description is now fixed in a separate minimal PR: #2347. This PR depends on #2347 landing first to get a green tsc on stable CI.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Dependency update: #2347/#2349 are closed as duplicates of #2344 (the faithful-backport fix, which also repairs the stable lockfile and the resume-hook import). This PR should land after #2344. One heads-up for the rebase: #2344 converts suspension-handler.ts's waitUntil import to the lazy ./wait-until.js wrapper, while this PR removes the only waitUntil call in that file — after both, the import becomes unused and should be dropped here.

"@workflow/core": patch
---

Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.
Fix unhandled rejection when `step_created`/`wait_created` calls fail in `waitUntil`

@VaguelySerious

Copy link
Copy Markdown
Member

Closing in favor of #2353

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@pranaygp@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
[core] Never ack orchestrator message before step dispatch sends complete (stable) by pranaygp · Pull Request #2346 · vercel/workflow · GitHub
Skip to content

[core] Never ack orchestrator message before step dispatch sends complete (stable) - #2346

Closed
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable
Closed

[core] Never ack orchestrator message before step dispatch sends complete (stable)#2346
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable

Conversation

@pranaygp

@pranaygppranaygp commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Blocked by #2349#2347. Land order: #2349 (broken stable lockfile) → #2347 (waitUntil import, unblocks tsc) → #2346 (this). Until those land, stable CI fails in pnpm install --frozen-lockfile and then in tsc, before this PR's tests run.

Stable (4.x) backport of #2345.

What

In suspension-handler.ts, the progress-critical ops — each step's step_created event write and its __wkf_step_${stepName} queue-dispatch send, plus wait_created writes — are now strictly awaited before the handler returns, instead of also being registered on a detached waitUntil(Promise.all(ops).catch(...)).

This guarantees the invariant: the orchestrator's queue message is never acked until all work that makes the run progress is durably enqueued. A crash before the await leaves the orchestrator message un-acked, so VQS redelivers and replay re-drives the run — rather than acking and orphaning a step whose dispatch send was lost.

It also removes the .catch(err => { ...throw err }) re-throw that fed a detached, unconsumed promise: on a late send failure that produced an unhandledRejection, which Node turns into process.exit(128) — the production crash signature behind the ~305s VQS-lease-recovery latency cluster (and the permanent orphans when the orchestrator chain had already concluded).

Scope

Surgical and orthogonal to #2336 (the safeWaitUntil crash hardening). The genuinely-background waitUntil sites (stream flushes in start.ts / step-executor.ts / step-handler.ts, and the fire-and-forget in resume-hook.ts) are untouched — they're not progress-critical and shouldn't block the ack.

Related

🤖 Generated with Claude Code

…lete
handleSuspension created each step_created event and enqueued its
step-dispatch queue message inside ops, but registered Promise.all(ops) on a
detached waitUntil(...) in addition to awaiting it. The detached copy framed
those progress-critical sends as droppable background work and re-threw send
failures into a promise nothing consumes (unhandled rejection -> process exit
128), which could crash a deployment and leave the orchestrator message acked
with the dispatch never sent, orphaning the step. It now strictly awaits the
sends only, so a crash before they complete leaves the message un-acked for
VQS to redeliver within the lease, re-creating the idempotent step_created and
re-sending the dispatch instead of orphaning the step.
Adds runtime.test.ts ack-ordering tests: the dispatch send must complete
before ack, a hanging send must not ack, and a failing send must reject the
handler (no ack) without rejecting any waitUntil promise.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings June 11, 2026 06:10
@pranaygp
pranaygp requested a review from a team as a code ownerJune 11, 2026 06:10
@vercel

vercelBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackErrorErrorJun 11, 2026 6:20am
example-nextjs-workflow-webpackErrorErrorJun 11, 2026 6:20am
example-workflowErrorErrorJun 11, 2026 6:20am
workbench-astro-workflowErrorErrorJun 11, 2026 6:20am
workbench-express-workflowErrorErrorJun 11, 2026 6:20am
workbench-fastify-workflowErrorErrorJun 11, 2026 6:20am
workbench-hono-workflowErrorErrorJun 11, 2026 6:20am
workbench-nitro-workflowErrorErrorJun 11, 2026 6:20am
workbench-nuxt-workflowErrorErrorJun 11, 2026 6:20am
workbench-sveltekit-workflowErrorErrorJun 11, 2026 6:20am
workbench-tanstack-start-workflowErrorErrorJun 11, 2026 6:20am
workbench-vite-workflowErrorErrorJun 11, 2026 6:20am
workflow-docsErrorErrorJun 11, 2026 6:20am
workflow-swc-playgroundErrorErrorJun 11, 2026 6:20am
workflow-tarballsErrorErrorJun 11, 2026 6:20am
workflow-webErrorErrorJun 11, 2026 6:20am

@github-actions

github-actionsBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

No test result files found.


Some E2E test jobs failed:

  • Vercel Prod: failure
  • Local Dev: skipped
  • Local Prod: skipped
  • Local Postgres: skipped
  • Windows: failure

Check the workflow run for details.

@changeset-bot

changeset-botBot commented Jun 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 63f4bc6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens crash-safety for orchestrator queue handling in @workflow/core by ensuring the suspension handler does not allow progress-critical step-dispatch queue sends to run as detached background work that could be dropped (or crash the process via unhandled rejections) after the orchestrator message is acknowledged.

Changes:

  • Remove the detached waitUntil(Promise.all(ops)) registration in handleSuspension() and rely solely on await Promise.all(ops) so step dispatch sends gate handler completion (and thus message ack).
  • Add a new runtime test suite that asserts ack-ordering and failure/hang behavior for step dispatch during suspension handling.
  • Add a changeset for a patch release of @workflow/core describing the ack-ordering invariant and the fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

FileDescription
packages/core/src/runtime/suspension-handler.tsRemoves detached waitUntil usage so step-dispatch sends complete before the handler resolves (preserving ack-ordering).
packages/core/src/runtime.test.tsAdds “ack ordering” tests that validate dispatch send completion gates handler resolution and failures prevent ack.
.changeset/ack-after-step-dispatch.mdPatch changeset documenting the crash-safety/ack-ordering fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +685 to +688
}) {
const workflowRun = await makeRunningRun(opts.runId);
const order: string[] = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing waitUntilPromises in driveHandler() is a reasonable defensive hardening, but the assertion isn't actually flaky as written. The only test that calls anyWaitUntilPromiseRejected() is the last test in this suite ("rejects the handler ... when the step-dispatch send fails"), and it's preceded by the two other suite tests, each followed by the afterEach that runs waitUntilPromises.length = 0. So the array is already empty when the rejection check runs — leftover entries from earlier describe blocks have been cleared.

The first test in the suite can see leftover entries, but it never inspects waitUntilPromises, so it isn't affected. Moving the reset into driveHandler() (or adding a beforeEach) would make it robust against future reordering/.only usage, but it's not a current correctness issue.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — waitUntilPromises.length = 0 now runs at the start of driveHandler(). Agreed with @vercel-bot that this isn't a current correctness issue (the only test that inspects the array is the last in the suite, after two afterEach resets), but it makes the assertion robust against future reordering/.only. I also applied the no-op .catch() mock hardening here that was flagged on the main PR (#2345), so the two test files stay in sync. Fixed in 63f4bc6.

"@workflow/core": patch
---

Never ack the orchestrator's queue message before the step-dispatch sends that make the run progress are durably enqueued. The suspension handler created each `step_created` event and enqueued its step-dispatch queue message inside `ops`, but registered `Promise.all(ops)` on a detached `waitUntil(...)` in addition to awaiting it. The detached copy framed those progress-critical sends as droppable background work and re-threw send failures into a promise nothing consumes (unhandled rejection → process exit 128), which could crash a deployment and leave the orchestrator message acked with the dispatch never sent — orphaning the step (its `step_created` is persisted but no queue message exists anywhere to drive the run). It now strictly awaits the sends only, so a crash before they complete leaves the message un-acked and VQS redelivers within the lease, re-creating the (idempotent) `step_created` and re-sending the dispatch instead of orphaning the step. Complements the crash fix in #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too verbose. match the format/terseness of other changesets

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed to match the sibling changesets (now ~4 lines, in line with abort-e2e-flakes.md etc). Fixed in 63f4bc6.

- Trim the changeset to match the terseness of sibling changesets.
- Attach a no-op .catch() to each promise the waitUntil mock records so a
rejecting promise can never surface as a real unhandled rejection in the
test process; keep the original promise for allSettled inspection.
- Reset waitUntilPromises at the start of driveHandler() so the rejection
check only observes this invocation's promises (robust to reordering/.only).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Heads up: the pre-existing tsc break on stable (resume-hook.ts:165 using waitUntil without importing it) that's flagged in this PR's description is now fixed in a separate minimal PR: #2347. This PR depends on #2347 landing first to get a green tsc on stable CI.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Dependency update: #2347/#2349 are closed as duplicates of #2344 (the faithful-backport fix, which also repairs the stable lockfile and the resume-hook import). This PR should land after #2344. One heads-up for the rebase: #2344 converts suspension-handler.ts's waitUntil import to the lazy ./wait-until.js wrapper, while this PR removes the only waitUntil call in that file — after both, the import becomes unused and should be dropped here.

"@workflow/core": patch
---

Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.
Fix unhandled rejection when `step_created`/`wait_created` calls fail in `waitUntil`

@VaguelySerious

Copy link
Copy Markdown
Member

Closing in favor of #2353

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@pranaygp@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [core] Never ack orchestrator message before step dispatch sends complete (stable) by pranaygp · Pull Request #2346 · vercel/workflow · GitHub
Skip to content

[core] Never ack orchestrator message before step dispatch sends complete (stable) - #2346

Closed
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable
Closed

[core] Never ack orchestrator message before step dispatch sends complete (stable)#2346
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable

Conversation

@pranaygp

@pranaygppranaygp commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Blocked by #2349#2347. Land order: #2349 (broken stable lockfile) → #2347 (waitUntil import, unblocks tsc) → #2346 (this). Until those land, stable CI fails in pnpm install --frozen-lockfile and then in tsc, before this PR's tests run.

Stable (4.x) backport of #2345.

What

In suspension-handler.ts, the progress-critical ops — each step's step_created event write and its __wkf_step_${stepName} queue-dispatch send, plus wait_created writes — are now strictly awaited before the handler returns, instead of also being registered on a detached waitUntil(Promise.all(ops).catch(...)).

This guarantees the invariant: the orchestrator's queue message is never acked until all work that makes the run progress is durably enqueued. A crash before the await leaves the orchestrator message un-acked, so VQS redelivers and replay re-drives the run — rather than acking and orphaning a step whose dispatch send was lost.

It also removes the .catch(err => { ...throw err }) re-throw that fed a detached, unconsumed promise: on a late send failure that produced an unhandledRejection, which Node turns into process.exit(128) — the production crash signature behind the ~305s VQS-lease-recovery latency cluster (and the permanent orphans when the orchestrator chain had already concluded).

Scope

Surgical and orthogonal to #2336 (the safeWaitUntil crash hardening). The genuinely-background waitUntil sites (stream flushes in start.ts / step-executor.ts / step-handler.ts, and the fire-and-forget in resume-hook.ts) are untouched — they're not progress-critical and shouldn't block the ack.

Related

🤖 Generated with Claude Code

…lete
handleSuspension created each step_created event and enqueued its
step-dispatch queue message inside ops, but registered Promise.all(ops) on a
detached waitUntil(...) in addition to awaiting it. The detached copy framed
those progress-critical sends as droppable background work and re-threw send
failures into a promise nothing consumes (unhandled rejection -> process exit
128), which could crash a deployment and leave the orchestrator message acked
with the dispatch never sent, orphaning the step. It now strictly awaits the
sends only, so a crash before they complete leaves the message un-acked for
VQS to redeliver within the lease, re-creating the idempotent step_created and
re-sending the dispatch instead of orphaning the step.
Adds runtime.test.ts ack-ordering tests: the dispatch send must complete
before ack, a hanging send must not ack, and a failing send must reject the
handler (no ack) without rejecting any waitUntil promise.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings June 11, 2026 06:10
@pranaygp
pranaygp requested a review from a team as a code ownerJune 11, 2026 06:10
@vercel

vercelBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackErrorErrorJun 11, 2026 6:20am
example-nextjs-workflow-webpackErrorErrorJun 11, 2026 6:20am
example-workflowErrorErrorJun 11, 2026 6:20am
workbench-astro-workflowErrorErrorJun 11, 2026 6:20am
workbench-express-workflowErrorErrorJun 11, 2026 6:20am
workbench-fastify-workflowErrorErrorJun 11, 2026 6:20am
workbench-hono-workflowErrorErrorJun 11, 2026 6:20am
workbench-nitro-workflowErrorErrorJun 11, 2026 6:20am
workbench-nuxt-workflowErrorErrorJun 11, 2026 6:20am
workbench-sveltekit-workflowErrorErrorJun 11, 2026 6:20am
workbench-tanstack-start-workflowErrorErrorJun 11, 2026 6:20am
workbench-vite-workflowErrorErrorJun 11, 2026 6:20am
workflow-docsErrorErrorJun 11, 2026 6:20am
workflow-swc-playgroundErrorErrorJun 11, 2026 6:20am
workflow-tarballsErrorErrorJun 11, 2026 6:20am
workflow-webErrorErrorJun 11, 2026 6:20am

@github-actions

github-actionsBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

No test result files found.


Some E2E test jobs failed:

  • Vercel Prod: failure
  • Local Dev: skipped
  • Local Prod: skipped
  • Local Postgres: skipped
  • Windows: failure

Check the workflow run for details.

@changeset-bot

changeset-botBot commented Jun 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 63f4bc6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens crash-safety for orchestrator queue handling in @workflow/core by ensuring the suspension handler does not allow progress-critical step-dispatch queue sends to run as detached background work that could be dropped (or crash the process via unhandled rejections) after the orchestrator message is acknowledged.

Changes:

  • Remove the detached waitUntil(Promise.all(ops)) registration in handleSuspension() and rely solely on await Promise.all(ops) so step dispatch sends gate handler completion (and thus message ack).
  • Add a new runtime test suite that asserts ack-ordering and failure/hang behavior for step dispatch during suspension handling.
  • Add a changeset for a patch release of @workflow/core describing the ack-ordering invariant and the fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

FileDescription
packages/core/src/runtime/suspension-handler.tsRemoves detached waitUntil usage so step-dispatch sends complete before the handler resolves (preserving ack-ordering).
packages/core/src/runtime.test.tsAdds “ack ordering” tests that validate dispatch send completion gates handler resolution and failures prevent ack.
.changeset/ack-after-step-dispatch.mdPatch changeset documenting the crash-safety/ack-ordering fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +685 to +688
}) {
const workflowRun = await makeRunningRun(opts.runId);
const order: string[] = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing waitUntilPromises in driveHandler() is a reasonable defensive hardening, but the assertion isn't actually flaky as written. The only test that calls anyWaitUntilPromiseRejected() is the last test in this suite ("rejects the handler ... when the step-dispatch send fails"), and it's preceded by the two other suite tests, each followed by the afterEach that runs waitUntilPromises.length = 0. So the array is already empty when the rejection check runs — leftover entries from earlier describe blocks have been cleared.

The first test in the suite can see leftover entries, but it never inspects waitUntilPromises, so it isn't affected. Moving the reset into driveHandler() (or adding a beforeEach) would make it robust against future reordering/.only usage, but it's not a current correctness issue.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — waitUntilPromises.length = 0 now runs at the start of driveHandler(). Agreed with @vercel-bot that this isn't a current correctness issue (the only test that inspects the array is the last in the suite, after two afterEach resets), but it makes the assertion robust against future reordering/.only. I also applied the no-op .catch() mock hardening here that was flagged on the main PR (#2345), so the two test files stay in sync. Fixed in 63f4bc6.

"@workflow/core": patch
---

Never ack the orchestrator's queue message before the step-dispatch sends that make the run progress are durably enqueued. The suspension handler created each `step_created` event and enqueued its step-dispatch queue message inside `ops`, but registered `Promise.all(ops)` on a detached `waitUntil(...)` in addition to awaiting it. The detached copy framed those progress-critical sends as droppable background work and re-threw send failures into a promise nothing consumes (unhandled rejection → process exit 128), which could crash a deployment and leave the orchestrator message acked with the dispatch never sent — orphaning the step (its `step_created` is persisted but no queue message exists anywhere to drive the run). It now strictly awaits the sends only, so a crash before they complete leaves the message un-acked and VQS redelivers within the lease, re-creating the (idempotent) `step_created` and re-sending the dispatch instead of orphaning the step. Complements the crash fix in #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too verbose. match the format/terseness of other changesets

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed to match the sibling changesets (now ~4 lines, in line with abort-e2e-flakes.md etc). Fixed in 63f4bc6.

- Trim the changeset to match the terseness of sibling changesets.
- Attach a no-op .catch() to each promise the waitUntil mock records so a
rejecting promise can never surface as a real unhandled rejection in the
test process; keep the original promise for allSettled inspection.
- Reset waitUntilPromises at the start of driveHandler() so the rejection
check only observes this invocation's promises (robust to reordering/.only).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Heads up: the pre-existing tsc break on stable (resume-hook.ts:165 using waitUntil without importing it) that's flagged in this PR's description is now fixed in a separate minimal PR: #2347. This PR depends on #2347 landing first to get a green tsc on stable CI.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Dependency update: #2347/#2349 are closed as duplicates of #2344 (the faithful-backport fix, which also repairs the stable lockfile and the resume-hook import). This PR should land after #2344. One heads-up for the rebase: #2344 converts suspension-handler.ts's waitUntil import to the lazy ./wait-until.js wrapper, while this PR removes the only waitUntil call in that file — after both, the import becomes unused and should be dropped here.

"@workflow/core": patch
---

Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.
Fix unhandled rejection when `step_created`/`wait_created` calls fail in `waitUntil`

@VaguelySerious

Copy link
Copy Markdown
Member

Closing in favor of #2353

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@pranaygp@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [core] Never ack orchestrator message before step dispatch sends complete (stable) by pranaygp · Pull Request #2346 · vercel/workflow · GitHub
Skip to content

[core] Never ack orchestrator message before step dispatch sends complete (stable) - #2346

Closed
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable
Closed

[core] Never ack orchestrator message before step dispatch sends complete (stable)#2346
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable

Conversation

@pranaygp

@pranaygppranaygp commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Blocked by #2349#2347. Land order: #2349 (broken stable lockfile) → #2347 (waitUntil import, unblocks tsc) → #2346 (this). Until those land, stable CI fails in pnpm install --frozen-lockfile and then in tsc, before this PR's tests run.

Stable (4.x) backport of #2345.

What

In suspension-handler.ts, the progress-critical ops — each step's step_created event write and its __wkf_step_${stepName} queue-dispatch send, plus wait_created writes — are now strictly awaited before the handler returns, instead of also being registered on a detached waitUntil(Promise.all(ops).catch(...)).

This guarantees the invariant: the orchestrator's queue message is never acked until all work that makes the run progress is durably enqueued. A crash before the await leaves the orchestrator message un-acked, so VQS redelivers and replay re-drives the run — rather than acking and orphaning a step whose dispatch send was lost.

It also removes the .catch(err => { ...throw err }) re-throw that fed a detached, unconsumed promise: on a late send failure that produced an unhandledRejection, which Node turns into process.exit(128) — the production crash signature behind the ~305s VQS-lease-recovery latency cluster (and the permanent orphans when the orchestrator chain had already concluded).

Scope

Surgical and orthogonal to #2336 (the safeWaitUntil crash hardening). The genuinely-background waitUntil sites (stream flushes in start.ts / step-executor.ts / step-handler.ts, and the fire-and-forget in resume-hook.ts) are untouched — they're not progress-critical and shouldn't block the ack.

Related

🤖 Generated with Claude Code

…lete
handleSuspension created each step_created event and enqueued its
step-dispatch queue message inside ops, but registered Promise.all(ops) on a
detached waitUntil(...) in addition to awaiting it. The detached copy framed
those progress-critical sends as droppable background work and re-threw send
failures into a promise nothing consumes (unhandled rejection -> process exit
128), which could crash a deployment and leave the orchestrator message acked
with the dispatch never sent, orphaning the step. It now strictly awaits the
sends only, so a crash before they complete leaves the message un-acked for
VQS to redeliver within the lease, re-creating the idempotent step_created and
re-sending the dispatch instead of orphaning the step.
Adds runtime.test.ts ack-ordering tests: the dispatch send must complete
before ack, a hanging send must not ack, and a failing send must reject the
handler (no ack) without rejecting any waitUntil promise.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings June 11, 2026 06:10
@pranaygp
pranaygp requested a review from a team as a code ownerJune 11, 2026 06:10
@vercel

vercelBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackErrorErrorJun 11, 2026 6:20am
example-nextjs-workflow-webpackErrorErrorJun 11, 2026 6:20am
example-workflowErrorErrorJun 11, 2026 6:20am
workbench-astro-workflowErrorErrorJun 11, 2026 6:20am
workbench-express-workflowErrorErrorJun 11, 2026 6:20am
workbench-fastify-workflowErrorErrorJun 11, 2026 6:20am
workbench-hono-workflowErrorErrorJun 11, 2026 6:20am
workbench-nitro-workflowErrorErrorJun 11, 2026 6:20am
workbench-nuxt-workflowErrorErrorJun 11, 2026 6:20am
workbench-sveltekit-workflowErrorErrorJun 11, 2026 6:20am
workbench-tanstack-start-workflowErrorErrorJun 11, 2026 6:20am
workbench-vite-workflowErrorErrorJun 11, 2026 6:20am
workflow-docsErrorErrorJun 11, 2026 6:20am
workflow-swc-playgroundErrorErrorJun 11, 2026 6:20am
workflow-tarballsErrorErrorJun 11, 2026 6:20am
workflow-webErrorErrorJun 11, 2026 6:20am

@github-actions

github-actionsBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

No test result files found.


Some E2E test jobs failed:

  • Vercel Prod: failure
  • Local Dev: skipped
  • Local Prod: skipped
  • Local Postgres: skipped
  • Windows: failure

Check the workflow run for details.

@changeset-bot

changeset-botBot commented Jun 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 63f4bc6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens crash-safety for orchestrator queue handling in @workflow/core by ensuring the suspension handler does not allow progress-critical step-dispatch queue sends to run as detached background work that could be dropped (or crash the process via unhandled rejections) after the orchestrator message is acknowledged.

Changes:

  • Remove the detached waitUntil(Promise.all(ops)) registration in handleSuspension() and rely solely on await Promise.all(ops) so step dispatch sends gate handler completion (and thus message ack).
  • Add a new runtime test suite that asserts ack-ordering and failure/hang behavior for step dispatch during suspension handling.
  • Add a changeset for a patch release of @workflow/core describing the ack-ordering invariant and the fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

FileDescription
packages/core/src/runtime/suspension-handler.tsRemoves detached waitUntil usage so step-dispatch sends complete before the handler resolves (preserving ack-ordering).
packages/core/src/runtime.test.tsAdds “ack ordering” tests that validate dispatch send completion gates handler resolution and failures prevent ack.
.changeset/ack-after-step-dispatch.mdPatch changeset documenting the crash-safety/ack-ordering fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +685 to +688
}) {
const workflowRun = await makeRunningRun(opts.runId);
const order: string[] = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing waitUntilPromises in driveHandler() is a reasonable defensive hardening, but the assertion isn't actually flaky as written. The only test that calls anyWaitUntilPromiseRejected() is the last test in this suite ("rejects the handler ... when the step-dispatch send fails"), and it's preceded by the two other suite tests, each followed by the afterEach that runs waitUntilPromises.length = 0. So the array is already empty when the rejection check runs — leftover entries from earlier describe blocks have been cleared.

The first test in the suite can see leftover entries, but it never inspects waitUntilPromises, so it isn't affected. Moving the reset into driveHandler() (or adding a beforeEach) would make it robust against future reordering/.only usage, but it's not a current correctness issue.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — waitUntilPromises.length = 0 now runs at the start of driveHandler(). Agreed with @vercel-bot that this isn't a current correctness issue (the only test that inspects the array is the last in the suite, after two afterEach resets), but it makes the assertion robust against future reordering/.only. I also applied the no-op .catch() mock hardening here that was flagged on the main PR (#2345), so the two test files stay in sync. Fixed in 63f4bc6.

"@workflow/core": patch
---

Never ack the orchestrator's queue message before the step-dispatch sends that make the run progress are durably enqueued. The suspension handler created each `step_created` event and enqueued its step-dispatch queue message inside `ops`, but registered `Promise.all(ops)` on a detached `waitUntil(...)` in addition to awaiting it. The detached copy framed those progress-critical sends as droppable background work and re-threw send failures into a promise nothing consumes (unhandled rejection → process exit 128), which could crash a deployment and leave the orchestrator message acked with the dispatch never sent — orphaning the step (its `step_created` is persisted but no queue message exists anywhere to drive the run). It now strictly awaits the sends only, so a crash before they complete leaves the message un-acked and VQS redelivers within the lease, re-creating the (idempotent) `step_created` and re-sending the dispatch instead of orphaning the step. Complements the crash fix in #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too verbose. match the format/terseness of other changesets

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed to match the sibling changesets (now ~4 lines, in line with abort-e2e-flakes.md etc). Fixed in 63f4bc6.

- Trim the changeset to match the terseness of sibling changesets.
- Attach a no-op .catch() to each promise the waitUntil mock records so a
rejecting promise can never surface as a real unhandled rejection in the
test process; keep the original promise for allSettled inspection.
- Reset waitUntilPromises at the start of driveHandler() so the rejection
check only observes this invocation's promises (robust to reordering/.only).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Heads up: the pre-existing tsc break on stable (resume-hook.ts:165 using waitUntil without importing it) that's flagged in this PR's description is now fixed in a separate minimal PR: #2347. This PR depends on #2347 landing first to get a green tsc on stable CI.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Dependency update: #2347/#2349 are closed as duplicates of #2344 (the faithful-backport fix, which also repairs the stable lockfile and the resume-hook import). This PR should land after #2344. One heads-up for the rebase: #2344 converts suspension-handler.ts's waitUntil import to the lazy ./wait-until.js wrapper, while this PR removes the only waitUntil call in that file — after both, the import becomes unused and should be dropped here.

"@workflow/core": patch
---

Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.
Fix unhandled rejection when `step_created`/`wait_created` calls fail in `waitUntil`

@VaguelySerious

Copy link
Copy Markdown
Member

Closing in favor of #2353

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@pranaygp@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' [core] Never ack orchestrator message before step dispatch sends complete (stable) by pranaygp · Pull Request #2346 · vercel/workflow · GitHub
Skip to content

[core] Never ack orchestrator message before step dispatch sends complete (stable) - #2346

Closed
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable
Closed

[core] Never ack orchestrator message before step dispatch sends complete (stable)#2346
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable

Conversation

@pranaygp

@pranaygppranaygp commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Blocked by #2349#2347. Land order: #2349 (broken stable lockfile) → #2347 (waitUntil import, unblocks tsc) → #2346 (this). Until those land, stable CI fails in pnpm install --frozen-lockfile and then in tsc, before this PR's tests run.

Stable (4.x) backport of #2345.

What

In suspension-handler.ts, the progress-critical ops — each step's step_created event write and its __wkf_step_${stepName} queue-dispatch send, plus wait_created writes — are now strictly awaited before the handler returns, instead of also being registered on a detached waitUntil(Promise.all(ops).catch(...)).

This guarantees the invariant: the orchestrator's queue message is never acked until all work that makes the run progress is durably enqueued. A crash before the await leaves the orchestrator message un-acked, so VQS redelivers and replay re-drives the run — rather than acking and orphaning a step whose dispatch send was lost.

It also removes the .catch(err => { ...throw err }) re-throw that fed a detached, unconsumed promise: on a late send failure that produced an unhandledRejection, which Node turns into process.exit(128) — the production crash signature behind the ~305s VQS-lease-recovery latency cluster (and the permanent orphans when the orchestrator chain had already concluded).

Scope

Surgical and orthogonal to #2336 (the safeWaitUntil crash hardening). The genuinely-background waitUntil sites (stream flushes in start.ts / step-executor.ts / step-handler.ts, and the fire-and-forget in resume-hook.ts) are untouched — they're not progress-critical and shouldn't block the ack.

Related

🤖 Generated with Claude Code

…lete
handleSuspension created each step_created event and enqueued its
step-dispatch queue message inside ops, but registered Promise.all(ops) on a
detached waitUntil(...) in addition to awaiting it. The detached copy framed
those progress-critical sends as droppable background work and re-threw send
failures into a promise nothing consumes (unhandled rejection -> process exit
128), which could crash a deployment and leave the orchestrator message acked
with the dispatch never sent, orphaning the step. It now strictly awaits the
sends only, so a crash before they complete leaves the message un-acked for
VQS to redeliver within the lease, re-creating the idempotent step_created and
re-sending the dispatch instead of orphaning the step.
Adds runtime.test.ts ack-ordering tests: the dispatch send must complete
before ack, a hanging send must not ack, and a failing send must reject the
handler (no ack) without rejecting any waitUntil promise.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings June 11, 2026 06:10
@pranaygp
pranaygp requested a review from a team as a code ownerJune 11, 2026 06:10
@vercel

vercelBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackErrorErrorJun 11, 2026 6:20am
example-nextjs-workflow-webpackErrorErrorJun 11, 2026 6:20am
example-workflowErrorErrorJun 11, 2026 6:20am
workbench-astro-workflowErrorErrorJun 11, 2026 6:20am
workbench-express-workflowErrorErrorJun 11, 2026 6:20am
workbench-fastify-workflowErrorErrorJun 11, 2026 6:20am
workbench-hono-workflowErrorErrorJun 11, 2026 6:20am
workbench-nitro-workflowErrorErrorJun 11, 2026 6:20am
workbench-nuxt-workflowErrorErrorJun 11, 2026 6:20am
workbench-sveltekit-workflowErrorErrorJun 11, 2026 6:20am
workbench-tanstack-start-workflowErrorErrorJun 11, 2026 6:20am
workbench-vite-workflowErrorErrorJun 11, 2026 6:20am
workflow-docsErrorErrorJun 11, 2026 6:20am
workflow-swc-playgroundErrorErrorJun 11, 2026 6:20am
workflow-tarballsErrorErrorJun 11, 2026 6:20am
workflow-webErrorErrorJun 11, 2026 6:20am

@github-actions

github-actionsBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

No test result files found.


Some E2E test jobs failed:

  • Vercel Prod: failure
  • Local Dev: skipped
  • Local Prod: skipped
  • Local Postgres: skipped
  • Windows: failure

Check the workflow run for details.

@changeset-bot

changeset-botBot commented Jun 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 63f4bc6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens crash-safety for orchestrator queue handling in @workflow/core by ensuring the suspension handler does not allow progress-critical step-dispatch queue sends to run as detached background work that could be dropped (or crash the process via unhandled rejections) after the orchestrator message is acknowledged.

Changes:

  • Remove the detached waitUntil(Promise.all(ops)) registration in handleSuspension() and rely solely on await Promise.all(ops) so step dispatch sends gate handler completion (and thus message ack).
  • Add a new runtime test suite that asserts ack-ordering and failure/hang behavior for step dispatch during suspension handling.
  • Add a changeset for a patch release of @workflow/core describing the ack-ordering invariant and the fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

FileDescription
packages/core/src/runtime/suspension-handler.tsRemoves detached waitUntil usage so step-dispatch sends complete before the handler resolves (preserving ack-ordering).
packages/core/src/runtime.test.tsAdds “ack ordering” tests that validate dispatch send completion gates handler resolution and failures prevent ack.
.changeset/ack-after-step-dispatch.mdPatch changeset documenting the crash-safety/ack-ordering fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +685 to +688
}) {
const workflowRun = await makeRunningRun(opts.runId);
const order: string[] = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing waitUntilPromises in driveHandler() is a reasonable defensive hardening, but the assertion isn't actually flaky as written. The only test that calls anyWaitUntilPromiseRejected() is the last test in this suite ("rejects the handler ... when the step-dispatch send fails"), and it's preceded by the two other suite tests, each followed by the afterEach that runs waitUntilPromises.length = 0. So the array is already empty when the rejection check runs — leftover entries from earlier describe blocks have been cleared.

The first test in the suite can see leftover entries, but it never inspects waitUntilPromises, so it isn't affected. Moving the reset into driveHandler() (or adding a beforeEach) would make it robust against future reordering/.only usage, but it's not a current correctness issue.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — waitUntilPromises.length = 0 now runs at the start of driveHandler(). Agreed with @vercel-bot that this isn't a current correctness issue (the only test that inspects the array is the last in the suite, after two afterEach resets), but it makes the assertion robust against future reordering/.only. I also applied the no-op .catch() mock hardening here that was flagged on the main PR (#2345), so the two test files stay in sync. Fixed in 63f4bc6.

"@workflow/core": patch
---

Never ack the orchestrator's queue message before the step-dispatch sends that make the run progress are durably enqueued. The suspension handler created each `step_created` event and enqueued its step-dispatch queue message inside `ops`, but registered `Promise.all(ops)` on a detached `waitUntil(...)` in addition to awaiting it. The detached copy framed those progress-critical sends as droppable background work and re-threw send failures into a promise nothing consumes (unhandled rejection → process exit 128), which could crash a deployment and leave the orchestrator message acked with the dispatch never sent — orphaning the step (its `step_created` is persisted but no queue message exists anywhere to drive the run). It now strictly awaits the sends only, so a crash before they complete leaves the message un-acked and VQS redelivers within the lease, re-creating the (idempotent) `step_created` and re-sending the dispatch instead of orphaning the step. Complements the crash fix in #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too verbose. match the format/terseness of other changesets

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed to match the sibling changesets (now ~4 lines, in line with abort-e2e-flakes.md etc). Fixed in 63f4bc6.

- Trim the changeset to match the terseness of sibling changesets.
- Attach a no-op .catch() to each promise the waitUntil mock records so a
rejecting promise can never surface as a real unhandled rejection in the
test process; keep the original promise for allSettled inspection.
- Reset waitUntilPromises at the start of driveHandler() so the rejection
check only observes this invocation's promises (robust to reordering/.only).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Heads up: the pre-existing tsc break on stable (resume-hook.ts:165 using waitUntil without importing it) that's flagged in this PR's description is now fixed in a separate minimal PR: #2347. This PR depends on #2347 landing first to get a green tsc on stable CI.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Dependency update: #2347/#2349 are closed as duplicates of #2344 (the faithful-backport fix, which also repairs the stable lockfile and the resume-hook import). This PR should land after #2344. One heads-up for the rebase: #2344 converts suspension-handler.ts's waitUntil import to the lazy ./wait-until.js wrapper, while this PR removes the only waitUntil call in that file — after both, the import becomes unused and should be dropped here.

"@workflow/core": patch
---

Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.
Fix unhandled rejection when `step_created`/`wait_created` calls fail in `waitUntil`

@VaguelySerious

Copy link
Copy Markdown
Member

Closing in favor of #2353

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@pranaygp@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [core] Never ack orchestrator message before step dispatch sends complete (stable) by pranaygp · Pull Request #2346 · vercel/workflow · GitHub
Skip to content

[core] Never ack orchestrator message before step dispatch sends complete (stable) - #2346

Closed
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable
Closed

[core] Never ack orchestrator message before step dispatch sends complete (stable)#2346
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable

Conversation

@pranaygp

@pranaygppranaygp commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Blocked by #2349#2347. Land order: #2349 (broken stable lockfile) → #2347 (waitUntil import, unblocks tsc) → #2346 (this). Until those land, stable CI fails in pnpm install --frozen-lockfile and then in tsc, before this PR's tests run.

Stable (4.x) backport of #2345.

What

In suspension-handler.ts, the progress-critical ops — each step's step_created event write and its __wkf_step_${stepName} queue-dispatch send, plus wait_created writes — are now strictly awaited before the handler returns, instead of also being registered on a detached waitUntil(Promise.all(ops).catch(...)).

This guarantees the invariant: the orchestrator's queue message is never acked until all work that makes the run progress is durably enqueued. A crash before the await leaves the orchestrator message un-acked, so VQS redelivers and replay re-drives the run — rather than acking and orphaning a step whose dispatch send was lost.

It also removes the .catch(err => { ...throw err }) re-throw that fed a detached, unconsumed promise: on a late send failure that produced an unhandledRejection, which Node turns into process.exit(128) — the production crash signature behind the ~305s VQS-lease-recovery latency cluster (and the permanent orphans when the orchestrator chain had already concluded).

Scope

Surgical and orthogonal to #2336 (the safeWaitUntil crash hardening). The genuinely-background waitUntil sites (stream flushes in start.ts / step-executor.ts / step-handler.ts, and the fire-and-forget in resume-hook.ts) are untouched — they're not progress-critical and shouldn't block the ack.

Related

🤖 Generated with Claude Code

…lete
handleSuspension created each step_created event and enqueued its
step-dispatch queue message inside ops, but registered Promise.all(ops) on a
detached waitUntil(...) in addition to awaiting it. The detached copy framed
those progress-critical sends as droppable background work and re-threw send
failures into a promise nothing consumes (unhandled rejection -> process exit
128), which could crash a deployment and leave the orchestrator message acked
with the dispatch never sent, orphaning the step. It now strictly awaits the
sends only, so a crash before they complete leaves the message un-acked for
VQS to redeliver within the lease, re-creating the idempotent step_created and
re-sending the dispatch instead of orphaning the step.
Adds runtime.test.ts ack-ordering tests: the dispatch send must complete
before ack, a hanging send must not ack, and a failing send must reject the
handler (no ack) without rejecting any waitUntil promise.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings June 11, 2026 06:10
@pranaygp
pranaygp requested a review from a team as a code ownerJune 11, 2026 06:10
@vercel

vercelBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackErrorErrorJun 11, 2026 6:20am
example-nextjs-workflow-webpackErrorErrorJun 11, 2026 6:20am
example-workflowErrorErrorJun 11, 2026 6:20am
workbench-astro-workflowErrorErrorJun 11, 2026 6:20am
workbench-express-workflowErrorErrorJun 11, 2026 6:20am
workbench-fastify-workflowErrorErrorJun 11, 2026 6:20am
workbench-hono-workflowErrorErrorJun 11, 2026 6:20am
workbench-nitro-workflowErrorErrorJun 11, 2026 6:20am
workbench-nuxt-workflowErrorErrorJun 11, 2026 6:20am
workbench-sveltekit-workflowErrorErrorJun 11, 2026 6:20am
workbench-tanstack-start-workflowErrorErrorJun 11, 2026 6:20am
workbench-vite-workflowErrorErrorJun 11, 2026 6:20am
workflow-docsErrorErrorJun 11, 2026 6:20am
workflow-swc-playgroundErrorErrorJun 11, 2026 6:20am
workflow-tarballsErrorErrorJun 11, 2026 6:20am
workflow-webErrorErrorJun 11, 2026 6:20am

@github-actions

github-actionsBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

No test result files found.


Some E2E test jobs failed:

  • Vercel Prod: failure
  • Local Dev: skipped
  • Local Prod: skipped
  • Local Postgres: skipped
  • Windows: failure

Check the workflow run for details.

@changeset-bot

changeset-botBot commented Jun 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 63f4bc6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens crash-safety for orchestrator queue handling in @workflow/core by ensuring the suspension handler does not allow progress-critical step-dispatch queue sends to run as detached background work that could be dropped (or crash the process via unhandled rejections) after the orchestrator message is acknowledged.

Changes:

  • Remove the detached waitUntil(Promise.all(ops)) registration in handleSuspension() and rely solely on await Promise.all(ops) so step dispatch sends gate handler completion (and thus message ack).
  • Add a new runtime test suite that asserts ack-ordering and failure/hang behavior for step dispatch during suspension handling.
  • Add a changeset for a patch release of @workflow/core describing the ack-ordering invariant and the fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

FileDescription
packages/core/src/runtime/suspension-handler.tsRemoves detached waitUntil usage so step-dispatch sends complete before the handler resolves (preserving ack-ordering).
packages/core/src/runtime.test.tsAdds “ack ordering” tests that validate dispatch send completion gates handler resolution and failures prevent ack.
.changeset/ack-after-step-dispatch.mdPatch changeset documenting the crash-safety/ack-ordering fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +685 to +688
}) {
const workflowRun = await makeRunningRun(opts.runId);
const order: string[] = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing waitUntilPromises in driveHandler() is a reasonable defensive hardening, but the assertion isn't actually flaky as written. The only test that calls anyWaitUntilPromiseRejected() is the last test in this suite ("rejects the handler ... when the step-dispatch send fails"), and it's preceded by the two other suite tests, each followed by the afterEach that runs waitUntilPromises.length = 0. So the array is already empty when the rejection check runs — leftover entries from earlier describe blocks have been cleared.

The first test in the suite can see leftover entries, but it never inspects waitUntilPromises, so it isn't affected. Moving the reset into driveHandler() (or adding a beforeEach) would make it robust against future reordering/.only usage, but it's not a current correctness issue.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — waitUntilPromises.length = 0 now runs at the start of driveHandler(). Agreed with @vercel-bot that this isn't a current correctness issue (the only test that inspects the array is the last in the suite, after two afterEach resets), but it makes the assertion robust against future reordering/.only. I also applied the no-op .catch() mock hardening here that was flagged on the main PR (#2345), so the two test files stay in sync. Fixed in 63f4bc6.

"@workflow/core": patch
---

Never ack the orchestrator's queue message before the step-dispatch sends that make the run progress are durably enqueued. The suspension handler created each `step_created` event and enqueued its step-dispatch queue message inside `ops`, but registered `Promise.all(ops)` on a detached `waitUntil(...)` in addition to awaiting it. The detached copy framed those progress-critical sends as droppable background work and re-threw send failures into a promise nothing consumes (unhandled rejection → process exit 128), which could crash a deployment and leave the orchestrator message acked with the dispatch never sent — orphaning the step (its `step_created` is persisted but no queue message exists anywhere to drive the run). It now strictly awaits the sends only, so a crash before they complete leaves the message un-acked and VQS redelivers within the lease, re-creating the (idempotent) `step_created` and re-sending the dispatch instead of orphaning the step. Complements the crash fix in #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too verbose. match the format/terseness of other changesets

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed to match the sibling changesets (now ~4 lines, in line with abort-e2e-flakes.md etc). Fixed in 63f4bc6.

- Trim the changeset to match the terseness of sibling changesets.
- Attach a no-op .catch() to each promise the waitUntil mock records so a
rejecting promise can never surface as a real unhandled rejection in the
test process; keep the original promise for allSettled inspection.
- Reset waitUntilPromises at the start of driveHandler() so the rejection
check only observes this invocation's promises (robust to reordering/.only).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Heads up: the pre-existing tsc break on stable (resume-hook.ts:165 using waitUntil without importing it) that's flagged in this PR's description is now fixed in a separate minimal PR: #2347. This PR depends on #2347 landing first to get a green tsc on stable CI.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Dependency update: #2347/#2349 are closed as duplicates of #2344 (the faithful-backport fix, which also repairs the stable lockfile and the resume-hook import). This PR should land after #2344. One heads-up for the rebase: #2344 converts suspension-handler.ts's waitUntil import to the lazy ./wait-until.js wrapper, while this PR removes the only waitUntil call in that file — after both, the import becomes unused and should be dropped here.

"@workflow/core": patch
---

Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.
Fix unhandled rejection when `step_created`/`wait_created` calls fail in `waitUntil`

@VaguelySerious

Copy link
Copy Markdown
Member

Closing in favor of #2353

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@pranaygp@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [core] Never ack orchestrator message before step dispatch sends complete (stable) by pranaygp · Pull Request #2346 · vercel/workflow · GitHub
Skip to content

[core] Never ack orchestrator message before step dispatch sends complete (stable) - #2346

Closed
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable
Closed

[core] Never ack orchestrator message before step dispatch sends complete (stable)#2346
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable

Conversation

@pranaygp

@pranaygppranaygp commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Blocked by #2349#2347. Land order: #2349 (broken stable lockfile) → #2347 (waitUntil import, unblocks tsc) → #2346 (this). Until those land, stable CI fails in pnpm install --frozen-lockfile and then in tsc, before this PR's tests run.

Stable (4.x) backport of #2345.

What

In suspension-handler.ts, the progress-critical ops — each step's step_created event write and its __wkf_step_${stepName} queue-dispatch send, plus wait_created writes — are now strictly awaited before the handler returns, instead of also being registered on a detached waitUntil(Promise.all(ops).catch(...)).

This guarantees the invariant: the orchestrator's queue message is never acked until all work that makes the run progress is durably enqueued. A crash before the await leaves the orchestrator message un-acked, so VQS redelivers and replay re-drives the run — rather than acking and orphaning a step whose dispatch send was lost.

It also removes the .catch(err => { ...throw err }) re-throw that fed a detached, unconsumed promise: on a late send failure that produced an unhandledRejection, which Node turns into process.exit(128) — the production crash signature behind the ~305s VQS-lease-recovery latency cluster (and the permanent orphans when the orchestrator chain had already concluded).

Scope

Surgical and orthogonal to #2336 (the safeWaitUntil crash hardening). The genuinely-background waitUntil sites (stream flushes in start.ts / step-executor.ts / step-handler.ts, and the fire-and-forget in resume-hook.ts) are untouched — they're not progress-critical and shouldn't block the ack.

Related

🤖 Generated with Claude Code

…lete
handleSuspension created each step_created event and enqueued its
step-dispatch queue message inside ops, but registered Promise.all(ops) on a
detached waitUntil(...) in addition to awaiting it. The detached copy framed
those progress-critical sends as droppable background work and re-threw send
failures into a promise nothing consumes (unhandled rejection -> process exit
128), which could crash a deployment and leave the orchestrator message acked
with the dispatch never sent, orphaning the step. It now strictly awaits the
sends only, so a crash before they complete leaves the message un-acked for
VQS to redeliver within the lease, re-creating the idempotent step_created and
re-sending the dispatch instead of orphaning the step.
Adds runtime.test.ts ack-ordering tests: the dispatch send must complete
before ack, a hanging send must not ack, and a failing send must reject the
handler (no ack) without rejecting any waitUntil promise.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings June 11, 2026 06:10
@pranaygp
pranaygp requested a review from a team as a code ownerJune 11, 2026 06:10
@vercel

vercelBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackErrorErrorJun 11, 2026 6:20am
example-nextjs-workflow-webpackErrorErrorJun 11, 2026 6:20am
example-workflowErrorErrorJun 11, 2026 6:20am
workbench-astro-workflowErrorErrorJun 11, 2026 6:20am
workbench-express-workflowErrorErrorJun 11, 2026 6:20am
workbench-fastify-workflowErrorErrorJun 11, 2026 6:20am
workbench-hono-workflowErrorErrorJun 11, 2026 6:20am
workbench-nitro-workflowErrorErrorJun 11, 2026 6:20am
workbench-nuxt-workflowErrorErrorJun 11, 2026 6:20am
workbench-sveltekit-workflowErrorErrorJun 11, 2026 6:20am
workbench-tanstack-start-workflowErrorErrorJun 11, 2026 6:20am
workbench-vite-workflowErrorErrorJun 11, 2026 6:20am
workflow-docsErrorErrorJun 11, 2026 6:20am
workflow-swc-playgroundErrorErrorJun 11, 2026 6:20am
workflow-tarballsErrorErrorJun 11, 2026 6:20am
workflow-webErrorErrorJun 11, 2026 6:20am

@github-actions

github-actionsBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

No test result files found.


Some E2E test jobs failed:

  • Vercel Prod: failure
  • Local Dev: skipped
  • Local Prod: skipped
  • Local Postgres: skipped
  • Windows: failure

Check the workflow run for details.

@changeset-bot

changeset-botBot commented Jun 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 63f4bc6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens crash-safety for orchestrator queue handling in @workflow/core by ensuring the suspension handler does not allow progress-critical step-dispatch queue sends to run as detached background work that could be dropped (or crash the process via unhandled rejections) after the orchestrator message is acknowledged.

Changes:

  • Remove the detached waitUntil(Promise.all(ops)) registration in handleSuspension() and rely solely on await Promise.all(ops) so step dispatch sends gate handler completion (and thus message ack).
  • Add a new runtime test suite that asserts ack-ordering and failure/hang behavior for step dispatch during suspension handling.
  • Add a changeset for a patch release of @workflow/core describing the ack-ordering invariant and the fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

FileDescription
packages/core/src/runtime/suspension-handler.tsRemoves detached waitUntil usage so step-dispatch sends complete before the handler resolves (preserving ack-ordering).
packages/core/src/runtime.test.tsAdds “ack ordering” tests that validate dispatch send completion gates handler resolution and failures prevent ack.
.changeset/ack-after-step-dispatch.mdPatch changeset documenting the crash-safety/ack-ordering fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +685 to +688
}) {
const workflowRun = await makeRunningRun(opts.runId);
const order: string[] = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing waitUntilPromises in driveHandler() is a reasonable defensive hardening, but the assertion isn't actually flaky as written. The only test that calls anyWaitUntilPromiseRejected() is the last test in this suite ("rejects the handler ... when the step-dispatch send fails"), and it's preceded by the two other suite tests, each followed by the afterEach that runs waitUntilPromises.length = 0. So the array is already empty when the rejection check runs — leftover entries from earlier describe blocks have been cleared.

The first test in the suite can see leftover entries, but it never inspects waitUntilPromises, so it isn't affected. Moving the reset into driveHandler() (or adding a beforeEach) would make it robust against future reordering/.only usage, but it's not a current correctness issue.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — waitUntilPromises.length = 0 now runs at the start of driveHandler(). Agreed with @vercel-bot that this isn't a current correctness issue (the only test that inspects the array is the last in the suite, after two afterEach resets), but it makes the assertion robust against future reordering/.only. I also applied the no-op .catch() mock hardening here that was flagged on the main PR (#2345), so the two test files stay in sync. Fixed in 63f4bc6.

"@workflow/core": patch
---

Never ack the orchestrator's queue message before the step-dispatch sends that make the run progress are durably enqueued. The suspension handler created each `step_created` event and enqueued its step-dispatch queue message inside `ops`, but registered `Promise.all(ops)` on a detached `waitUntil(...)` in addition to awaiting it. The detached copy framed those progress-critical sends as droppable background work and re-threw send failures into a promise nothing consumes (unhandled rejection → process exit 128), which could crash a deployment and leave the orchestrator message acked with the dispatch never sent — orphaning the step (its `step_created` is persisted but no queue message exists anywhere to drive the run). It now strictly awaits the sends only, so a crash before they complete leaves the message un-acked and VQS redelivers within the lease, re-creating the (idempotent) `step_created` and re-sending the dispatch instead of orphaning the step. Complements the crash fix in #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too verbose. match the format/terseness of other changesets

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed to match the sibling changesets (now ~4 lines, in line with abort-e2e-flakes.md etc). Fixed in 63f4bc6.

- Trim the changeset to match the terseness of sibling changesets.
- Attach a no-op .catch() to each promise the waitUntil mock records so a
rejecting promise can never surface as a real unhandled rejection in the
test process; keep the original promise for allSettled inspection.
- Reset waitUntilPromises at the start of driveHandler() so the rejection
check only observes this invocation's promises (robust to reordering/.only).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Heads up: the pre-existing tsc break on stable (resume-hook.ts:165 using waitUntil without importing it) that's flagged in this PR's description is now fixed in a separate minimal PR: #2347. This PR depends on #2347 landing first to get a green tsc on stable CI.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Dependency update: #2347/#2349 are closed as duplicates of #2344 (the faithful-backport fix, which also repairs the stable lockfile and the resume-hook import). This PR should land after #2344. One heads-up for the rebase: #2344 converts suspension-handler.ts's waitUntil import to the lazy ./wait-until.js wrapper, while this PR removes the only waitUntil call in that file — after both, the import becomes unused and should be dropped here.

"@workflow/core": patch
---

Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.
Fix unhandled rejection when `step_created`/`wait_created` calls fail in `waitUntil`

@VaguelySerious

Copy link
Copy Markdown
Member

Closing in favor of #2353

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@pranaygp@VaguelySerious
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); [core] Never ack orchestrator message before step dispatch sends complete (stable) by pranaygp · Pull Request #2346 · vercel/workflow · GitHub
Skip to content

[core] Never ack orchestrator message before step dispatch sends complete (stable) - #2346

Closed
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable
Closed

[core] Never ack orchestrator message before step dispatch sends complete (stable)#2346
pranaygp wants to merge 2 commits into
stablefrom
fix/ack-after-step-enqueue-stable

Conversation

@pranaygp

@pranaygppranaygp commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Blocked by #2349#2347. Land order: #2349 (broken stable lockfile) → #2347 (waitUntil import, unblocks tsc) → #2346 (this). Until those land, stable CI fails in pnpm install --frozen-lockfile and then in tsc, before this PR's tests run.

Stable (4.x) backport of #2345.

What

In suspension-handler.ts, the progress-critical ops — each step's step_created event write and its __wkf_step_${stepName} queue-dispatch send, plus wait_created writes — are now strictly awaited before the handler returns, instead of also being registered on a detached waitUntil(Promise.all(ops).catch(...)).

This guarantees the invariant: the orchestrator's queue message is never acked until all work that makes the run progress is durably enqueued. A crash before the await leaves the orchestrator message un-acked, so VQS redelivers and replay re-drives the run — rather than acking and orphaning a step whose dispatch send was lost.

It also removes the .catch(err => { ...throw err }) re-throw that fed a detached, unconsumed promise: on a late send failure that produced an unhandledRejection, which Node turns into process.exit(128) — the production crash signature behind the ~305s VQS-lease-recovery latency cluster (and the permanent orphans when the orchestrator chain had already concluded).

Scope

Surgical and orthogonal to #2336 (the safeWaitUntil crash hardening). The genuinely-background waitUntil sites (stream flushes in start.ts / step-executor.ts / step-handler.ts, and the fire-and-forget in resume-hook.ts) are untouched — they're not progress-critical and shouldn't block the ack.

Related

🤖 Generated with Claude Code

…lete
handleSuspension created each step_created event and enqueued its
step-dispatch queue message inside ops, but registered Promise.all(ops) on a
detached waitUntil(...) in addition to awaiting it. The detached copy framed
those progress-critical sends as droppable background work and re-threw send
failures into a promise nothing consumes (unhandled rejection -> process exit
128), which could crash a deployment and leave the orchestrator message acked
with the dispatch never sent, orphaning the step. It now strictly awaits the
sends only, so a crash before they complete leaves the message un-acked for
VQS to redeliver within the lease, re-creating the idempotent step_created and
re-sending the dispatch instead of orphaning the step.
Adds runtime.test.ts ack-ordering tests: the dispatch send must complete
before ack, a hanging send must not ack, and a failing send must reject the
handler (no ack) without rejecting any waitUntil promise.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
CopilotAI review requested due to automatic review settings June 11, 2026 06:10
@pranaygp
pranaygp requested a review from a team as a code ownerJune 11, 2026 06:10
@vercel

vercelBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
example-nextjs-workflow-turbopackErrorErrorJun 11, 2026 6:20am
example-nextjs-workflow-webpackErrorErrorJun 11, 2026 6:20am
example-workflowErrorErrorJun 11, 2026 6:20am
workbench-astro-workflowErrorErrorJun 11, 2026 6:20am
workbench-express-workflowErrorErrorJun 11, 2026 6:20am
workbench-fastify-workflowErrorErrorJun 11, 2026 6:20am
workbench-hono-workflowErrorErrorJun 11, 2026 6:20am
workbench-nitro-workflowErrorErrorJun 11, 2026 6:20am
workbench-nuxt-workflowErrorErrorJun 11, 2026 6:20am
workbench-sveltekit-workflowErrorErrorJun 11, 2026 6:20am
workbench-tanstack-start-workflowErrorErrorJun 11, 2026 6:20am
workbench-vite-workflowErrorErrorJun 11, 2026 6:20am
workflow-docsErrorErrorJun 11, 2026 6:20am
workflow-swc-playgroundErrorErrorJun 11, 2026 6:20am
workflow-tarballsErrorErrorJun 11, 2026 6:20am
workflow-webErrorErrorJun 11, 2026 6:20am

@github-actions

github-actionsBot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

No test result files found.


Some E2E test jobs failed:

  • Vercel Prod: failure
  • Local Dev: skipped
  • Local Prod: skipped
  • Local Postgres: skipped
  • Windows: failure

Check the workflow run for details.

@changeset-bot

changeset-botBot commented Jun 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 63f4bc6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
workflowPatch
@workflow/world-testingPatch
@workflow/astroPatch
@workflow/nestPatch
@workflow/rollupPatch
@workflow/sveltekitPatch
@workflow/vitePatch
@workflow/nuxtPatch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens crash-safety for orchestrator queue handling in @workflow/core by ensuring the suspension handler does not allow progress-critical step-dispatch queue sends to run as detached background work that could be dropped (or crash the process via unhandled rejections) after the orchestrator message is acknowledged.

Changes:

  • Remove the detached waitUntil(Promise.all(ops)) registration in handleSuspension() and rely solely on await Promise.all(ops) so step dispatch sends gate handler completion (and thus message ack).
  • Add a new runtime test suite that asserts ack-ordering and failure/hang behavior for step dispatch during suspension handling.
  • Add a changeset for a patch release of @workflow/core describing the ack-ordering invariant and the fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

FileDescription
packages/core/src/runtime/suspension-handler.tsRemoves detached waitUntil usage so step-dispatch sends complete before the handler resolves (preserving ack-ordering).
packages/core/src/runtime.test.tsAdds “ack ordering” tests that validate dispatch send completion gates handler resolution and failures prevent ack.
.changeset/ack-after-step-dispatch.mdPatch changeset documenting the crash-safety/ack-ordering fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +685 to +688
}) {
const workflowRun = await makeRunningRun(opts.runId);
const order: string[] = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing waitUntilPromises in driveHandler() is a reasonable defensive hardening, but the assertion isn't actually flaky as written. The only test that calls anyWaitUntilPromiseRejected() is the last test in this suite ("rejects the handler ... when the step-dispatch send fails"), and it's preceded by the two other suite tests, each followed by the afterEach that runs waitUntilPromises.length = 0. So the array is already empty when the rejection check runs — leftover entries from earlier describe blocks have been cleared.

The first test in the suite can see leftover entries, but it never inspects waitUntilPromises, so it isn't affected. Moving the reset into driveHandler() (or adding a beforeEach) would make it robust against future reordering/.only usage, but it's not a current correctness issue.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — waitUntilPromises.length = 0 now runs at the start of driveHandler(). Agreed with @vercel-bot that this isn't a current correctness issue (the only test that inspects the array is the last in the suite, after two afterEach resets), but it makes the assertion robust against future reordering/.only. I also applied the no-op .catch() mock hardening here that was flagged on the main PR (#2345), so the two test files stay in sync. Fixed in 63f4bc6.

"@workflow/core": patch
---

Never ack the orchestrator's queue message before the step-dispatch sends that make the run progress are durably enqueued. The suspension handler created each `step_created` event and enqueued its step-dispatch queue message inside `ops`, but registered `Promise.all(ops)` on a detached `waitUntil(...)` in addition to awaiting it. The detached copy framed those progress-critical sends as droppable background work and re-threw send failures into a promise nothing consumes (unhandled rejection → process exit 128), which could crash a deployment and leave the orchestrator message acked with the dispatch never sent — orphaning the step (its `step_created` is persisted but no queue message exists anywhere to drive the run). It now strictly awaits the sends only, so a crash before they complete leaves the message un-acked and VQS redelivers within the lease, re-creating the (idempotent) `step_created` and re-sending the dispatch instead of orphaning the step. Complements the crash fix in #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too verbose. match the format/terseness of other changesets

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trimmed to match the sibling changesets (now ~4 lines, in line with abort-e2e-flakes.md etc). Fixed in 63f4bc6.

- Trim the changeset to match the terseness of sibling changesets.
- Attach a no-op .catch() to each promise the waitUntil mock records so a
rejecting promise can never surface as a real unhandled rejection in the
test process; keep the original promise for allSettled inspection.
- Reset waitUntilPromises at the start of driveHandler() so the rejection
check only observes this invocation's promises (robust to reordering/.only).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Heads up: the pre-existing tsc break on stable (resume-hook.ts:165 using waitUntil without importing it) that's flagged in this PR's description is now fixed in a separate minimal PR: #2347. This PR depends on #2347 landing first to get a green tsc on stable CI.

@pranaygp

Copy link
Copy Markdown
ContributorAuthor

Dependency update: #2347/#2349 are closed as duplicates of #2344 (the faithful-backport fix, which also repairs the stable lockfile and the resume-hook import). This PR should land after #2344. One heads-up for the rebase: #2344 converts suspension-handler.ts's waitUntil import to the lazy ./wait-until.js wrapper, while this PR removes the only waitUntil call in that file — after both, the import becomes unused and should be dropped here.

"@workflow/core": patch
---

Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Strictly await the step-dispatch sends in the suspension handler instead of also registering them on a detached `waitUntil`, so the orchestrator's queue message is never acked before the dispatch that makes the run progress is durably enqueued. A crash before then leaves the message un-acked for VQS to redeliver and replay, rather than orphaning the step. Also removes the re-throw that turned send failures into an unhandled rejection (process exit 128). Complements #2336.
Fix unhandled rejection when `step_created`/`wait_created` calls fail in `waitUntil`

@VaguelySerious

Copy link
Copy Markdown
Member

Closing in favor of #2353

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@pranaygp@VaguelySerious