Intermittent issue with publishing of docs in Hippo CMS

Some of the documents in Hippo CMS fail intermittently, when we try publishing them through code using DocumentWorkflow.publish(), with following error in log. The same document gets published at a later time.

org.hippoecm.repository.api.WorkflowException: Action 'publishBranch' is not allowed for project with id '<BranchName>'.
at com.onehippo.repository.wpm.project.documentworkflow.WpmDocumentWorkflowImpl.triggerAction(WpmDocumentWorkflowImpl.java:101) ~[hippo-addon-wpm-repository-cms-13.4.0.jar:13.4.0]
at org.onehippo.repository.documentworkflow.DocumentWorkflowImpl.publishBranch(DocumentWorkflowImpl.java:433) ~[hippo-repository-workflow-5.6.1.jar:13.4.0]
at org.onehippo.repository.documentworkflow.DocumentWorkflowImpl.publish(DocumentWorkflowImpl.java:314) ~[hippo-repository-workflow-5.6.1.jar:13.4.0]
at sun.reflect.GeneratedMethodAccessor1046.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_77]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_77]
at org.hippoecm.repository.impl.WorkflowManagerImpl$WorkflowInvocationHandler.invoke(WorkflowManagerImpl.java:373) ~[hippo-repository-engine-13.4.0.jar:13.4.0]
at com.sun.proxy.$Proxy214.publish(Unknown Source) ~[?:?]
.....
at org.hippoecm.frontend.dialog.AbstractDialog.handleSubmit(AbstractDialog.java:556) [hippo-cms-api-13.4.0.jar:13.4.0]
at org.hippoecm.frontend.dialog.AbstractDialog$2.onSubmit(AbstractDialog.java:279) [hippo-cms-api-13.4.0.jar:13.4.0]
at org.hippoecm.frontend.dialog.ButtonWrapper$1.onSubmit(ButtonWrapper.java:75) [hippo-cms-api-13.4.0.jar:13.4.0]
at org.apache.wicket.ajax.markup.html.form.AjaxButton$1.onSubmit(AjaxButton.java:113) [wicket-core-7.11.0.jar:7.11.0]
at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior$AjaxFormSubmitter.onSubmit(AjaxFormSubmitBehavior.java:218) [wicket-core-7.11.0.jar:7.11.0]
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1312) [wicket-core-7.11.0.jar:7.11.0]
at org.hippoecm.frontend.dialog.AbstractDialog.delegateSubmit(AbstractDialog.java:564) [hippo-cms-api-13.4.0.jar:13.4.0]
at org.apache.wicket.markup.html.form.Form.process(Form.java:976) [wicket-core-7.11.0.jar:7.11.0]
at org.hippoecm.frontend.dialog.AbstractDialog.process(AbstractDialog.java:696) [hippo-cms-api-13.4.0.jar:13.4.0]
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:797) [wicket-core-7.11.0.jar:7.11.0]
at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior.onEvent(AjaxFormSubmitBehavior.java:174) [wicket-core-7.11.0.jar:7.11.0]
at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:155) [wicket-core-7.11.0.jar:7.11.0]
at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:601) [wicket-core-7.11.0.jar:7.11.0]
at sun.reflect.GeneratedMethodAccessor208.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_77]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_77]
at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:258) [wicket-core-7.11.0.jar:7.11.0]
....

Does it have anything to do with Projects feature? Are we missing any configuration?
Any pointers will be greatly appreciated.