Thousands of failures with no explanation
Read the story →35,259 failed actions traced to one bug, and zero since the fix, across more than 120,000 actions
Every day thousands of automated actions on our platform were failing. Each failure was saved with an empty status and the same message from the database driver, “Failed query.” That message doesn’t tell you which query or which constraint, so when people talked about these failures they were mostly guessing.
I didn’t want to guess, so my first pull request didn’t try to fix anything. It only walked the error’s cause chain and saved the real PostgreSQL error code and the constraint name in their own columns. I wanted the failures to tell us what they were before we changed anything.
Before I merged it, I read my own PR again line by line against the ticket, and I found a mistake I made. I was logging the raw error one line before cleaning it, so customer ids and action settings would have gone into our logs. I fixed it in both places the error was logged and added tests. Then I reverted the fix on purpose to make sure the tests really failed without it, because I wanted to know they were actually checking something.
Once the real errors were being saved, it only took a few days to see the answer. About 85% of the failures were error code 23505, a unique key violation, and the key didn’t include the organization. So when two brands had the same asset, the first organization’s action went through and every other organization’s action for that asset failed.
I added the organization to the key and fixed how the job was queued. After that went live, this failure went to zero, and it has stayed at zero across more than 120,000 actions since.
Now when an error doesn’t say what’s wrong, I first make it record the real cause, and then the fix is usually small.