Skip to content

[Workflows] Add restart from step options#6718

Merged
harrishancock merged 3 commits into
mainfrom
osilva/restart-from-step
May 7, 2026
Merged

[Workflows] Add restart from step options#6718
harrishancock merged 3 commits into
mainfrom
osilva/restart-from-step

Conversation

@pombosilva

Copy link
Copy Markdown
Contributor

Extends WorkflowInstance.restart() to accept an optional from parameter, allowing users to restart a workflow instance from a specific step instead of from the beginning.

await instance.restart({ from: { name: 'aggregate' } });
await instance.restart({ from: { name: 'process', count: 3 } });
await instance.restart({ from: { name: 'checkpoint', type: 'do' } });

@pombosilva pombosilva marked this pull request as ready for review May 4, 2026 13:19
@pombosilva pombosilva requested review from a team as code owners May 4, 2026 13:19
@pombosilva pombosilva requested a review from penalosa May 4, 2026 13:19
@github-actions

github-actions Bot commented May 4, 2026

Copy link
Copy Markdown

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@ask-bonk

ask-bonk Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

This PR adds WorkflowInstanceRestartOptions with a from parameter to allow restarting a workflow from a specific step. Type declarations, generated snapshots, tests, and mock are all updated — but the actual runtime implementation was not changed.

Issues

  1. [HIGH] restart() implementation not updated — The InstanceImpl.restart() method in src/cloudflare/internal/workflows-api.ts (lines 70-74) ignores the options argument entirely. The from field is never serialized into the request body sent to the backend. The current implementation sends only { id: this.id } regardless of what's passed in.

    The tests should catch this — testRestartFromStepNameOnly asserts body.from equals { name: 'fetch data' }, but the implementation never sends from, so these tests would fail.

    Suggested fix in src/cloudflare/internal/workflows-api.ts:

    - async restart(): Promise<void> {
    -   await callFetcher(this.fetcher, '/restart', {
    -     id: this.id,
    -   });
    - }
    + async restart(options?: WorkflowInstanceRestartOptions): Promise<void> {
    +   await callFetcher(this.fetcher, '/restart', {
    +     id: this.id,
    +     ...options,
    +   });
    + }
  2. [LOW] Mock uses module-level mutable statelastRestartBody in workflows-mock.js is module-level mutable state shared across all test cases. If test ordering changes or tests run concurrently, this could produce flaky assertions. Not a blocker, just worth noting.


This review was generated by an AI assistant and may contain inaccuracies.

@ask-bonk

ask-bonk Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

The key finding is high severity: the actual implementation in src/cloudflare/internal/workflows-api.ts was not updated. The restart() method (lines 70-74) still ignores any arguments — the from field from WorkflowInstanceRestartOptions is never serialized into the request body. The type declarations and tests all expect it, but the runtime code silently drops it. The new tests (testRestartFromStepNameOnly, testRestartFromStepAllOptions) should fail because of this, since the mock will never receive the from field.

A suggested fix was posted as a PR comment.

github run

@pombosilva pombosilva force-pushed the osilva/restart-from-step branch 2 times, most recently from 0a08bb5 to 97bb373 Compare May 4, 2026 13:53
@pombosilva pombosilva force-pushed the osilva/restart-from-step branch from 97bb373 to fabc556 Compare May 4, 2026 14:18
@codspeed-hq

codspeed-hq Bot commented May 4, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 72 untouched benchmarks
⏩ 129 skipped benchmarks1


Comparing osilva/restart-from-step (12cb5c8) with main (ae4004e)

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Comment thread src/cloudflare/internal/workflows.d.ts Outdated
Comment thread src/cloudflare/internal/workflows-api.ts Outdated
@NuroDev NuroDev requested review from NuroDev and removed request for penalosa May 7, 2026 12:56
@harrishancock harrishancock enabled auto-merge May 7, 2026 16:35
@harrishancock harrishancock merged commit 064b952 into main May 7, 2026
26 checks passed
@harrishancock harrishancock deleted the osilva/restart-from-step branch May 7, 2026 18:22
Sign up for free to 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