An Exit Code Is Not a Verdict
A scheduled job of ours failed on every run for nine days. The scheduler marked every run a success. Nothing was hidden: the failure was written down each morning in a log that nobody read.
What actually happened
It was a small automation that ran each morning and wrote a report. Its scheduler recorded an exit code of zero every time, so the dashboard stayed green. But the real work happened inside a wrapper script, and the wrapper caught the error, wrote it to a log file, and then exited normally. From the outside, a run that did nothing looked exactly like a run that did everything.
We only found it because a person went looking for the report and it was not there. Nine days of silence, and every signal we had built said things were fine.
This is not a rare bug. It is the default shape of most automation. A process tells you one number when it ends. That number answers one narrow question: did the process decide to call itself a failure? It does not answer the question you care about, which is whether the work got done.
Why exit status lies so easily
There are a few ordinary ways a broken run comes back as zero.
- Something swallows the error. A wrapper, a retry loop or an error handler catches the failure, logs it, and returns normally. The log has the truth. The exit code does not.
- A pipe reports the wrong stage. In a shell pipeline, the status you get back is the status of the last command in the pipe, not the first. If a job runs a command and pipes its output into a filter or a formatter, the formatter succeeding is what you see, even when the real command failed. Bash has an option,
pipefail, that changes this so a failure anywhere in the pipe is reported. It is off by default. - The work is skipped, not failed. A missing input, an expired credential or an empty queue can lead a program to do nothing and exit cleanly, because from its point of view there was nothing to do.
- The check checks the wrong thing. A health check that confirms a service is listening says nothing about whether the service returns correct answers. A login page that loads proves the login page loads.
Habit one: judge the output, not the exit
Decide what a successful run leaves behind, and check for that. For a report job, that means a file with today's date and a plausible size. A sync job should leave the destination matching the source. Backups should be restorable, which means someone restores it on a schedule. The question is never "did it exit zero." The question is "is the thing it was supposed to make actually there, and does it look right."
This costs a little more to write, because you have to say in advance what "right" means. That is the point. If you cannot describe the output of a good run, you do not yet know what your check is protecting.
Habit two: a check only counts if something reads it
Our failing job had a log, and the log was accurate. It did not matter, because nothing read it. A check that writes to a file nobody opens is a diary, not a control.
So every check needs a reader, and the reader should be something that already gets looked at. For us that meant routing check results into the briefing we read at the start of each work session, with failures printed first and successes collapsed to a single word. If a check cannot reach a place a human will see, either connect it or delete it. A check you think is running, but nobody watches, is worse than no check, because it gives you confidence you have not earned.
Habit three: break the thing on purpose
The only way to know a check catches a failure is to cause the failure and watch the check fire. Delete the file it looks for. Point it at an empty input. Corrupt one record. Kill the service it monitors. If the check stays green, it was never checking what you thought.
This is the same idea as mutation testing in software: deliberately introduce a defect and confirm the test suite fails. It feels like extra work. It is the cheapest insurance you will ever buy, because a check that has never gone red is a check you have only assumed works.
Habit four: make the failure loud at the source
Where you control the code, make failure the default outcome rather than something the code has to remember to report.
- Turn on strict modes in shell scripts so an error stops the script instead of rolling past it, and so pipes report their failures.
- When a wrapper catches an error, have it exit with a non-zero status after logging, not instead of it.
- Treat "did nothing" as a failure when doing nothing is not a normal result. An empty report on a day that should have data is a finding, not a quiet success.
- Record a short receipt for each run: when it ran, what it produced, and how big it was. Then the next check can compare today against yesterday.
Why this matters more with AI agents
An AI agent that runs a task and reports "done" is giving you an exit code in sentence form. It is a claim about the work, not proof of it. Agents are good at producing confident summaries, and a confident summary of a task that silently failed is the same trap with better grammar.
The habits carry over directly. Ask what a finished task leaves behind and check for that artifact yourself. Make sure some person or process actually reads the agent's results. Test your review process by handing it a task you know was done wrong. We cover the same theme from the security side in why a guard prompt is not a control: a sentence that says something is safe is not the same as a mechanism that makes it safe.
A short checklist
- For each automated job, write one sentence: "a good run leaves behind ____."
- Check for that thing, not for the exit code.
- Route the result somewhere a human already looks, failures first.
- Break what the check guards at least once and confirm it goes red.
- Turn on strict error handling and
pipefailin shell scripts.
Sources
- GNU Bash Reference Manual: Pipelines (pipeline exit status and the pipefail option)