Hello,
You need to retrieve the WorkflowProcessInstance : (WorkflowProcessInstance)kSession.getProcessInstance(processInstanceId);
Then : workflowProcessInstance.setVariable("formValid", formValid);
But after server restart workflowProcessInstance can be null and I don't find how to solve this problem.