Google chief executive Sundar Pichai talked about Gmail in May. (Jeff Chiu/AP)

It was around 4 a.m. Friday when Jonathan Kealing, bleary-eyed from an all-nighter with his 11-month-old daughter, first noticed the flood of emails into his inbox: from Groupon, the St. Louis Cardinals, a political campaign, a kids' store.

These were messages that Gmail had for years swept dutifully, quietly into his “Promotions” tab, where the coupons and other junk goes. Now, they were bursting into his main inbox, onto his phone’s lock screen, into his head. And they just kept coming.

An inadvertent bug had made Gmail’s filters go haywire, rerouting messages in a way that made users think it had lost its judgment over what messages deserved to land on top of the pile — and at the worst possible time of the year, when companies are bombarding people with holiday shopping pitches.

A Google spokesperson said the company expected the bug to be fixed within the day — but not before exposing, ever so slightly, how little we understand about the machinery that helps us feel as if our lives are in control.

Google’s Gmail is now 14 years old, and like most teenagers, it remains a mystery — a bundle of baffling algorithms hand-coded to impose order onto the Internet’s endless chaos. Gmail’s minimalist facade masks automated software for searching, spam-spotting, spell-checking, language translation and dozens of other abilities. Its latest, “Smart Compose,” automatically fills in the next word it thinks you, the human, are going to say.

All of it comes together to power email, which on a scale of basic human utilities ranks not far behind electricity. So when, instead, a tiny error was encoded into some computer file in some server in one of Google’s 15 sprawling data centers, running at all hours from protected compounds around the world, no one could quite understand what had happened — or even who, or what, to blame.

A small fraction of Gmail’s more than 1.4 billion worldwide users took to the Internet with questions: Had some setting changed or some shadowy algorithm contorted to alter what was important and what was not? Had the holiday season overloaded the world’s most popular email service? Or, more sinister, had the retail industry conspired to finally fool Google’s junk-mail filters, kneecapping the algorithms once and for all?

No, a Google spokesperson says. It’s just a bug, very rare but fixable. People first noticed it Thursday evening, and engineers on Friday were working to resolve the issue sometime this afternoon.

“We are aware of an issue in Gmail causing certain promotional email to be incorrectly categorized,” a spokesperson wrote in an email.

By then, it had already wriggled its way into the world’s attention spans. “I am insanely busy these days and the worst that can happen to me is to be distracted,” wrote a user on the Google forums. “Glad I am not the one that broke it,” wrote another user. “Somebody at Google is having a tough day.”

For Kealing, 33, a self-described compulsive email organizer living in Minneapolis, it exposed a vulnerability: “When I’m getting emails from political parties and group-deal sites I signed up for 1,000 years ago, it kind of throws off your mojo,” he said.

So he deleted the messages — a consumer survey, a getaway package for an all-inclusive Mexican resort — and went on with his day. He had a few emails to send.