Skip to content

[types] add restart-from-step support to WorkflowInstance.restart()#6701

Open
avenceslau wants to merge 3 commits intomainfrom
avenceslau/restart-from-step
Open

[types] add restart-from-step support to WorkflowInstance.restart()#6701
avenceslau wants to merge 3 commits intomainfrom
avenceslau/restart-from-step

Conversation

@avenceslau
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' } });

Fix the request body sent by WorkflowInstance.restart() to use 'from'
instead of 'step', matching the binding shim's expected field name.
Add tests for restart with no options, with step name only, and with
all options (name, count, type).
@avenceslau avenceslau requested review from a team as code owners April 30, 2026 11:52
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 30, 2026

UnknownError: ProviderInitError

github run

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 30, 2026

@avenceslau Bonk workflow failed. Check the logs for details.

View workflow run · To retry, trigger Bonk again.

@github-actions
Copy link
Copy Markdown

The generated output of @cloudflare/workers-types has been changed by this PR. If this is intentional, run just generate-types to update the snapshot. Alternatively, you can download the full generated types:

Full Type Diff
diff -r types/generated-snapshot/latest/index.d.ts bazel-bin/types/definitions/latest/index.d.ts
15225a15226,15239
> interface WorkflowInstanceRestartOptions {
>   /**
>    * Restart from a specific step. If omitted, the instance restarts from the beginning.
>    * The step must exist in the instance's execution history.
>    */
>   from?: {
>     /** The step name as defined in your workflow code. */
>     name: string;
>     /** 1-indexed occurrence of this step name. Defaults to 1. Use when the same step name appears multiple times (e.g. in a loop). */
>     count?: number;
>     /** Step type filter. Use when different step types share the same name. */
>     type?: "do" | "sleep" | "waitForEvent";
>   };
> }
15241c15255,15257
<    * Restart the instance.
---
>    * Restart the instance. Optionally restart from a specific step, preserving
>    * cached results for all steps before it.
>    * @param options Options for the restart, including an optional step to restart from.
15243c15259
<   public restart(): Promise<void>;
---
>   public restart(options?: WorkflowInstanceRestartOptions): Promise<void>;
diff -r types/generated-snapshot/latest/index.ts bazel-bin/types/definitions/latest/index.ts
15177a15178,15191
> export interface WorkflowInstanceRestartOptions {
>   /**
>    * Restart from a specific step. If omitted, the instance restarts from the beginning.
>    * The step must exist in the instance's execution history.
>    */
>   from?: {
>     /** The step name as defined in your workflow code. */
>     name: string;
>     /** 1-indexed occurrence of this step name. Defaults to 1. Use when the same step name appears multiple times (e.g. in a loop). */
>     count?: number;
>     /** Step type filter. Use when different step types share the same name. */
>     type?: "do" | "sleep" | "waitForEvent";
>   };
> }
15193c15207,15209
<    * Restart the instance.
---
>    * Restart the instance. Optionally restart from a specific step, preserving
>    * cached results for all steps before it.
>    * @param options Options for the restart, including an optional step to restart from.
15195c15211
<   public restart(): Promise<void>;
---
>   public restart(options?: WorkflowInstanceRestartOptions): Promise<void>;

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

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

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

This PR extends WorkflowInstance.restart() to accept an optional from parameter for restarting from a specific step. Types and implementation look correct, and backward compatibility is preserved (JSON.stringify drops undefined values so the no-argument case is unchanged).

Issues found (ranked by severity):

  1. [MEDIUM] Mock doesn't validate from payload, so tests don't actually verify the parameter is passed through. The /restart mock returns 200 unconditionally regardless of body content. testRestartFromStepNameOnly and testRestartFromStepAllOptions only verify no error is thrown -- a regression that silently drops from would pass all tests.
  2. [LOW] check-snapshot CI is failing. The generated types snapshot needs to be regenerated with just generate-types. (Already flagged by the CI bot.)

This review was generated by an AI assistant. Findings may contain errors -- please verify before acting on them.

}

if (reqUrl.pathname === '/restart' && request.method === 'POST') {
return Response.json({}, { status: 200 });
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.

The mock returns 200 unconditionally without inspecting the request body. This means the testRestartFromStepNameOnly and testRestartFromStepAllOptions tests only verify the call doesn't throw -- they don't assert that from is actually included in the request payload. A regression that silently drops the from field would pass all tests.

Consider validating the body and returning the from data so the tests can assert on it. For example:

Suggested change
return Response.json({}, { status: 200 });
if (reqUrl.pathname === '/restart' && request.method === 'POST') {
return Response.json({ result: { from: data.from } }, { status: 200 });
}

Then in the test assertions, verify the response carries the expected from value back (or at minimum, assert data.from is defined when it should be).

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 30, 2026

Review posted on PR #6701. Two findings:

  1. [MEDIUM] The /restart mock handler returns 200 unconditionally without validating the request body. The new restart-from-step tests only verify the call doesn't throw -- they don't assert the from parameter actually reaches the request payload. I posted an inline suggestion on the mock to return data.from so tests can assert on it.

  2. [LOW] The check-snapshot CI is failing because the generated types snapshot hasn't been regenerated (already flagged by the CI bot).

github run

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.

2 participants