I am basically having a similar issue. When I programmatically add the file, the workflow starts on create. It will then fail. Sometimes, it appears to not start at all.
What I have gathered from the log files is that the workflow is being started before the add operation is complete. SharePoint throws an error in the workflow because listitem has been modified after the workflow was started.
I have been able to confirm this is my problem by manually starting the workflow on the file after I programmatically upload and it works.
In the code when you add the file, you could stop the workflow from starting automatically, then add the file and then manually start the workflow, then set the workflow back to automatic. This is what I have chose to do, as the other methods (add a delay to the workflow or create an synchronous event receiver to fire the workflow manually on itemadded) are either too much work or sketchy, at best.
Also, I'm pretty sure you do not need to call the update method on the document library after you add the file. This may be creating the lock that is causing the workflow not to fire.
Another thing is that the account that your code is running under to add the file may not have permissions to run the workflow.
** UPDATE **
I just finished my fix for this. Here is my solution. Code could still use a little clean up :-)
private void startWorkflow(SPListItem item, Guid workflowID)
SPWorkflowAssociation wfA = item.ParentList.WorkflowAssociations.GetAssociationByBaseID(workflowID);
item.Web.Site.WorkflowManager.StartWorkflow(item, wfA, wfA.AssociationData, true);
private void ChangeAutoCreateWorkflow(SPDocumentLibrary library, Guid workflowID, bool startOnCreate)
// SPWorkflowAssociation changedOne = null;
SPWorkflowAssociation wfA = library.WorkflowAssociations.GetAssociationByBaseID(workflowID);
wfA.AutoStartCreate = startOnCreate;
//Get folder where I am moving the file to
SPFolder uploadsLibrary = item.Web.Folders[uploadsLibraryName];
//get library for the workflow
SPDocumentLibrary uploads = web.GetListByInternalName(uploadsLibraryName) as SPDocumentLibrary;
Guid workflowGuid = new Guid("FAKEACCC-9686-4244-A7AC-A31BDD56625F");
//stop the autocreate on the workflow
ChangeAutoCreateWorkflow(uploads, workflowGuid, false);
//move the file
file.MoveTo(uploadsLibrary.Url + "/" + fileName);
//get the new file
SPFile newFile = uploads.RootFolder.Files[uploadsLibrary.Url + "/" + fileName];
//get the file listitem
SPListItem newListItem = newFile.Item;
//run the workflow on it
//set workflow back to auto start on create
ChangeAutoCreateWorkflow(uploads, workflowGuid, true);