@@ -86,13 +86,12 @@ export const onComplete = internalMutation({
86
86
assert ( journalEntry , `Journal entry not found: ${ stepId } ` ) ;
87
87
const workflowId = journalEntry . workflowId ;
88
88
89
- const error = ! validate ( onCompleteContext , args . context )
90
- ? `Invalid onComplete context for workId ${ args . workId } ` +
91
- JSON . stringify ( args . context )
92
- : ! journalEntry . step . inProgress
93
- ? `Journal entry not in progress: ${ stepId } `
94
- : undefined ;
95
- if ( error ) {
89
+ if (
90
+ ! validate ( onCompleteContext , args . context , { allowUnknownFields : true } )
91
+ ) {
92
+ const error =
93
+ `Invalid onComplete context for workId ${ args . workId } ` +
94
+ JSON . stringify ( args . context ) ;
96
95
await ctx . db . patch ( workflowId , {
97
96
runResult : {
98
97
kind : "failed" ,
@@ -101,7 +100,20 @@ export const onComplete = internalMutation({
101
100
} ) ;
102
101
return ;
103
102
}
103
+ const { generationNumber } = args . context ;
104
104
const workflow = await getWorkflow ( ctx , workflowId , null ) ;
105
+ if ( workflow . generationNumber !== generationNumber ) {
106
+ console . error (
107
+ `Workflow: ${ workflowId } already has generation number ${ workflow . generationNumber } when completing ${ stepId } ` ,
108
+ ) ;
109
+ return ;
110
+ }
111
+ if ( ! journalEntry . step . inProgress ) {
112
+ console . error (
113
+ `Step finished but journal entry not in progress: ${ stepId } status: ${ journalEntry . step . runResult ?. kind ?? "pending" } ` ,
114
+ ) ;
115
+ return ;
116
+ }
105
117
if (
106
118
journalEntry . step . functionType === "pause" &&
107
119
args . result . kind === "success"
@@ -154,13 +166,6 @@ export const onComplete = internalMutation({
154
166
}
155
167
return ;
156
168
}
157
- const { generationNumber } = args . context ;
158
- if ( workflow . generationNumber !== generationNumber ) {
159
- console . error (
160
- `Workflow: ${ workflowId } already has generation number ${ workflow . generationNumber } when completing ${ stepId } ` ,
161
- ) ;
162
- return ;
163
- }
164
169
const workpool = await getWorkpool ( ctx , args . context . workpoolOptions ) ;
165
170
await workpool . enqueueMutation (
166
171
ctx ,
0 commit comments