workflows: rollback types#6766
Conversation
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR.
This PR adds TypeScript types for Workflow step.do() rollback options (WorkflowRollbackContext, WorkflowRollbackHandler, WorkflowStepRollbackOptions).
Issues
-
[MEDIUM]
WorkflowStepRollbackOptions<T>generic not threaded throughdo()overloads — TheWorkflowStepRollbackOptionstype accepts a genericTthat flows toWorkflowRollbackContext<T>.output, but bothdo()overloads use the bareWorkflowStepRollbackOptions(defaultingTtounknown). This meansctx.outputin the rollback handler is alwaysunknown, even though the step's return typeTis known. Users will have to castoutputmanually, which defeats the purpose of the generic. See inline suggestion. -
[LOW] Type tests assert
outputisunknown— masks issue #1 — The type tests currently assertctx.outputisunknown, which passes but only because the generic isn't wired through. If/when you fix issue #1, the tests for the first overload should assert the inferred type (e.g.,string), which would catch any future regression.
These comments were generated by an AI code reviewer and may not be perfect. Please use your judgment when evaluating them.
|
I've posted a review on PR #6766 with 2 findings:
|
Merging this PR will not alter performance
Comparing Footnotes
|
|
/bonk review |
There was a problem hiding this comment.
Previous review findings have all been addressed — WorkflowStepRollbackOptions<T> is now correctly threaded through both do() overloads, and the type tests assert string | undefined instead of unknown.
Remaining findings:
-
[LOW] No backward-compatibility test for
do()without rollback options — All three test cases pass a rollback options object (even{}). Consider adding a test that callsdo()without the trailing parameter to verify the existing API shape still works. -
[LOW] Separate
import typestatement —import type {WorkflowStep}on line 12 could be folded into the existing import block on lines 5-11 using inlinetypesyntax (import { ..., type WorkflowStep }) to reduce import clutter.
These comments were generated by an AI code reviewer and may not be perfect. Please use your judgment when evaluating them.
| } | ||
| ); | ||
|
|
||
| workflowStep.do('empty rollback options', async () => 'ok', {}); |
There was a problem hiding this comment.
Consider adding tests without any rollback options to verify backward compatibility of the existing overloads:
| workflowStep.do('empty rollback options', async () => 'ok', {}); | |
| workflowStep.do('empty rollback options', async () => 'ok', {}); | |
| // Verify existing call signatures still work without rollback options | |
| workflowStep.do('no rollback 2-arg', async (): Promise<string> => 'ok'); | |
| workflowStep.do('no rollback 3-arg', {retries: {limit: 1, delay: 0}}, async (): Promise<string> => 'ok'); |
| RpcTarget, | ||
| WorkerEntrypoint, | ||
| } from 'cloudflare:workers'; | ||
| import type {WorkflowStep} from 'cloudflare:workers'; |
There was a problem hiding this comment.
Nit: this import could be merged with the block above using inline type syntax:
| import type {WorkflowStep} from 'cloudflare:workers'; | |
| import { | |
| cache, | |
| DurableObject, | |
| RpcStub, | |
| RpcTarget, | |
| WorkerEntrypoint, | |
| type WorkflowStep, | |
| } from 'cloudflare:workers'; |
|
I've posted a review on PR #6766 with 2 findings:
The previous review's MEDIUM finding (generic |
Adds Workers types for optional
step.do(name, config?, callback, { rollback, rollbackConfig })Workflow rollback options.