@@ -131,8 +131,8 @@ func (o *requestOwner) handle(ctx context.Context) error {
131131
132132 if sdkrequest .HasAsyncOps (o .mgr .Ops (), o .run .Attempt , 0 ) {
133133 // Always checkpoint first, then handle the async conversion.
134- o .handleFirstCheckpoint (ctx )
135- return o .handleAsyncConversion (ctx )
134+ token := o .handleFirstCheckpoint (ctx )
135+ return o .handleAsyncConversion (ctx , token )
136136 }
137137
138138 // Attempt to flush the response directly to the client immediately, reducing TTFB
@@ -169,7 +169,7 @@ func (o *requestOwner) handle(ctx context.Context) error {
169169//
170170// We also need to handle the API response to our user, which is either a token,
171171// a redirect, or a custom response.
172- func (o * requestOwner ) handleAsyncConversion (ctx context.Context ) error {
172+ func (o * requestOwner ) handleAsyncConversion (ctx context.Context , token string ) error {
173173 if ! sdkrequest .HasAsyncOps (o .mgr .Ops (), o .run .Attempt , 0 ) {
174174 return nil
175175 }
@@ -193,19 +193,19 @@ func (o *requestOwner) handleAsyncConversion(ctx context.Context) error {
193193 case AsyncResponseToken :
194194 return json .NewEncoder (o .w ).Encode (asyncResponseToken {
195195 RunID : o .run .RunID ,
196- Token : redirectToken ( o . run . RunID ) ,
196+ Token : token ,
197197 })
198198 case AsyncResponseCustom :
199199 v (o .w , o .r )
200200 return nil
201201 case AsyncResponseRedirect :
202202 if v .URL != nil {
203- url = v .URL (redirectToken ( o .run .RunID ) )
203+ url = v .URL (o .run .RunID , token )
204204 }
205205 }
206206
207207 if url == "" {
208- url = defaultRedirectURL (o .provider .opts , o .run .RunID )
208+ url = defaultRedirectURL (o .provider .opts , o .run .RunID , token )
209209 }
210210
211211 http .Redirect (o .w , o .r , url , http .StatusSeeOther )
@@ -312,7 +312,9 @@ func (o *requestOwner) call(ctx context.Context) APIResult {
312312// It also checkpoints the first N steps (potentially including the entire function).
313313//
314314// This is a blocking operation; to run this in the background use a goroutine.
315- func (o * requestOwner ) handleFirstCheckpoint (ctx context.Context ) {
315+ //
316+ // This returns an optional token used when redirecting to async outputs.
317+ func (o * requestOwner ) handleFirstCheckpoint (ctx context.Context ) string {
316318 var (
317319 requestBody []byte
318320 err error
@@ -357,10 +359,11 @@ func (o *requestOwner) handleFirstCheckpoint(ctx context.Context) {
357359 }, o .mgr .Ops ()... )
358360 if err != nil {
359361 o .provider .logger .Error ("error creating new api-based inngest run" , "error" , err , "run_id" , o .run .RunID )
360- return
362+ return ""
361363 }
362364
363365 o .run = * resp
366+ return resp .Token
364367}
365368
366369// validateResumeRequestSignature validates the signature for resume requests.
0 commit comments