Meet the AI That Could Solve Facebook's Bug Problem

One look at the stats and it’s pretty apparent: Facebook is a mobile app. The social network is accessed via a mobile device by some 88% of its users, according to Hootsuite, and when it comes to those visiting the site, 95% use a smartphone or a tablet.

Credit: Facebook

(Image credit: Facebook)

Given around 2.23 billion people log onto the platform in any given month, these numbers are staggering. Get things wrong and your mistakes are seen by the widest-ever audience.

This was made apparent recently when 6.8m users’ photos were left exposed thanks to a bug in its third-party API. If Facebook is to win back confidence and prove that its service is bug and leak free, then it needs to do everything it can to make sure these sort of breaches never happen again. 

Debugging on such a scale is a mammoth task, so just how do you test the Facebook app significantly enough to make sure bugs are zapped before they get to the user? With that many people using Facebook on their Android or iOS device, the permutations are jaw dropping. So how do you police something on this scale?

MORE: How to Stop Facebook From Sharing Your Data

Well, for most companies, the simple answer is to get a merry band of coders to do it. But if you are a coder, do you really want to spend all of your time debugging? Of course you don’t, you want to be creating new things and making software that could change the lives of millions.

Enter Sapienz

This is where Sapienz comes in. Created by a team that was born out of Monoidics, a London start-up that was acquired by Facebook in 2009, and Majicke, which was snapped up in 2017, this software is the ultimate bug hunter that’s helping Facebook make sure its apps are problem free, and it’s doing it with a little help from machine learning.

Here’s what we learned from a talk Mark Harman, an engineering manager at Facebook, gave about the software and its implications in the tech world beyond Facebook.

1. Using AI was born out of boredom

“Apps fail, so we will generate tests,” says Harman. “[But] the current state of the industry means that it is usually humans who generate tests. This is a slow process and a painful on as well. It’s also something developers find relatively boring, they would rather be doing something else.

“For this reason, it gets regarded as not explicitly unimportant but implicitly unimportant. That is until one day when something becomes super urgent because there is a fault in it.”

2. There’s 100,000 changes to Facebook’s code every week

That’s right, there’s 100,000 changes to Facebook’s source code every single week, which means that this code needs to be continuously checked for bugs. Facebook uses a cloud network of Android emulators to find bugs, which can be scaled accordingly. “The Sapienz technology has been completely deployed and it's found hundreds of bugs and runs on hundreds of emulators every minute. It is finding lots of crashes for us,” says Harman. To combat this, Sapienz decided to look at ways to automate the test-generating process.

3. To make the process even better, Facebook is using AI and machine learning to spot bugs

“The most exciting challenge for us that we could try and tackle was, if it is hard to find test cases to reveal bugs, how much harder would it be to then find changes to the code automatically to fix the bugs?” notes Harman. “This is very much bleeding edge. What we wanted was to take all this information and to automatically find the bugs. The idea here is to have a workflow where we find a crash, using Sapienz, that will trigger a patch that will generate to fix that crash.”

This tool is called SapFix and is currently proof of concept, with the hope that it will eventually work independently of automated bug finder Sapienz. 

4. It’s doing this to make Facebook's apps better but there’s also another very good reason

“Our goal is twofold: one is that we want to find them before we actually go to the public but the other thing is to allow the developers to move faster and work on things that are much more interesting to them,” explains Harman. “They would much rather spend their time being creative and make new products than have to spend their time understanding why this sequence here was referencing something it shouldn’t.”

5. Computers are great and all, but humans will always be needed to spot bugs

“Theoretically you could have no developers overseeing things but I don’t think we would want to get to that process,” Harman reveals. “We have now got an end to end process, where we will take a piece of software, automatically find crashes in it and fix some of those and check some of those fixes are good. But then it still goes to the developer. It is the developer finally reviews and decides whether this goes into the code base. We wouldn’t let an automated technology loose on our code base without having developer oversight.”

It’s worth thinking about this the next time you fire up Facebook and post a status. If everything works perfectly then it’s down to Harman and his team, decades of computational research and a nice dollop of AI. 

The good news is, when Sapienz is deemed ready it will be made open source. “There’s nothing peculiar about the kind of bugs we find in Facebook apps,” explains Harman. “Ultimately, we can make this technology available to the whole community. Make it open source and let others use this technology to help infrastructural work available.”

Once that's done, it may mean that the myriad Facebook bugs we have seen of late will be a thing of the past. This is something that couldn’t come sooner for both Facebook and its users.

Marc Chacksfield is Director of Shortlist Media and Editor-In-Chief of Shortlist. He's been a technology and entertainment journalist for 15 years and was previously UK Editor In Chief at Tom's Guide, TechRadar and Digital Camera World. He's also written for the likes of T3 and Tom's Hardware. In his spare time he tries to play guitar, PlayStation and supports Chelsea.