Skip to content

[Workflows] Fix: implement workflows instance methods#12881

Merged
pombosilva merged 2 commits intomainfrom
osilva/fix-implement-workflows-instance-methods
Mar 19, 2026
Merged

[Workflows] Fix: implement workflows instance methods#12881
pombosilva merged 2 commits intomainfrom
osilva/fix-implement-workflows-instance-methods

Conversation

@pombosilva
Copy link
Contributor

@pombosilva pombosilva commented Mar 13, 2026

Fixes #12872 that reverted the original #12814 .

The original PR was causing constant Windows CI errors where the workerd process crashed mid tests.

The problem was with the pause() flow in binding.test.ts tests. Pause makes a void call to waitUntilNothingIsRunning so that running step.do's can finish before actually pausing the instance. The last thing waitUntilNothingIsRunning does is to change the instance status to paused and then aborts the Engine DO. The problem with this is because this is a void call that returns immediately, the actual abort fires later. At that point, no RPC is active and the abort happens in an orphaned context - which makes workerd crash on Windows CI.

The fix was to simply propagate Errors, where pause signals Engine instead of aborting - the key is that the throw must happen from inside the workflow's own promise chain where init() can catch it.


Original PR main changes:

Implements the 4 missing Workflow instance lifecycle methods for local dev: pause(), resume(), restart(), and terminate().

  • Pause: pause() sets WaitingForPause status, then it checks between steps, stores the pause timestamp, transitions to Paused, and aborts the DO. If there are any pending step.do's these will finish before going to Paused.
  • Resume: cancels a pending pause (WaitingForPause -> Running), or fully resumes by offsetting priority queue timers by the pause duration and firing init().
  • Restart: aborts the DO, then on the fresh instance reads stored INSTANCE_METADATA, cleans up SQL/KV (preserving modifier keys and mocked event data), writes fresh logs, and fires init().
  • Terminate: sets status to Terminated and aborts.

Also:

  • Validated step configuration.
  • Aligned states table schema with production (DATETIME('now','subsec') for timestamp precision).
  • WorkflowHandle.status() auto-refreshes stale DO stubs after abort.
    Also:

Validated step configuration.
Aligned states table schema with production (DATETIME('now','subsec') for timestamp precision).
WorkflowHandle.status() auto-refreshes stale DO stubs after abort.


A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2026

🦋 Changeset detected

Latest commit: 7b5437b

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

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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 13, 2026

✅ All changesets look good

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 13, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12881

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12881

miniflare

npm i https://pkg.pr.new/miniflare@12881

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12881

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12881

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12881

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12881

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12881

wrangler

npm i https://pkg.pr.new/wrangler@12881

commit: 7b5437b

@pombosilva pombosilva force-pushed the osilva/fix-implement-workflows-instance-methods branch 25 times, most recently from a467471 to ad6c122 Compare March 17, 2026 15:53
@pombosilva pombosilva force-pushed the osilva/fix-implement-workflows-instance-methods branch 7 times, most recently from d5925a6 to 6f8cc6c Compare March 18, 2026 15:12
@pombosilva pombosilva marked this pull request as ready for review March 18, 2026 15:19
@pombosilva pombosilva requested review from a team as code owners March 18, 2026 15:19
@workers-devprod
Copy link
Contributor

workers-devprod commented Mar 18, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/workflows
  • ✅ @cloudflare/wrangler
Show detailed file reviewers

devin-ai-integration[bot]

This comment was marked as resolved.

@pombosilva pombosilva force-pushed the osilva/fix-implement-workflows-instance-methods branch 2 times, most recently from 9695f80 to 3c92208 Compare March 18, 2026 17:49
Copy link
Contributor

@penalosa penalosa left a comment

Choose a reason for hiding this comment

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

Looks good from the vitest pool & miniflare side, but this also needs a workflows review

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Mar 18, 2026
@pombosilva pombosilva force-pushed the osilva/fix-implement-workflows-instance-methods branch 4 times, most recently from a599e23 to cd73e7e Compare March 19, 2026 10:51
devin-ai-integration[bot]

This comment was marked as resolved.

@pombosilva pombosilva force-pushed the osilva/fix-implement-workflows-instance-methods branch from cd73e7e to 86a7d0c Compare March 19, 2026 11:06
@pombosilva pombosilva force-pushed the osilva/fix-implement-workflows-instance-methods branch from 86a7d0c to 7b5437b Compare March 19, 2026 16:03
@pombosilva pombosilva merged commit 8729f3d into main Mar 19, 2026
40 of 41 checks passed
@pombosilva pombosilva deleted the osilva/fix-implement-workflows-instance-methods branch March 19, 2026 17:31
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants